fix: correct Magic Transit tunnel health metrics (active dimension, resultStatus) - #49
Open
michielappelman wants to merge 1 commit into
Conversation
- Remove the "active" dimension from magicTransitTunnelHealthChecksAdaptiveGroups. Including it causes the query to return zero rows for every time window, on every tunnel type (GRE and CNI/PNI). cloudflare_magic_transit_active_tunnels is removed along with it. - Fix resultStatus comparison: the API returns "ok"/"timeout", never "healthy". cloudflare_magic_transit_healthy_tunnels was permanently empty, and cloudflare_magic_transit_tunnel_failures was counting successful checks as failures.
michielappelman
force-pushed
the
fix/magic-transit-active-and-resultstatus
branch
from
July 31, 2026 13:45
d64b14a to
c6e5ee9
Compare
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
cloudflare_magic_transit_active_tunnels,cloudflare_magic_transit_healthy_tunnels, andcloudflare_magic_transit_tunnel_failureswere missing or wrong for accounts with active Magic Transit tunnels, even though the underlying GraphQL data clearly existed and the API token had correct permissions.Root-caused via direct GraphQL testing against a live account with both GRE and CNI/PNI (Cloudflare Network Interconnect) tunnels. Two independent bugs were found (a third, unrelated bug affecting whether these queries ever run at all for zero-zone accounts is split out into #50):
1. The
activedimension breaksmagicTransitTunnelHealthChecksAdaptiveGroupsIncluding
activein thedimensionsselection set causes the query to return zero rows, for every time window tested (60s through 13h), regardless of tunnel type:activeactiveVerified via raw
curlagainst/client/v4/graphqlwith no exporter code involved, and reproduced identically on a second, unrelated account. Notably, Cloudflare's own dashboard queries for this exact dataset (captured from the network tab while viewing the Magic Transit tunnel health charts) never selectactiveas a dimension - onlytunnelName,resultStatus, and one ofdatetimeFiveMinutes/remoteTunnelIPv4. This looks like an upstream GraphQL Analytics bug specific to that field; it's being reported separately to the API owners. In the meantime this PR removesactivefrom the query and drops thecloudflare_magic_transit_active_tunnelsmetric that depended on it, since it can't be computed without the field.This also explains a confusing support pattern: dashboard graphs for a tunnel can show healthy/active data while this exporter shows nothing at all for the same account/timeframe - the two are querying the same dataset with different dimension sets, and only one of them hits the broken field.
2.
resultStatusfilter checks for the wrong stringThe code filtered on
resultStatus === "healthy", but the API never returns that value. Verified across two independent accounts (including a customer's production data) that the actual values are"ok"(success) and"timeout"(failure) - never"healthy".Effect of the bug:
cloudflare_magic_transit_healthy_tunnelswas permanently empty (the filter never matched).cloudflare_magic_transit_tunnel_failureswas counting every successful health check as a failure, since its filter wasresultStatus !== "healthy", which matched"ok"results too.Changes
src/cloudflare/gql/queries.ts: removeactivefromMagicTransitMetricsQuerydimensions.src/cloudflare/client.ts: remove the now-unbuildablecloudflare_magic_transit_active_tunnelsmetric; fixresultStatuscomparisons from"healthy"to"ok".README.md: remove the now-removedcloudflare_magic_transit_active_tunnelsrow from the metrics table.Testing
tsc --noEmitandvitest run(56 existing tests) pass.biome checkclean on all touched files.active-dependent metrics were empty (theactivedimension bug) andhealthy_tunnels/tunnel_failureswere wrong (theresultStatusbug); after, all metrics report correctly, e.g.cloudflare_magic_transit_healthy_tunnels{tunnel_name="..."} 10557matching real health check volume, andtunnel_failuresdropping from ~10590 (incorrectly counting successes) to 1 (actual failures) for the same tunnel/window.Breaking change
cloudflare_magic_transit_active_tunnelsis removed. It cannot be reintroduced until the upstreamactivefield issue is resolved by Cloudflare, since there's no other way to compute it from this dataset today.