feat(query-engine): migrate Cloudflare/PlanetScale handlers to the registry (45/61) - #345
Merged
Merged
Conversation
Adds 15 integration sub-query defs covering 8 handlers: cloudflareInfraZones, ZoneHosts, ZoneSecurity, ZoneDns, Workers, PlatformResources, serviceCloudflareStats and planetscaleInfraTimeseries. Each def inlines the small payload-derived prologue (`params`, `filters`, `base`) that used to sit in the handler, so the def is self-contained. The sub-queries keep their own ids -- cloudflareInfraZoneHostTotals and cloudflareInfraZoneHostTimeseries are distinct spans and distinct cache keys, and folding them under the handler name would merge unrelated entries. Handlers that report `ignoredFilters` keep their own `toCloudflareFilters` call. It is a pure function of the payload, so computing it in both the def and the handler cannot drift, and which filters a metric family could not honor is presentation rather than query construction. planetscaleInfraTimeseries folds its branch/no-branch conditional into compile, the same way serviceUsage folds its previous-window branch. Two scripting traps worth recording, both caught by typecheck rather than by review: * Dead `const xCompiled = CH.compile(...)` declarations survived the first removal pass because the reference count was taken over the whole file, and these variable names repeat across handlers (`latencyCompiled` appears in five). Counting references per handler block removed 17 declarations that would otherwise have kept compiling queries nobody ran. * The extracted compile expressions lost their `CH.compile` prefix, because the balanced-paren capture returned the argument list alone. Verified: apps/api typecheck; SQL baseline byte-identical; routes + warehouse suites 310 pass.
…y (47/61) serviceDbQuerySummary's three sub-queries all take the identical params object, so a shared `dbQueryParams` helper builds it per def from the payload instead of the handler threading one object into three compiles. The summary sub-query is single-row and reads through runQueryFirst. Verified: both packages typecheck; SQL baseline byte-identical; routes + warehouse suites 310 pass.
podFacets, nodeFacets and workloadFacets. They were classified complex only because they build with compileUnion rather than CH.compile; compileUnion returns the same CompiledQuery, so each is an ordinary single-query def. Their maxThreads: 4 setting moves into the def, keeping the reason for it (bounding Map-column decompression memory across the UNION fan-out) next to the query it protects. Verified: both packages typecheck; SQL baseline byte-identical; routes + warehouse suites 310 pass.
servicePlanetScaleStats reads either the database-level or the branch-level rollup depending on whether a database was requested. Each of its three sub-queries folds that branch into compile, so the id, profile and row schema stay one decision per sub-query instead of two. The handler keeps `byBranch` because its merge key depends on it -- that is response assembly, not query construction. Verified: apps/api typecheck; SQL baseline byte-identical; routes + warehouse suites 310 pass.
🍁 Maple PR previewNote Preview resources were removed when this pull request closed. Final commit |
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.
Continues #344. Takes the registry from 37 to 45 of 61 handlers by covering the integrations group.
What
15 sub-query defs across 8 handlers:
cloudflareInfraZones,ZoneHosts,ZoneSecurity,ZoneDns,Workers,PlatformResources,serviceCloudflareStats,planetscaleInfraTimeseries.Each def inlines the payload-derived prologue (
params,filters,base) that used to live in the handler, so the def is self-contained. A typical handler drops from ~50 lines to:Design notes
cloudflareInfraZoneHostTotalsand...HostTimeseriesare distinct spans and distinct cache keys; folding them under the handler name would merge unrelated cache entries.toCloudflareFiltersis computed in both the def and the handler. Deliberate: it's a pure function of the payload so the two cannot drift, andignoredFilters(which filters a metric family couldn't honor) is presentation, not query construction.apps/api/src/routes/queries.ts, because@maple/query-engine-integrationsdepends on@maple/query-engine— declaring them in the core registry would invert that edge.planetscaleInfraTimeseriesfolds its branch/no-branch conditional intocompile, matching howserviceUsagehandles its previous-window branch.Two scripting traps, both caught by typecheck
Recording these because they're the failure mode of bulk migration, not of the design:
const xCompiled = CH.compile(...)declarations survived the first removal pass. The reference count was taken over the whole file, and these names repeat across handlers —latencyCompiledappears in five. Scoping the count per handler block removed 17 declarations that would otherwise have gone on compiling queries nobody ran.CH.compileprefix, because the balanced-paren capture returned the argument list alone.Testing
apps/apitypecheck cleanapps/apiroutes + warehouse suites: 310 pass, 126 skipped (ClickHouse e2e)Remaining after this: 16
execute,executeQueryBuilder,executeRawSqlare the QuerySpec and raw-SQL surfaces; forcing them intoQueryDefwould be a semantics rewrite.ZoneDetail(3 compiles),ZoneBreakdown(4, with a dependent 4th query),servicePlanetScaleStats(6)compileUnion, which has norowSchemahook at allserviceOperations(161 lines),listPods,hostInfraTimeseries,spanHierarchy(sequential probe + fallback),serviceDbQuerySummary,servicePlatforms🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.