Skip to content

Commit 225d268

Browse files
committed
fix(quick-start): update data for freshness anomaly
1 parent 7b98b84 commit 225d268

4 files changed

Lines changed: 24 additions & 17 deletions

File tree

testgen/__main__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def quick_start(
428428
click.echo("loading initial data")
429429
run_quick_start_increment(0)
430430
now_date = datetime.now(UTC)
431-
time_delta = timedelta(days=-30) # 1 month ago
431+
time_delta = timedelta(days=-35) # before the first monitor iteration (~34 days back)
432432
table_group_id = "0ea85e17-acbe-47fe-8394-9970725ad37d"
433433
test_suite_id = "9df7489d-92b3-49f9-95ca-512160d7896f"
434434

@@ -449,16 +449,19 @@ def quick_start(
449449
run_quick_start_increment(iteration)
450450
run_test_execution(test_suite_id, run_date=run_date)
451451

452-
monitor_iterations = 42 # 3 weeks
452+
monitor_iterations = 68 # ~5 weeks
453453
monitor_interval = timedelta(hours=12)
454454
monitor_test_suite_id = "823a1fef-9b6d-48d5-9d0f-2db9812cc318"
455455
# Round down to nearest 12-hour mark (12:00 AM or 12:00 PM UTC)
456456
now = datetime.now(UTC)
457457
nearest_12h_mark = now.replace(hour=12 if now.hour >= 12 else 0, minute=0, second=0, microsecond=0)
458458
monitor_run_date = nearest_12h_mark - monitor_interval * (monitor_iterations - 1)
459+
weekday_morning_count = 0
459460
for iteration in range(1, monitor_iterations + 1):
460461
click.echo(f"Running monitor iteration: {iteration} / {monitor_iterations}")
461-
run_monitor_increment(monitor_run_date, iteration)
462+
if monitor_run_date.weekday() < 5 and monitor_run_date.hour < 12:
463+
weekday_morning_count += 1
464+
run_monitor_increment(monitor_run_date, iteration, weekday_morning_count)
462465
run_test_execution(monitor_test_suite_id, run_date=monitor_run_date)
463466
monitor_run_date += monitor_interval
464467

testgen/commands/run_quick_start.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,18 @@ def _metric_cumulative_shift(iteration: int) -> tuple[float, float]:
130130
return discount, price
131131

132132

133-
def _get_monitor_params_mapping(run_date: datetime, iteration: int = 0) -> dict:
133+
def _get_monitor_params_mapping(run_date: datetime, iteration: int = 0, weekday_morning_count: int = 0) -> dict:
134134
# Volume: linear growth with jitter, spike at specific iteration for anomaly
135-
if iteration == 37:
135+
if iteration == 60:
136136
new_sales = 100
137137
else:
138-
new_sales = random.randint(8, 12) # noqa: S311
138+
new_sales = random.randint(5, 15) # noqa: S311
139139

140-
# Freshness: update every other iteration, late update for anomaly
141-
is_update_suppliers_iter = (iteration % 2 == 0 and iteration != 38) or iteration == 39
140+
# Freshness: weekday morning updates with 1-day outage after schedule goes active
141+
is_weekday = run_date.weekday() < 5
142+
is_morning = run_date.hour < 12
143+
is_outage = weekday_morning_count == 21
144+
is_update_suppliers_iter = is_weekday and is_morning and not is_outage
142145

143146
# Metrics: compute deltas for discount and price shifts
144147
curr_discount, curr_price = _metric_cumulative_shift(iteration)
@@ -151,11 +154,11 @@ def _get_monitor_params_mapping(run_date: datetime, iteration: int = 0) -> dict:
151154
"ITERATION_NUMBER": iteration,
152155
"RUN_DATE": run_date,
153156
"NEW_SALES": new_sales,
154-
"IS_ADD_CUSTOMER_COL_ITER": iteration == 29,
155-
"IS_DELETE_CUSTOMER_COL_ITER": iteration == 36,
156-
"IS_UPDATE_PRODUCT_ITER": not 14 < iteration < 18,
157-
"IS_CREATE_RETURNS_TABLE_ITER": iteration == 32,
158-
"IS_DELETE_CUSTOMER_ITER": iteration in (18, 22, 34),
157+
"IS_ADD_CUSTOMER_COL_ITER": iteration == 47,
158+
"IS_DELETE_CUSTOMER_COL_ITER": iteration == 58,
159+
"IS_UPDATE_PRODUCT_ITER": not 24 < iteration < 28,
160+
"IS_CREATE_RETURNS_TABLE_ITER": iteration == 52,
161+
"IS_DELETE_CUSTOMER_ITER": iteration in (29, 36, 55),
159162
"IS_UPDATE_SUPPLIERS_ITER": is_update_suppliers_iter,
160163
"DISCOUNT_DELTA": discount_delta,
161164
"PRICE_DELTA": price_delta,
@@ -234,8 +237,8 @@ def run_quick_start_increment(iteration):
234237
setup_cat_tests(iteration)
235238

236239

237-
def run_monitor_increment(run_date, iteration):
238-
params_mapping = _get_monitor_params_mapping(run_date, iteration)
240+
def run_monitor_increment(run_date, iteration, weekday_morning_count=0):
241+
params_mapping = _get_monitor_params_mapping(run_date, iteration, weekday_morning_count)
239242
_prepare_connection_to_target_database(params_mapping)
240243

241244
target_db_name = params_mapping["PROJECT_DB"]

testgen/template/quick_start/initial_data_seeding.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SELECT '823a1fef-9b6d-48d5-9d0f-2db9812cc318'::UUID AS id,
5454
'{TABLE_GROUPS_NAME} Monitor Suite' AS test_suite_description,
5555
'N' AS export_to_observability,
5656
TRUE AS is_monitor,
57-
14 AS monitor_lookback,
57+
28 AS monitor_lookback,
5858
30 AS predict_min_lookback;
5959

6060
INSERT INTO job_schedules

testgen/template/quick_start/run_monitor_iteration.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ SELECT * FROM new_sales;
4242

4343

4444
UPDATE demo.d_ebike_customers
45-
SET last_contact = :RUN_DATE
45+
SET last_contact = :RUN_DATE,
46+
customer_decile = customer_decile + 1
4647
WHERE ctid IN (
4748
SELECT ctid
4849
FROM demo.d_ebike_customers

0 commit comments

Comments
 (0)