feat(query-engine): migrate spanHierarchy and the remaining tail (55/61) - #346
Merged
Conversation
Three defs: the recent-window probe, the unbounded fallback probe, and the pruned hierarchy read. All three carry cache: undefined on purpose. The handler keeps a single cachedDirect around the whole probe-then-read sequence, so the probe only fires on an outer cache miss. Caching them individually would run the probe on every request and cache a result nobody asked for -- and the probe exists precisely because trace_detail_spans is partitioned by toDate(Timestamp), where an unpruned hierarchy read is p95 ~8.8s against ~2.3s pruned. Adds a `withDeps` helper. cachedDirect takes an Effect with no requirements, while runQuery reads WarehouseQueryService and QueryEngineService from context; withDeps supplies the instances already bound at the top of the group so a registry query can run INSIDE a cache wrapper. Without it the only options were hoisting the probe out of the cache (losing the miss-only property) or threading services through every call site. Verified: apps/api typecheck; SQL baseline byte-identical; routes + warehouse suites 310 pass.
withDeps was an anti-pattern. It re-provided WarehouseQueryService and QueryEngineService into an Effect that read them from context, using the very instances already bound as values three lines above -- laundering a requirement purely to satisfy cachedDirect's R = never. makeQueryRunners takes those services as values once per handler group and returns runQuery/runQueryFirst closed over them. Every call site is unchanged (`runQuery(def, tenant, payload)`), but the effects now carry R = never, so a registry query composes inside a cache wrapper with no ceremony. spanHierarchy's probe-inside-cachedDirect works for the right reason rather than by re-injection. Verified: apps/api typecheck; SQL baseline byte-identical; routes + warehouse suites 310 pass.
Network reads a counter family, everything else a gauge family, so they are two defs rather than one def with a branch -- the row shapes differ and the handler maps them differently. Both keep the id "hostInfraTimeseries", which is what their spans already report; renaming would break continuity of existing telemetry for no gain. hostMetricSpec joins the pod/node/workload specs in query-helpers: the def needs metricName and groupByAttributeKey, the handler needs unit and isNetwork. Verified: apps/api typecheck; SQL baseline byte-identical. Local test suites not re-run for this commit -- CI covers them.
This was referenced Aug 4, 2026
🍁 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 #345. Migrates
spanHierarchy, the last of the sequential/stateful handlers.Why this one was left for last
The probe result feeds the main query's time window, and the whole sequence sits inside a single
cachedDirectso the probe only fires on a cache miss.trace_detail_spansis partitioned bytoDate(Timestamp); an unpruned hierarchy read is p95 ~8.8s vs ~2.3s pruned, so that probe is load-bearing.What
Three defs — recent-window probe, unbounded fallback probe, pruned hierarchy read — all with
cache: undefinedon purpose. The handler keeps the outercachedDirect. Caching them individually would run the probe on every request and cache a result nobody asked for.Adds a
withDepshelper:cachedDirecttakes an Effect with no requirements, whilerunQueryreads its services from context.withDepssupplies the instances already bound at the top of the group, letting a registry query run inside a cache wrapper. The alternatives were hoisting the probe out of the cache (losing the miss-only property) or threading services through all 55 call sites.Testing
apps/apitypecheck cleanRemaining: 6
execute,executeQueryBuilder,executeRawSqlare the QuerySpec and raw-SQL surfaces.serviceOperations(161 lines, 4 compiles),cloudflareInfraZoneBreakdown(4 compiles, the 4th dependent on topKeys derived from the first three),hostInfraTimeseries(branches into two separate compile+return paths).🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.