Commit 5c6da48
authored
[HDX-4111] refactor(alerts/search): consolidate saved-search → chart-config builder (#2166)
## Summary
Refs [HDX-4111](https://linear.app/clickhouse/issue/HDX-4111/private-instance-alert-system-triggering-false-positive-alerts).
Consolidate the saved-search → chart-config builder into a single shared helper. The alert task, the alert preview chart, and the app search page each had their own inline builder, and only the search page applied `source.tableFilterExpression`. On Log sources where that field is set, the alert path could legitimately count rows the search page hides — same false-positive class as HDX-4111, different cause from the underlying ClickHouse bug. Routing all three paths through the shared builder eliminates this drift class.
## Changes
### Shared chart-config builder
`packages/common-utils/src/core/searchChartConfig.ts` (new) exports `buildSearchChartConfig(source, input)` — the single source of truth for assembling a `BuilderChartConfig` from a `TSource` plus saved-search-style fields. Three call sites now route through it:
| Call site | Before | After |
| --- | --- | --- |
| `packages/app/src/DBSearchPage.tsx` (`useSearchedConfigToChartConfig`) | inline; applied `tableFilterExpression`; latently dropped it when user filters were non-null | shared builder |
| `packages/app/src/components/AlertPreviewChart.tsx` | inline; did NOT apply `tableFilterExpression` | shared builder |
| `packages/api/src/tasks/checkAlerts/index.ts` (`SAVED_SEARCH` branch) | inline; did NOT apply `tableFilterExpression` | shared builder |
Behavior fixes that fall out of consolidation:
- `tableFilterExpression` is now applied uniformly on Log sources by the alert task and the alert preview.
- A latent bug in the search-page builder is fixed: a non-null `filters` array no longer silently drops the table filter via spread-overwrite.
- The alert preview chart now matches what the alert task will actually count.
### Shared default SELECT for count alerts
`ALERT_COUNT_DEFAULT_SELECT` (in the same module) — both the alert task and the alert preview chart use this constant for the `count()` aggregate, so the two paths produce byte-identical SELECT shapes.
### `SearchChartConfig` return type
Narrower than `BuilderChartConfigWithOptDateRange` (keeps `timestampValueExpression` required, since the builder always sets it from the source). Lets downstream callers spread-and-add `dateRange` into `BuilderChartConfigWithDateRange` without TS errors.
## Risk / behavior change
Alerts on Log sources with `tableFilterExpression` set will now evaluate against a strictly smaller row set — the same rows the search page was already showing. Any alert that was quietly firing only because of rows hidden by `tableFilterExpression` will stop firing. This is a correctness fix.
Follow-up structural work (TILE alert chart-config consolidation, `computeAliasWithClauses` extraction) is tracked in [HDX-4113](https://linear.app/clickhouse/issue/HDX-4113/consolidate-alert-chart-config-assembly-into-hyperdxcommon-utils).1 parent fecbfff commit 5c6da48
9 files changed
Lines changed: 810 additions & 93 deletions
File tree
- .changeset
- packages
- api/src
- models
- tasks/checkAlerts
- __tests__
- app/src
- components
- common-utils/src
- core
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
137 | 138 | | |
138 | 139 | | |
139 | 140 | | |
| |||
Lines changed: 105 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
2314 | 2314 | | |
2315 | 2315 | | |
2316 | 2316 | | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
| 2321 | + | |
| 2322 | + | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
| 2346 | + | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
| 2384 | + | |
| 2385 | + | |
| 2386 | + | |
| 2387 | + | |
| 2388 | + | |
| 2389 | + | |
| 2390 | + | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
| 2395 | + | |
| 2396 | + | |
| 2397 | + | |
| 2398 | + | |
| 2399 | + | |
| 2400 | + | |
| 2401 | + | |
| 2402 | + | |
| 2403 | + | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
| 2416 | + | |
| 2417 | + | |
| 2418 | + | |
| 2419 | + | |
| 2420 | + | |
2317 | 2421 | | |
2318 | 2422 | | |
2319 | 2423 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
| |||
512 | 516 | | |
513 | 517 | | |
514 | 518 | | |
515 | | - | |
516 | | - | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
517 | 529 | | |
| 530 | + | |
518 | 531 | | |
519 | 532 | | |
520 | 533 | | |
521 | | - | |
522 | 534 | | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
| 535 | + | |
541 | 536 | | |
542 | 537 | | |
543 | 538 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | 41 | | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
| |||
511 | 510 | | |
512 | 511 | | |
513 | 512 | | |
514 | | - | |
| 513 | + | |
515 | 514 | | |
516 | 515 | | |
517 | 516 | | |
| |||
690 | 689 | | |
691 | 690 | | |
692 | 691 | | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
693 | 704 | | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
| 705 | + | |
722 | 706 | | |
723 | 707 | | |
724 | 708 | | |
| |||
1324 | 1308 | | |
1325 | 1309 | | |
1326 | 1310 | | |
1327 | | - | |
1328 | | - | |
1329 | | - | |
1330 | | - | |
1331 | | - | |
1332 | | - | |
1333 | | - | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
1334 | 1320 | | |
1335 | 1321 | | |
1336 | 1322 | | |
| |||
0 commit comments