fix: expire boundary double-count and label sort order in counter chains#42
Merged
davidbirdsong merged 1 commit intoJul 3, 2026
Conversation
Author
|
This change is part of the following stack: Change managed by git-spice. |
a702fbd to
316fd99
Compare
Author
|
Waiting on reads granted: https://github.com/supabase/k8s-observability/pull/455 |
316fd99 to
3d428e6
Compare
Two bugs that cause counter value spikes in pushed metrics: 1. When Lookback == WindowTTL, buckets at the exact boundary were expired then re-fetched, double-counting the gauge in the chain base. Changed expire check from >= to >. 2. Key.String() preserved label insertion order, so the same series could map to different counter chains when labels arrived in different order (e.g. seeding from VM). Labels are now sorted by name before serialization. Also: collapse WindowTTL into Lookback (they served the same purpose), add Prometheus counters for convergence tuning, add fixture capture tool and second spike incident test data.
3d428e6 to
5f6a766
Compare
jose-ledesma
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix two bugs that cause counter value spikes in pushed metrics, add Prometheus observability counters for convergence tuning, and add a fixture capture tool for future spike investigations.
Bug fixes
Expire boundary double-count. When
WindowTTL == Lookback(or after collapsing them into a single setting), buckets at exactly the boundary were expired and then re-fetched on the next tick. The re-inserted gauge was double-counted in the chain base, shifting all subsequent counters upward. Fixed by changing the expire check from>=to>.Label sort order in Key.String(). Keys with the same labels in different insertion order produced different string representations, causing the engine to create separate counter chains for what VM treats as the same series. The seeding path (
LastValues) iterates a Go map (unordered), so seeded chains could silently diverge from live chains. Fixed by sorting labels by name before serialization.Collapse WindowTTL into Lookback
WindowTTLandLookbackserved the same purpose in practice (a window only receives data from the live fetch, so keeping it open longer than the fetch range is pointless). RemovedWindowTTLas a separate setting.Lookbacknow controls both the live query range and window expiry.Prometheus metrics
Added per-tick counters and gauges on
/metricslabeled bycomponentto make convergence behavior observable and tuning data-driven:converge_post_stabilize_updates_totalconverge_expire_flushes_totalconverge_ingest_samples_totalconverge_expire_samples_totalconverge_live_fetch_observations_totalconverge_backfill_fetch_observations_totalconverge_snapshot_samples_totalconverge_open_windowsconverge_tracker_countconverge_push_errors_totalFixture capture tool
cmd/capture-fixturesfetches observations from the CF API for a specific zone and time range, trims to a single metric, and writes JSON fixtures for use inspike_test.go. Includes a second captured incident (zone43c0ec06, 2026-06-26 14:00-14:22 UTC).Spike test improvements
Refactored spike tests to be table-driven across multiple fixture sets. Both the original supabase.co capture and the new 0626 incident are tested for pre-fix spike detection and post-fix clean output.
Test plan
go test ./...passesTestExpireBoundaryDoubleCountdemonstrates and verifies the boundary fixTestKeyStringLabelOrderdemonstrates and verifies the sort fixTestSpikeDetection_PreFixconfirms spikes exist under old behavior (both fixture sets)TestSpikeDetection_PostFixconfirms no spikes after fix (both fixture sets)converge_*metrics appear on/metricsrate(cloudflare_zone_requests_total[5m]) * 60