Repository navigation
refactor: Share PromQL chart planning and rows between app and MCP - #3529
Conversation
🦋 Changeset detectedLatest commit: fe3ecd0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
PR Review
3 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 3 minor None could be anchored to changed lines; they are listed below. Findings outside the changed lines3 minor
Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
Deep Review✅ No critical issues found. This is a behavior-preserving refactor that consolidates two drifting copies of PromQL chart planning and row-shaping into one shared module ( Prior feedback — resolved. The reported crash (
The jscpd duplicate-code advisory names clones in 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Reviewers (1): direct-analysis (correctness, previous-comments, maintainability, performance). Testing gaps: The moved common-utils suite (+512 lines) and updated MCP suite (+60 lines) carry the behavior forward and cover the new No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
4ef1631 to
3eb1605
Compare
🔴 Tier 4 — CriticalTouches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI. Why this tier:
Review process: Deep review from a domain expert. Synchronous walkthrough may be required. Stats
|
E2E Test Results✅ All tests passed • 464 passed • 1 skipped • 1157s
Tests ran across 4 shards in parallel. |
3eb1605 to
21704a9
Compare
| @@ -615,6 +627,22 @@ export function hashCode(str: string) { | |||
| return hash; | |||
| } | |||
|
|
|||
| /** A chart's granularity, with 'auto' (or none) resolved for its date range. */ | |||
| export function getTimeChartGranularity<T extends string>( | |||
There was a problem hiding this comment.
🔵 minor — The CLI's ported getTimeChartGranularity now duplicates this function, and its @source tag is stale
packages/cli/src/shared/tileConfig.ts:261-275 is a copy tagged @source packages/app/src/ChartUtils.tsx (getTimeChartGranularity), and it hardcodes 80. That function no longer exists in ChartUtils.tsx; the canonical version is now in common-utils/core/utils. Have the CLI import getTimeChartGranularity and TIME_CHART_AUTO_GRANULARITY_BUCKETS from @hyperdx/common-utils/dist/core/utils, delete the port, and run yarn ratchet:update.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
21704a9 to
2fbe910
Compare
bdb5fa0 to
15616d3
Compare
|
Hit a bug while testing the next PR up the stack: Bug: large instant clickstack_promql results crash with Cannot read properties of undefined (reading 'length') Repro: run clickstack_promql with queryType: "instant" and an expression that returns over 50k characters. For example, increase(hyperdx_alerts_webhook_deliveries_total[$__range]) over a two-week range returns 130 series with 28 labels each. The same expression wrapped in sum by (outcome) works, because its result is small. Cause: introduced in 5796ff7.
|
Whooops, thanks for finding that. Should be fixed now in f9abb1e |
f9abb1e to
fe3ecd0
Compare
fe3ecd0 to
427ed56
Compare
427ed56 to
c60938c
Compare
c60938c to
d3410e5
Compare
The app and MCP each had their own copy of PromQL query planning and result shaping. Move it to common-utils core/promqlChart.ts and use it from both, so MCP returns exactly what the dashboard draws. MCP table tiles now return a column per label, capped at 10,000 rows, and histogram heatmaps return rows keyed by le. Heatmap auto steps are sized for 245 buckets, as in the app. The app behaves as before.
Replace variable-key object accesses with .at()/Map lookups so common-utils stays within its --max-warnings 80 budget.
trimObject measured every field with JSON.stringify(value).length, which throws for undefined values because JSON.stringify(undefined) returns undefined. PromQL table and histogram tiles started returning seriesLabels: undefined, so any instant table result over 50k characters crashed with "Cannot read properties of undefined (reading 'length')". Drop undefined fields in trimObject, as JSON.stringify does for the whole object, and omit seriesLabels from tile results that have none.
d3410e5 to
22e3141
Compare
Summary
Moves PromQL query planning and result shaping into common-utils so the app and MCP's
query_tileshare one copy instead of two that can drift. Follow-up to the review on #3528.common-utils/src/core/promqlChart.tsholds what was in the app'spromqlChartQuery.tsandChartUtils.tsx: resolving granularity and alignment, building the instant and range queries, parsing results, building chart, table and histogram rows, and reducing series.getTimeChartGranularity, theautobucket counts (80 for time charts, 245 for heatmaps) andMAX_TABLE_ROWSmove tocommon-utils/src/core/utils.ts.promqlTile.tsnow calls the shared code, so PromQL table tiles return a column per label (capped at 10,000 rows, withlimitsent on instant queries), histogram heatmaps return rows keyed byle, and heatmapautosteps match the app. Time chart and reduced tiles return the same rows as before.le) throwsPromqlChartError, which MCP reports as a user error.How to test
References