Skip to content

feat(query-engine): migrate Cloudflare/PlanetScale handlers to the registry (45/61) - #345

Merged
Makisuo merged 4 commits into
mainfrom
feat/query-registry-integrations
Aug 4, 2026
Merged

feat(query-engine): migrate Cloudflare/PlanetScale handlers to the registry (45/61)#345
Makisuo merged 4 commits into
mainfrom
feat/query-registry-integrations

Conversation

@Makisuo

@Makisuo Makisuo commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

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:

const filters = toCloudflareFilters(payload)
const [totalRows, bucketRows] = yield* Effect.all(
  [
    runQuery(Queries.cloudflareInfraZoneHostTotals, tenant, payload),
    runQuery(Queries.cloudflareInfraZoneHostTimeseries, tenant, payload),
  ],
  { concurrency: 2 },
)

Design notes

  • Sub-queries keep their own ids. cloudflareInfraZoneHostTotals and ...HostTimeseries are distinct spans and distinct cache keys; folding them under the handler name would merge unrelated cache entries.
  • toCloudflareFilters is computed in both the def and the handler. Deliberate: it's a pure function of the payload so the two cannot drift, and ignoredFilters (which filters a metric family couldn't honor) is presentation, not query construction.
  • These live app-side, in apps/api/src/routes/queries.ts, because @maple/query-engine-integrations depends on @maple/query-engine — declaring them in the core registry would invert that edge.
  • planetscaleInfraTimeseries folds its branch/no-branch conditional into compile, matching how serviceUsage handles 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:

  1. Dead 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 — latencyCompiled appears in five. Scoping the count per handler block removed 17 declarations that would otherwise have gone on compiling queries nobody ran.
  2. The extracted compile expressions lost their CH.compile prefix, because the balanced-paren capture returned the argument list alone.

Testing

  • apps/api typecheck clean
  • SQL baseline byte-identical (14 tests) — all 45 migrated handlers emit exactly the SQL they did before
  • apps/api routes + warehouse suites: 310 pass, 126 skipped (ClickHouse e2e)

Remaining after this: 16

  • 3 that should NOT be migratedexecute, executeQueryBuilder, executeRawSql are the QuerySpec and raw-SQL surfaces; forcing them into QueryDef would be a semantics rewrite.
  • 3 Cloudflare multi-queryZoneDetail (3 compiles), ZoneBreakdown (4, with a dependent 4th query), servicePlanetScaleStats (6)
  • 3 facetscompileUnion, which has no rowSchema hook at all
  • 7 core multi-queryserviceOperations (161 lines), listPods, hostInfraTimeseries, spanHierarchy (sequential probe + fallback), serviceDbQuerySummary, servicePlatforms

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Makisuo added 4 commits August 5, 2026 01:10
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.
@Makisuo
Makisuo merged commit a645f09 into main Aug 4, 2026
2 checks passed
@Makisuo
Makisuo deleted the feat/query-registry-integrations branch August 4, 2026 23:17
@railway-app
railway-app Bot temporarily deployed to maple / production August 4, 2026 23:18 Inactive
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🍁 Maple PR preview

Note

Preview resources were removed when this pull request closed.

Final commit a645f09 · View workflow run

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