Skip to content

Judge usage drift only where there is enough evidence for it - #1884

Merged
rdimitrov merged 2 commits into
mainfrom
rdimitrov-registry-usage-dashboard-preview
Nov 21, 2026
Merged

rdimitrov merged 2 commits into
mainfrom
rdimitrov-registry-usage-dashboard-preview

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

What

The "Usage estimate drifted from the gateway counters" rule now judges its two estimates separately, each only when there is enough evidence for it:

  • Requests: when the gateway counted at least 1,000 requests that day.
  • Data: when at least 1,000 listing records were sampled.

Why

The rule fires when the log-based estimate of requests or data is more than 10% from the gateway's counters. On a day with little traffic, a handful of listing records stand for all listing data, so the data estimate strays that far by chance. In staging, most quiet days would have fired.

The first version of this change used one threshold on the number of sampled records. Review found it wrong in both directions, and the second commit replaces it:

  • A busy day whose access records went missing has few records, so it was excluded and the loss went unreported. The request threshold is now on the gateway's count, not on what was read.
  • A day with many lookup records and a single listing record passed, although that one record stands for all listing data. The data threshold is now on sampled listing records: the day's listing requests divided by the largest weight one listing record carries, which never overstates how many there were.

Effect

  • Nothing changes in a cluster today: the two usage rules exist only where the Discord webhook is set, and neither stack has it.
  • A day where neither estimate can be judged, or whose ratios are unknown, evaluates to 0, as an empty table already did.

How it was checked

  • go -C deploy test ./... passes.
  • The new query was run as the read-only Grafana role against a copy of staging's stored days restored from its backup:
    • On every stored day the rule value equals that day's request drift, and stays below 10. The quiet days' data drift, which is far beyond 10, is not judged; the busy days' data drift is judged and is small.
    • A busy day with its records lost (a million requests counted, a few thousand lookups read): fires.
    • Enough sampled listings with data far off: fires.
    • One listing record among many other records, data far off: does not fire on data.
    • No listing weight recorded, ratios unknown, empty table: 0, with no division by zero.
  • The file still contains no dollar sign, which Grafana would expand.

Not checked: the rule was not loaded into a Grafana instance again; only its SQL and annotation text changed.

The drift rule compares the newest day's log-based estimate with the
gateway counters and fires beyond 10 percent. On a day with little
traffic a handful of listing records stand for all listing data, so
the estimate strays that far by chance: in staging most quiet days
would have fired.

Judge a day only when it has at least 20,000 sampled records. A busy
day is sampled to about 100,000, so the rule still covers every day
that the dashboards are read for.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The guard can miss severe log loss on busy days and still allow false data-drift alerts because it counts all records rather than sampled listings.

2 open issues
What changed in this PR

This PR adds a minimum-sample guard to the usage collector’s Grafana drift alert, aiming to reduce noisy alerts on low-traffic days.

Changes:

  • Evaluate the newest stored day’s request and data drift only when it has at least 20,000 sampled records.
  • Document the cutoff and its rationale in the deployment guide and alert annotations.
File Description
deploy/​README.md Documents the minimum sample size for drift alerts.
deploy/​pkg/​k8s/​usage/​alerting/​rules.yaml Adds the sample-size guard and updates the alert explanation.

Review effort: Balanced

Review of the previous commit found that a single threshold on sampled
records was wrong in both directions:

- A busy day whose access records went missing has few records, so it
  was excluded, and the loss went unreported.
- A day with many lookup records and a single listing record passed,
  although that one record stands for all listing data.

Judge the request estimate whenever the gateway counted at least 1,000
requests, whatever was read from the logs. Judge the data estimate when
at least 1,000 listing records were sampled, taken as the day's listing
requests divided by the largest weight one listing record carries,
which never overstates the count.

Co-authored-by: Copilot App <[email protected]>
@rdimitrov rdimitrov changed the title Do not judge usage drift on days with few sampled records Judge usage drift only where there is enough evidence for it Nov 21, 2026
@rdimitrov
rdimitrov merged commit 5fa0c6d into main Nov 21, 2026
12 checks passed
@rdimitrov
rdimitrov deleted the rdimitrov-registry-usage-dashboard-preview branch November 21, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants