Skip to content

fix: query each Network Analytics dataset independently to avoid null… - #46

Open
ahmedbadr-workday wants to merge 1 commit into
cloudflare:mainfrom
ahmedbadr-workday:fix/network-analytics-split
Open

fix: query each Network Analytics dataset independently to avoid null…#46
ahmedbadr-workday wants to merge 1 commit into
cloudflare:mainfrom
ahmedbadr-workday:fix/network-analytics-split

Conversation

@ahmedbadr-workday

Copy link
Copy Markdown

Problem

For accounts entitled to some but not all Network Analytics (NAv2) datasets, the exporter returns zero NAv2 metrics — even for datasets the account is fully entitled to. See issue #44.

getAccountMetrics("network-analytics") issues a single combined GraphQL query that selects six NAv2 datasets in one viewer { accounts { … } } document (magicTransit, magicFirewall, dosd/L3 DoS, advanced TCP protection, advanced DNS protection, IDPS). If the account lacks entitlement to any one of them, the GraphQL API returns an authorization error on that non-nullable field, which null-bubbles up to data.viewer and nulls the entire response — so entitled datasets (e.g. Magic Transit) come back empty too.

Fix

Split the combined query into one query per NAv2 dataset and collect them independently, so a denial on one dataset can no longer null-bubble the others. Denied datasets are remembered and skipped on subsequent refreshes; entitled datasets continue to return metrics.

Changes

  • src/cloudflare/gql/queries.ts: split the combined query into six per-dataset queries
  • src/cloudflare/client.ts: collect each NAv2 dataset independently with a per-dataset denied-cache and soft-handling of access-denied responses
  • src/cloudflare/client.test.ts: cover partial entitlement (some datasets denied, others returned) instead of expecting the whole refresh to throw

Verification

  • bun run check (biome) clean
  • bun run typecheck clean
  • bun run test — full suite passes

…-bubbling

getAccountMetrics("network-analytics") issued a single combined GraphQL query selecting six NAv2 datasets. When an account lacks entitlement to any one dataset, the GraphQL API returns an authorization error on that non-nullable field, which null-bubbles up to data.viewer and nulls the entire response, so even fully entitled datasets (e.g. Magic Transit) return nothing.

Split the combined query into one query per dataset and collect them independently, so a denial on one dataset no longer null-bubbles the others. Denied datasets are remembered and skipped on subsequent refreshes; entitled datasets continue to return metrics.

Updates client tests to cover partial entitlement (some datasets denied, others returned) instead of expecting the whole refresh to throw.
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.

1 participant