fix(cloudflare): correct TPR's zone-analytics query and export its selection helpers#2702
Open
kHorozhanov wants to merge 2 commits into
Open
fix(cloudflare): correct TPR's zone-analytics query and export its selection helpers#2702kHorozhanov wants to merge 2 commits into
kHorozhanov wants to merge 2 commits into
Conversation
added 2 commits
July 24, 2026 22:24
…lection helpers
queryTraffic asked httpRequestsAdaptiveGroups for orderBy: [sum_requests_DESC]
and sum { requests }. Neither exists on that dataset — the API rejects them
with "unknown enum value sum_requests_DESC" and "unknown field requests".
Those are schema-validation errors, not plan gating, so the query fails on
every zone. runTPR treats a failed traffic query as "no traffic data" and
skips gracefully, so --experimental-tpr silently pre-rendered nothing.
Corrected to count_DESC / count, and added tests that pin the request shape:
the previous query fails them.
Also exports queryTraffic, filterTrafficPaths, selectRoutes and resolveZoneId
so traffic-ranked selection can be reused with warmCdnCache, which is already
public but has no way to choose which paths to warm.
`toContain("count")` was satisfied by `count_DESC` in orderBy, so it held
even when the selection set asked for `sum { requests }`. Match `count` as a
field on its own line instead — verified it fails when only the selector is
reverted.
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.
What
Two changes to
@vinext/cloudflare's TPR module:--experimental-tprsilently pre-renders nothing.warmCdnCache.The bug
queryTrafficaskshttpRequestsAdaptiveGroupsfororderBy: [sum_requests_DESC]and selectssum { requests }. Neither exists on that dataset. Verified against a live zone:orderBy: [sum_requests_DESC]+sum { requests }error parsing args … orderBy: unknown enum value sum_requests_DESCorderBy: [count_DESC]+sum { requests }unknown field "requests"orderBy: [count_DESC]+countThese are schema-validation failures, not plan gating — contrast a genuinely plan-gated field like
edgeResponseContentTypeName, which fails withcode: authz("does not have access to the field"). So the query fails on every zone regardless of plan.Why it went unnoticed:
runTPRcatches a failing traffic query and treats it as "no traffic data", then skips gracefully — which is indistinguishable from a zone that genuinely has no traffic. The feature reports success and does nothing.Fixed by using
count_DESC/count, and mappingg.countinstead ofg.sum.requests.Tests
tests/tpr-traffic-query.test.tsis new — there was no coverage ofqueryTrafficat all (onlytpr-kv-keys.test.ts, which covers the KV key format). It pins the parts of the request the schema actually validates, the response mapping, and error surfacing. I verified the guard fails on the old query and passes on the new one:It also covers
filterTrafficPathsandselectRoutes, which were previously untested.The export
warmCdnCacheis already exported from@vinext/cloudflare/internal/cdn-warmand takes an arbitrarytargetUrl+paths, which makes it usable outside the bundleddeploypipeline — useful when the deployment shape isn't the onevinext-cloudflare deploybuilds (in our case a gateway worker in front of the renderer, so warming has to go through the gateway URL). But it has no way to decide which paths to warm, and the logic for that already exists here.So this exports
queryTraffic,filterTrafficPaths,selectRoutesandresolveZoneId(plus theTrafficEntry/SelectedRoutestypes) from@vinext/cloudflare/internal/tpr, following the same precedent that madecdn-warma separate entry point. No behaviour change — the only public entry today isrunTPR, which also does the local pre-render and KV upload.One thing worth flagging for anyone reusing
filterTrafficPaths: it assumes zone == one app. On a zone shared by several Workers the raw top paths include the other Workers' routes, which callers need to filter by their own base path.