fix: query each Network Analytics dataset independently to avoid null… - #46
Open
ahmedbadr-workday wants to merge 1 commit into
Open
fix: query each Network Analytics dataset independently to avoid null…#46ahmedbadr-workday wants to merge 1 commit into
ahmedbadr-workday wants to merge 1 commit into
Conversation
…-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.
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
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 oneviewer { 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 todata.viewerand 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 queriessrc/cloudflare/client.ts: collect each NAv2 dataset independently with a per-dataset denied-cache and soft-handling of access-denied responsessrc/cloudflare/client.test.ts: cover partial entitlement (some datasets denied, others returned) instead of expecting the whole refresh to throwVerification
bun run check(biome) cleanbun run typecheckcleanbun run test— full suite passes