fix: don't block account-scoped refresh on zero-zone accounts - #50
Open
michielappelman wants to merge 1 commit into
Open
fix: don't block account-scoped refresh on zero-zone accounts#50michielappelman wants to merge 1 commit into
michielappelman wants to merge 1 commit into
Conversation
MetricExporter gated account-scoped refresh on zones.length === 0 to detect an uninitialized context. Magic Transit-only accounts can legitimately have zero zones, which permanently blocked every account-level query (magic-transit, magic-transit-slo, magic-transit-traffic, magic-firewall-samples, worker-totals, etc.) from ever fetching data for such accounts. Gate on accountId === "" instead, which correctly distinguishes 'never initialized' from 'initialized with zero zones'.
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.
Problem
MetricExporter.refreshWithTimeRangeandupdateZoneContextgate account-scoped refresh onstate.zones.length === 0, using it as a proxy for "context not yet initialized."Magic Transit-only accounts (or any account where the token can't list zones, or the account simply has none) can legitimately have zero zones. For these accounts, this check is permanently true, so
isFirstContextnever fires and every subsequent alarm hits the "no zone context yet" skip - meaning every account-level query (magic-transit,magic-transit-slo,magic-transit-traffic,magic-firewall-samples,worker-totals,logpush-account,images) silently never runs for that account, even though none of these queries use zone data at all.Found while debugging why Magic Transit metrics were completely absent (not just wrong) for a zero-zone account -
/metricsshowedcloudflare_accounts 1but nothing else, and Worker logs showed"Skipping refresh - no account context yet"/"Skipping refresh - no zone context yet"repeating indefinitely.Fix
Track "has this exporter ever received a context push" via
accountId === ""(the actual uninitialized-state sentinel already used elsewhere inMetricExporterState) instead ofzones.length === 0, in both theisFirstContextcheck inupdateZoneContextand the skip-gate inrefreshWithTimeRange. This correctly distinguishes "never initialized" from "initialized with zero zones," and has no effect on accounts that do have zones.Testing
tsc --noEmitandvitest run(56 existing tests) pass.biome checkclean.magic-transit/magic-transit-traffic/magic-firewall-samplesall populate correctly on schedule.