Commit 1ae6220
fix(telemetry): exclude pre-schema rows from latency rollup (#137)
## What
Follow-up to #132. Adds a schema-version marker to every latency row and
filters on it in the rollup query, so pre-#132 rows are excluded from
`/telemetry/v1/stats/latency`.
## Why (the AE default-0 gotcha)
The Analytics Engine SQL API has **no NULLs**: any `double` a row never
wrote is materialized as **`0`** at query time. Rows written by the
pre-latency Worker (before #132) have no `double7..10`, so they read
`scan_p50 == 0` — a materialized 0, not a real sample. That passed the
rollup's `WHERE <p50col> >= 0` sentinel filter and showed up as legit `0
ms` samples. Caught in the live smoke of the endpoint: a day that
predates the deploy reported `samples > 0, avg 0`.
The `-1` sentinel can't fix this on its own — it only distinguishes
empty from present *within* a row that actually wrote the doubles; a
legacy row never wrote them, so there's no sentinel to read.
## Fix
- **Write** (`writePing`): append a schema-version marker `double11 = 1`
(`LATENCY_SCHEMA_VERSION`) on every row that carries the latency
doubles.
- **Query** (`queryLatencyMetric`): add `AND double11 >= 1` to each
per-metric `WHERE` (in addition to the existing `>= 0` sentinel). A
legacy row materializes the marker as `0` and is excluded; a new
empty-latency row is marked (`double11 = 1`) but still excluded by its
`-1` sentinel; a real `0 ms` still counts.
- Both sites comment the AE missing-double=0 behavior. README dataset
table + rollup section updated (`double11` row, dual-filter
explanation).
## Tests (worker vitest)
- `writePing` marks every new latency-schema row with `double11 = 1`.
- A new-but-empty-latency row is marked (`double11 = 1`) yet still
carries the `-1` sentinels — proving the marker and sentinel filters are
independent (the sentinel is what excludes it).
- Both per-metric rollup queries include `double11 >= 1` (the mechanism
that excludes pre-latency rows, whose marker materializes as 0).
Gates green: worker `typecheck` + `lint` + `test` (58, +2 new).
## Notes
Cut from latest `origin/main` (which already includes #132). Endpoint
still needs the same wrangler secrets as #132; the live smoke that
surfaced this bug already has them set. Do not merge — for review.
Refs #34
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 319e85f commit 1ae6220
3 files changed
Lines changed: 90 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
46 | 55 | | |
47 | 56 | | |
48 | 57 | | |
| |||
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
75 | 85 | | |
76 | 86 | | |
77 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
389 | 405 | | |
390 | 406 | | |
391 | 407 | | |
392 | 408 | | |
393 | 409 | | |
394 | 410 | | |
395 | | - | |
| 411 | + | |
396 | 412 | | |
397 | | - | |
398 | | - | |
399 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
400 | 419 | | |
401 | 420 | | |
402 | 421 | | |
| |||
427 | 446 | | |
428 | 447 | | |
429 | 448 | | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
430 | 453 | | |
431 | 454 | | |
432 | 455 | | |
| |||
548 | 571 | | |
549 | 572 | | |
550 | 573 | | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
555 | 581 | | |
556 | 582 | | |
557 | 583 | | |
| |||
561 | 587 | | |
562 | 588 | | |
563 | 589 | | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
564 | 599 | | |
565 | 600 | | |
566 | 601 | | |
567 | 602 | | |
568 | 603 | | |
569 | 604 | | |
570 | 605 | | |
571 | | - | |
| 606 | + | |
| 607 | + | |
572 | 608 | | |
573 | 609 | | |
574 | 610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
572 | 572 | | |
573 | 573 | | |
574 | 574 | | |
| 575 | + | |
| 576 | + | |
575 | 577 | | |
576 | 578 | | |
577 | 579 | | |
| |||
589 | 591 | | |
590 | 592 | | |
591 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
592 | 619 | | |
593 | 620 | | |
594 | 621 | | |
| |||
701 | 728 | | |
702 | 729 | | |
703 | 730 | | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
704 | 734 | | |
705 | 735 | | |
706 | 736 | | |
| |||
0 commit comments