Skip to content

feat(app): exemplar overlay for metric and PromQL time charts - #2808

Merged
jordan-simonovski merged 31 commits into
mainfrom
jordansimonovski/exemplars-overlay
Nov 26, 2026
Merged

jordan-simonovski merged 31 commits into
mainfrom
jordansimonovski/exemplars-overlay

Conversation

@jordan-simonovski

@jordan-simonovski jordan-simonovski commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

The feature itself. Stacked on #2807 (the chart-file refactor) — review that first; this diff is the feature only.

Fourth of the PRs replacing #2536.

What it does

Time charts on metric and PromQL sources can overlay exemplars — individual trace-linked points. Hovering a marker shows the exemplar's own value and time plus trace metadata, with a button to open the trace.

Off by default for the whole deployment behind NEXT_PUBLIC_ENABLE_EXEMPLARS, and per-chart behind enableExemplars.

The rule the whole feature turns on

A marker sits at the trace's own measurement on the chart's shared axis. So it is only honest when the chart draws one line, in the same unit. That is enforced in four places, and most of the review findings on the original PR were cases where one of them leaked:

  1. A single non-ratio histogram series with no group by.
  2. An aggregation that leaves the axis on the observation scale — a count of observations is not a duration, so a count-aggregated histogram gets no markers.
  3. For PromQL, an expression that plots a duration, with the duration call spanning the whole expression (histogram_quantile(...) * 1000 renders a different unit than its exemplars carry).
  4. A rendered-series count taken from the main query, not the exemplar response. Prometheus only returns series that carry a sampled exemplar, so the response answers "how many series had exemplars", not "how many lines are drawn" — a multi-line chart whose buffer happened to hold one series' worth would otherwise get markers of unknown provenance.

Where a marker cannot be drawn honestly, it is dropped

Not moved. Outside the rendered window by more than one bucket, or below a fitted y-axis floor, and it does not render — with the count surfaced on the chart, because an overlay that silently thins out is worse than one that explains itself. The exception is above the ceiling, where pinning reads as "at least this high" and the hover card carries the real number.

Note on common-utils

Those primitives ship in this PR rather than their own. Every one of the exemplar exports is consumed only by the app — landing them alone would fail the unused-export check with no consumer.

Included from the original PR's review rounds

Four rounds, roughly 1 P0/P1 and 15 P2s each. The substantive ones: the hover card now shows value and time (both clamps cite it as their justification and it showed neither); the PromQL aggregation parsing that decides series identity, including label matchers and quoted label names; the ClickHouse scan's ex_TimeUnix bound, which was previously filtering on the row time while projecting the exemplar time; the query-key quantisation, which now fetches the window it keys; and the card lifecycle across zoom, live tail and display-type switches.

Remaining P2/P3s are tracked in #2804 rather than blocking this.

Verification

make ci-lint, make ci-unit (5,350 tests), dashboard E2E 80 passed / 0 failed (2 flakes on listing-page specs that draw no chart).


Note

Medium Risk
Large UI and query surface (marker lifecycle, PromQL series heuristics, new Prometheus calls) with careful fail-safe behavior, but mistakes could mis-attribute traces or add query load; mitigated by feature flags and eligibility guards.

Overview
Adds an exemplar overlay on metric and PromQL time charts: trace-linked diamond markers at each exemplar’s measured value/time, with hover and pin cards, trace metadata from a configurable trace source, and navigation into search or the standalone trace page. The capability is gated by NEXT_PUBLIC_ENABLE_EXEMPLARS and per-chart enableExemplars, with eligibility rules in the chart editor (single histogram line, duration-scale aggregation, or PromQL expressions that plot duration).

End-to-end wiring includes Prometheus query_exemplars (with abortable requests), Grafana-style sampling and clamping (useExemplarMarkers, exemplarPoints, y/x bounds so outliers don’t flatten the axis), team maxExemplars, display-settings UI, and toolbar notices for fetch errors or clamped markers. Alert/external chart config explicitly drops enableExemplars and exemplarTraceSourceId so inline alerts don’t blank chartConfig.

Reviewed by Cursor Bugbot for commit 4824baf. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 26, 2026 10:39pm UTC
hyperdx-storybook Ready Ready Preview Nov 26, 2026 10:39pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4824baf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Minor
@hyperdx/app Minor
@hyperdx/api Minor
@hyperdx/otel-collector Minor

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

@greptile-apps

greptile-apps Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds exemplar overlay feature to time charts.

The PR appears safe to merge based on this re-review; no new blocking issue was established.

Summary

The PR adds a deployment-gated, per-chart exemplar overlay for eligible metric and PromQL time charts, including trace navigation, editor settings, and marker lifecycle handling. The changes since the previous review primarily merge updates from the base branch; no new actionable issue attributable to those changes was established.

Reviews (14) · Last reviewed commit: "Merge remote-tracking branch 'origin/jor..."

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

<!-- deep-review -->

Deep Review

⚠️ This review did not complete. Read the Coverage section before treating anything below as a verdict.

Bash was unavailable for the entire session — every invocation, including with the sandbox disabled, failed with bwrap: Can't create file at /home/.mcp.json: Permission denied. There are also no Grep or Glob tools registered in this session, and WebFetch was not permitted. Read against an exact path was the only working file access.

Consequence: the diff was never computable. git diff, git log, and gh pr diff were all unreachable, so there is no verified list of changed files and no way to distinguish lines this PR added from lines already present at eb1ac50b. I reconstructed part of the feature surface by following import statements from a seed path, and reviewed what I could read directly. Twelve reviewer sub-agents were dispatched against that reconstructed scope; their reports did not arrive before output was required, so none of their findings are represented here. The findings below are only those I verified myself by reading the files.

✅ No critical issues found in the code I was able to read — this is not a clean bill of health for the PR, since coverage was partial.

🟡 P2 -- recommended

  • packages/app/src/components/DBTimeChart/useExemplarCard.ts:166 -- the range-change effect clears pinnedExemplar and hoveredExemplar but leaves clampDroppedCount untouched, so the "N exemplar markers fall outside the chart's plotted range" notice built at line 264 can outlive the range whose clamping produced it.
    • Fix: reset clampDroppedCount to 0 inside the same rangeKey effect that clears the two card states.
🔵 P3 nitpicks (2)
  • packages/app/src/components/DBTimeChart/useExemplarCard.ts:270 -- reportClampDropped hands out the raw setClampDroppedCount dispatcher, so its exported type accepts an updater function while the name and the consuming call site imply a plain count.
    • Fix: wrap it in a useCallback narrowed to (count: number) => void so the cross-module contract matches the name.
  • packages/app/src/components/Exemplars/exemplarPoints.ts:206 -- when the y-domain is non-numeric and visibleSeriesMax is 0, bounds collapse to {min: 0, max: 0} and clampExemplarY returns Math.min(y, 0), drawing every marker at 0 instead of at its own value.
    • Fix: treat a non-positive visibleSeriesMax as a degenerate ceiling and return early, leaving the value unclamped rather than flattening markers to the floor.

Notes on what I did verify

Three things I checked that are correct, recorded so they are not re-flagged on a future pass:

  • Exemplar.timestamp is epoch milliseconds (exemplarPoints.ts:74 divides by 1000 for the chart's second-based x unit), so exemplarTraceWindow(exemplar.timestamp) in useExemplarCard.ts:227 is operating in the right unit.
  • The window-split reduce at exemplarPoints.ts:147 has no initial value, but the split only runs when ordered.length > maxExemplars >= windowCount, so every slice is non-empty and it cannot throw on an empty array.
  • quantize.ts fetches the same quantised window it keys on (floor start / ceil end), so the cache entry is a genuine superset of every raw window mapping to that key.

Reviewers (1 of 13 reported): learnings-researcher.

Dispatched but no results returned — none of their analysis is in this report: correctness, adversarial, security, testing, maintainability, project-standards, kieran-typescript, julik-frontend-races, performance, reliability, api-contract, agent-native.

Coverage limitations:

  • No diff. Changed-file list and added-vs-pre-existing attribution are both unverified; findings are scoped to code I read, not to this PR's actual delta.
  • Files read: DBTimeChart/DBTimeChart.tsx (partial), DBTimeChart/useExemplarCard.ts (lines 1–279), DBTimeChart/index.ts, Exemplars/index.ts, Exemplars/exemplarPoints.ts, hooks/useExemplars/quantize.ts, hooks/useExemplars/index.ts, root package.json.
  • Not reviewed at all: hooks/useExemplars/useExemplars.ts, exemplarNormalize.ts, useExemplarTraceMeta.ts (the fetch, normalisation and trace-lookup layer), HDXMultiSeriesTimeChart.tsx (marker rendering and the drop reporting that the P2 above depends on), ExemplarDot.tsx, ExemplarHoverCard.tsx, useChartToolbarItems, and everything under packages/common-utils/ — which is where the ClickHouse ex_TimeUnix scan, the PromQL duration/aggregation gating, and the four series-identity invariants described by the author actually live. The load-bearing correctness claims of this feature are in the unreviewed set.
  • No test files were located or assessed, so no statement is made about test coverage in either direction.
  • docs/solutions/ does not exist in this repo, so there were no prior learnings to apply.

Recommendation: re-run this review in an environment with working git and search tools before relying on it as a merge gate.

@jordan-simonovski
jordan-simonovski force-pushed the jordansimonovski/exemplars-overlay branch from 186c54f to 082981c Compare August 5, 2026 13:02
@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches 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:

  • Critical-path files (2) — tenancy, public API, or shipped database config:
    • packages/api/src/models/team.ts
    • packages/api/src/routers/external-api/v2/utils/alertChartConfig.ts
  • Query rendering engine substantially modified — 354 lines (bar: 150). Every chart, search, and alert query flows through this code:
    • packages/common-utils/src/core/renderChartConfig.ts
  • Cross-layer change: touches frontend (packages/app) + backend (packages/api) + shared utils (packages/common-utils)

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 33
  • Production lines changed: 2791 (+ 3525 in test files, excluded from tier calculation)
  • Critical-path lines changed: 361
  • Branch: jordansimonovski/exemplars-overlay
  • Author: jordan-simonovski

To override this classification, remove the review/tier-4 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 480 passed • 1 skipped • 1090s

Status Count
✅ Passed 480
❌ Failed 0
⚠️ Flaky 11
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

<!-- deep-review -->

Deep Review

⚠️ Partial run — read the coverage note before treating this as a clean bill of health. Two things degraded this review. (1) Bash is non-functional in this environment (every invocation, including echo, fails at the sandbox layer), so git diff could not be computed and scope was reconstructed by reading the working tree; Grep/Glob were also unavailable, leaving Read as the only working tool. (2) Of 12 dispatched reviewers, only 1 (testing) returned before output was required. The correctness, adversarial, security, reliability, performance, api-contract, frontend-races, maintainability, TypeScript, project-standards, and agent-native passes did not report. Absence of P0/P1 findings below reflects that, not a verified-clean diff.

✅ No critical issues found by the one reviewer that completed.

🟡 P2 — recommended

  • packages/app/src/components/DBTimeChart/useExemplarCard.ts:236 — the 273-line hover/pin card state machine has no dedicated test, and the only suite that renders it never hovers, clicks, pins, or switches display type.
    • Fix: Add a renderHook test covering pin/unpin precedence over hover, Escape dismissal of only the pinned card, display-type change clearing both cards, exemplarNotice precedence when a fetch error and a dropped-marker count coexist, and the constructed trace deep-link URL.
  • packages/app/src/HDXMultiSeriesTimeChart/useExemplarMarkers.ts:176 — the hovered-marker-dropped guard, the brush-zoom click suppression, and the onExemplarsDropped count argument are all unexercised; the existing suite only covers the pinned-marker guard and the domain-change guard.
    • Fix: Extend useExemplarMarkers.test.ts to assert hover-end fires when a hovered marker leaves the set, that a post-brush synthetic click is swallowed and suppressNextClickRef is reset, and that onExemplarsDropped receives a positive count rather than only an empty points array.
  • packages/app/src/hooks/useExemplars/useExemplarTraceMeta.ts:25 — nothing covers this hook's query gating, its per-source expression overrides, or the root-span ordering in the SQL it builds; the one suite that touches it mocks it wholesale.
    • Fix: Add a test asserting the query stays disabled without a trace id or with a non-trace source kind, that source-supplied serviceNameExpression / traceIdExpression / parentSpanIdExpression replace the defaults, and that an empty result set resolves to null instead of throwing.
  • packages/app/src/components/DBTimeChart/useChartToolbarItems.tsx:127 — the exemplar notice toolbar item is untested in both its fetch-error and dropped-marker wordings.
    • Fix: Assert the exemplar-notice item renders only for a non-null notice and that its tooltip label equals the string passed in.
🔵 P3 nitpicks (1)
  • packages/app/src/hooks/useExemplars/quantize.ts:25 — quantizeStart / quantizeEnd have no test pinning their exact outputs, including a range short enough to quantize into a single bucket.
    • Fix: Add a unit test asserting floor/ceil behaviour exactly on and just across a 30s boundary, and that a degenerate range does not collapse the fetch window to zero width.

Reviewers (1 of 12 completed): testing. Dispatched but not returned: correctness, adversarial, security, reliability, performance, api-contract, frontend-races, maintainability, kieran-typescript, project-standards, agent-native.

Testing gaps:

  • useExemplarCard.ts (273 lines) is covered only incidentally, with its data hooks mocked out and no interaction ever triggered.
  • useExemplarTraceMeta.ts SQL construction and gating are unverified by any suite.
  • quantize.ts outputs are never asserted, only consumed opaquely.
  • Conversely, the eligibility gates (isExemplarEligible, isPromqlExemplarEligible) and the SQL renderers were found to carry thorough negative-case coverage — ratio, group-by, multi-series, count/sum aggregation, non-histogram types, top-level PromQL binary operators, and non-spanning duration calls. That is the best-tested part of the change.

Two unverified leads worth chasing before merge — surfaced during scope reconstruction, not confirmed by a reviewer, so deliberately left unscored:

  • prometheusApi.queryExemplars in packages/app/src/api.ts posts to v1/prometheus/query_exemplars; a partial read of packages/api/src/routers/api/prometheus.ts found only /query_range, /query, and /label/:name/values. Confirm the path resolves (a direct-to-Prometheus base URL or a rewrite would explain it) before assuming the PromQL half of the feature is wired.
  • No editor UI referencing enableExemplars or exemplarTraceSourceId was located across the chart-editor components, while in-code comments describe a toggle "next to 'As Ratio'". Confirm whether the per-chart flag is settable outside hand-edited dashboard JSON.

knudtty
knudtty previously approved these changes Nov 24, 2026
…es' into jordansimonovski/exemplars-overlay

# Conflicts:
#	packages/api/src/models/team.ts
#	packages/app/package.json
#	packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx
#	packages/app/src/HDXMultiSeriesTimeChart/__tests__/useChartScales.test.ts
#	packages/app/src/HDXMultiSeriesTimeChart/useChartScales.ts
#	packages/app/src/components/DBTimeChart/DBTimeChart.tsx
#	packages/common-utils/package.json
#	packages/common-utils/src/core/renderChartConfig.ts
#	packages/common-utils/src/types.ts
…t-chart-files

# Conflicts:
#	packages/app/src/HDXMultiSeriesTimeChart.tsx
…es' into jordansimonovski/exemplars-overlay

# Conflicts:
#	packages/app/package.json
#	packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx
*
* The chart-editor toggle and the SQL renderer both delegate here so they can't
* drift apart.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 P1 — Exemplar-eligible aggFns include ones histogram charts cannot render

translateHistogram and translateExponentialHistogram (packages/common-utils/src/core/histogram.ts:75-86, 263-276) only support quantile and count, and throw for anything else. So avg/min/max/last_value/any/none in EXEMPLAR_COMPATIBLE_AGG_FNS can never apply, and METRIC_INELIGIBLE in exemplarToggle.ts tells users to pick avg/min/max/last value, which breaks the main chart query. Reduce the set to quantile and change the copy to say a quantile is required.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

else if (c === quote) quote = null;
continue;
}
if (c === '"' || c === "'") quote = c;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Paren walk ignores PromQL backtick raw strings

The quote tracker only recognises " and '. A ) inside a backtick matcher (e.g. histogram_quantile(0.9, x{path=`/a)`})) closes the call early and marks a valid expression ineligible. promqlSeriesLabels.ts already handles backticks, so add the backtick to the quote check here too: c === '"' || c === "'" || c === ''`.

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

'none',
]);

export function isExemplarEligible({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Eligibility check ignores formulas, so a formula like A * 1000 gets markers in the wrong unit

A metric chart with one histogram series and a formula such as A * 1000 (with showOperandSeries: false) draws one line, so plottedSeriesCount is 1 and isExemplarEligible passes. The axis is then in ms while the markers are in seconds. This is the same failure the PromQL whole-expression rule exists to prevent. Fix: pass hasFormulas: (config.formulas?.length ?? 0) > 0 from renderMetricExemplarsChartConfig and from getExemplarToggleState (form formulas), and refuse when it is true.

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

// Outline that contrasts with the background (dark in light mode, light
// in dark mode) rather than matching it — the amber fill alone is
// low-contrast on a white background, so the marker needs a defined edge.
stroke="var(--color-text-default, #1a1a1a)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Marker outline uses an undefined token, so it is always #1a1a1a, even in dark mode

--color-text-default is not defined anywhere in the app theme (_tokens.scss defines --color-text and --click-global-color-text-default), so the stroke always falls back to near-black. The comment promises a light outline in dark mode, which never happens. The data-viz conventions also forbid reusing --color-text-* for chart marks. Fix: use an existing chart token for the outline (e.g. a background or contrast chart token from _chart-categorical-tokens.scss) and drop the hex fallbacks.

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

if (!enabled || configType === 'sql') {
return { showExemplars: false };
}
if (configType === 'promql') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Toggle is offered on ClickHouse-backed PromQL connections, where exemplars are always empty

queryExemplarsHandler in packages/api/src/routers/api/prometheus.ts returns {status:'success', data: []} for any connection where isPrometheusEndpoint is false. On those charts the editor still enables 'Show exemplars', the overlay stays empty, and no notice explains why. Fix: either gate showExemplars (or set exemplarIneligibleReason) on the connection being a Prometheus endpoint, or have the API return a reason that useExemplarCard surfaces as the notice.

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

defaultValue={DEFAULT_MAX_EXEMPLARS}
placeholder={`default = ${DEFAULT_MAX_EXEMPLARS}, 0 = unlimited`}
min={0}
max={1000}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — 'Max exemplars per chart' accepts 0 ('unlimited') and up to 1000, but both fetch paths cap at 200

EXEMPLAR_QUERY_LIMIT = 200 bounds the ClickHouse scan (LIMIT 200) and capExemplarsPerBucket on the Prometheus path. So 'unlimited', 500 and 1000 all draw at most 200 markers. Fix: cap the form and TeamClickHouseSettingsUpdateSchema at EXEMPLAR_QUERY_LIMIT and reword the '0 = unlimited' placeholder, or raise the fetch limit to follow the team setting.

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

return null;
}
const s = traceSource;
const from = s.from.databaseName

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Trace-meta query builds the table name by hand instead of using tableExpr/chSql

The table is built as `\`${databaseName}\`.\`${tableName}\ `` by string concatenation. That breaks on names containing a backtick, and it duplicates tableExpr in `packages/common-utils/src/clickhouse/index.ts`, which binds them as `Identifier` params. Fix: build the query with `chSql`, `tableExpr({ database, table })` and parameters, as `renderMetricExemplarsChartConfig` does.

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

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

onExemplarSelect?.(exemplar, cx, cy);
},
[onExemplarSelect, suppressNextClickRef],
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pin close leaves hover stuck

Medium Severity

Pinning an exemplar clears the parent hover card but leaves hoveredExemplarKey set in the marker layer. Closing the pin with Escape (cursor still on the marker) therefore hides the card while isExemplarHovered stays true, so the series tooltip stays suppressed until the pointer leaves and re-enters the marker.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 29d5ae2. Configure here.

// Reported from an effect, not the memo, so this never sets state during render.
useEffect(() => {
onExemplarsDropped?.(droppedCount);
}, [droppedCount, onExemplarsDropped]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quantized fetch inflates drop notices

Medium Severity

Exemplar fetches use a 30s-quantized window, but drop counting compares markers to the live x-domain with only one granularity of tolerance. On short live-tail ranges whose bucket is finer than 30s, overhang markers are counted as dropped and the toolbar warning stays up even though the overlay is behaving as designed.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 29d5ae2. Configure here.


function collapsesHistogramBuckets(expression: string | undefined): boolean {
return !!expression && HISTOGRAM_QUANTILE_CALL.test(expression);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

histogram_avg keeps le labels

Low Severity

isPromqlExemplarEligible treats histogram_avg(...) as a duration-valued overlay, but collapsesHistogramBuckets only matches histogram_quantile. For classic histograms the raw exemplar series still carry le, so a single histogram_avg line is counted as many series and the overlay is suppressed with a false multiple-series notice.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 29d5ae2. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

AI review gate — Cursor Bugbot found issues

  • Cursor Bugbot found issues that are not resolved (check concluded 'neutral').

Unresolved findings (3):

What to do:

  • Fix the findings and push. The reviewer re-reviews the new commit and the gate re-runs by itself.
  • Finding wrong, or reviewer stuck? Ask a human with write access who is not the PR author to approve this exact commit, then re-run the gate. Their approval stands in for the AI review (a new push needs a new approval).

Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically.

knudtty
knudtty previously approved these changes Nov 25, 2026
Base automatically changed from jordansimonovski/split-chart-files to main November 25, 2026 18:14
const [startDate, endDate] = fetchRange;
const resp = await prometheusApi.queryExemplars(
{
query: promqlExpression,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 P1 — PromQL exemplar fetch sends the raw expression, so macros, dashboard variables and filters are never expanded

The main chart builds its query through getPromqlChartQueries (in packages/common-utils/src/core/promqlChart.ts), which calls substitutePromqlChartConfigTemplates (in macros.ts). That expands $__rate_interval, $__interval and $__range, resolves $var references, and injects config.filters matchers. This hook passes getExemplarPromqlExpression(config.promqlExpression) to /query_exemplars without any of that. Two things break. The standard histogram_quantile(0.95, sum by (le)(rate(x_bucket[$__rate_interval]))) fails to parse upstream, so the chart shows the error notice instead of markers. On a dashboard with a service filter or variable, the markers come from every service. Fix: run the config through substitutePromqlChartConfigTemplates({...config, dateRange: fetchRange}) before choosing the expression. Add a test that uses a macro and a filter.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

// other services/routes/tenants) that share the same metric name.
};

const where = await renderWhere(whereConfig, metadata);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 P1 — Metric exemplar scan skips dashboard variable substitution, so tiles that use variables query a raw $var

renderChartConfig calls substituteChartConfigVariables(rawChartConfig) first (line ~3503). renderMetricExemplarsChartConfig passes the unsubstituted config to renderWhere. Dashboard tiles arrive with variables: tileVariables (DBDashboardPage.tsx:856), so a where or aggCondition such as ServiceName IN ($service) reaches ClickHouse literally: the query errors or matches the wrong rows. Fix: call substituteChartConfigVariables(chartConfig) at the top of renderMetricExemplarsChartConfig, the same way renderChartConfig does.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

// on time charts. Sourced natively for metric/PromQL sources and generated
// per time bucket for trace sources. The UI gates the toggle on supported
// source kinds; off by default so the extra exemplar query never runs.
enableExemplars: z.boolean().optional(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Schema doc says exemplars are 'generated per time bucket for trace sources', but trace sources are not supported

EXEMPLAR_SUPPORTED_KINDS in useExemplars.tsx is Metric and Promql only ('Trace-generated exemplars are added in a follow-up'), and getExemplarToggleState hides the toggle on trace sources. Remove the trace-source claim from the enableExemplars and ExemplarSchema comments, since API and MCP authors read them.

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

…plars-overlay

# Conflicts:
#	packages/app/src/HDXMultiSeriesTimeChart/MemoChart.tsx
#	packages/app/src/HDXMultiSeriesTimeChart/__tests__/useChartScales.test.ts
#	packages/app/src/HDXMultiSeriesTimeChart/useChartScales.ts
#	packages/app/src/components/DBTimeChart/DBTimeChart.tsx
#	packages/app/src/components/DBTimeChart/__tests__/DBTimeChart.test.tsx
#	packages/app/src/components/DBTimeChart/useChartToolbarItems.tsx
Comment thread packages/app/src/api.ts
query: params.query,
start: String(params.start),
end: String(params.end),
connectionId: params.connectionId,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 P1 — PromQL exemplar request sends connectionId instead of sourceId, so the API rejects every call with a 400

The /query_exemplars handler in packages/api/src/routers/api/prometheus.ts:634 calls resolvePromqlTarget(teamId, params.sourceId). That call returns 400 'missing required parameter: sourceId' when there is no sourceId (packages/api/src/controllers/promql.ts:389), and it ignores connectionId, database and table. So every PromQL chart with exemplars enabled draws no markers and shows the error notice. Fix: give queryExemplars a sourceId: string param, as queryRange and query have, drop connectionId/database/table, and pass source.id from useExemplars.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

timestamp: 1700000000 + i,
}),
);
mockQueryExemplars.mockResolvedValue({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — PromQL fetch tests mock queryExemplars but never check the params it is called with

The tests only check whether prometheusApi.queryExemplars was called and stub its response. That is why the missing sourceId and the unexpanded $__rate_interval both pass. Fix: add expect(mockQueryExemplars).toHaveBeenCalledWith(expect.objectContaining({ sourceId, query: <expanded expression> }), expect.anything()), using a config whose expression contains a macro and a filter.

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 4 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4824baf. Configure here.


// No point paying for a proxy round-trip per window on a chart that can never
// show the result.
const enabled = wantsExemplars && !tooManySeries;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ineligible overlay stays silent

Low Severity

useExemplars gates metric charts only on enableExemplars and series count, not isExemplarEligible. A count or grouped histogram that still has the overlay on runs a successful empty fetch, so dropped stays unset and the toolbar never explains why markers disappeared.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4824baf. Configure here.

@jordan-simonovski
jordan-simonovski merged commit 4188b80 into main Nov 26, 2026
34 of 35 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 4824baf5 Deployed Nov 26, 2026 by vercel[bot]
Preview – hyperdx-storybook — 4824baf5 Deployed Nov 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants