Repository navigation
feat(app): add a duration heatmap view to trace search #3184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
083db6d
75c193c
4918bf5
8b07158
cfcd014
21d2698
d204045
2473a2e
5a4294c
520d3ef
fa48608
f9b80ac
b181834
72b9fb3
7e7a232
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@hyperdx/app': minor | ||
| --- | ||
|
|
||
| Add a RED/Heatmap switch to the trace search results view. Heatmap shows the duration distribution over time as the same tile the dashboard renders, and the choice is kept in the URL so a reload or a shared link reopens the same view. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ import { | |
| Group, | ||
| Modal, | ||
| Paper, | ||
| SegmentedControl, | ||
| Select, | ||
| Stack, | ||
| Text, | ||
|
|
@@ -163,7 +164,12 @@ import DBSqlRowTableWithSideBar from './components/DBSqlRowTableWithSidebar'; | |
| import PatternTable from './components/PatternTable'; | ||
| import { DBSearchHeatmapChart } from './components/Search/DBSearchHeatmapChart'; | ||
| import DirectTraceSidePanel from './components/Search/DirectTraceSidePanel'; | ||
| import { TraceRedMetricsChart } from './components/Search/TraceRedMetricsChart'; | ||
| import { | ||
| TRACE_CHART_MODES, | ||
| TraceRedMetricsChart, | ||
| } from './components/Search/TraceRedMetricsChart'; | ||
| import { useHeatmapLiveTailGuard } from './components/Search/useHeatmapLiveTailGuard'; | ||
| import { useTraceChartModeReset } from './components/Search/useTraceChartModeReset'; | ||
| import SourceSchemaPreview, { | ||
| isSourceSchemaPreviewEnabled, | ||
| } from './components/SourceSchemaPreview'; | ||
|
|
@@ -1126,6 +1132,13 @@ function DBSearchPageContent() { | |
| ]).withDefault('results'), | ||
| ); | ||
|
|
||
| // RED vs heatmap for the trace results chart. URL state, like the page's | ||
| // other view toggles, so a reload or shared link keeps the view. | ||
| const [traceChartMode, setTraceChartMode] = useQueryState( | ||
| 'traceChartMode', | ||
| parseAsStringEnum([...TRACE_CHART_MODES]).withDefault('red'), | ||
| ); | ||
|
|
||
| // URL-only, not saved with the search: null uses the source default. | ||
| const [groupByParam, setGroupByParam] = useQueryState( | ||
| 'groupBy', | ||
|
|
@@ -1461,6 +1474,12 @@ function DBSearchPageContent() { | |
| // Same, for the histogram group by. Also set when a saved search switches the | ||
| // source, since the group by isn't part of the saved search. | ||
| const pendingGroupByReconcileRef = useRef<string | null>(null); | ||
| // Same, for the trace RED/Heatmap choice (see useTraceChartModeReset). | ||
| const { arm: armTraceChartModeReset, disarm: disarmTraceChartModeReset } = | ||
| useTraceChartModeReset({ | ||
| searchedSourceId: searchedSource?.id, | ||
| setTraceChartMode, | ||
| }); | ||
|
|
||
| const watchedSourceObj = useMemo( | ||
| () => inputSourceObjs?.find(s => s.id === watchedSource), | ||
|
|
@@ -1527,6 +1546,11 @@ function DBSearchPageContent() { | |
| const isCatchingUpToConfig = | ||
| !!watchedSource && watchedSource === searchedSource?.id; | ||
|
|
||
| // Re-selecting the searched source undoes a pick whose search hasn't run. | ||
| if (isCatchingUpToConfig) { | ||
| disarmTraceChartModeReset(); | ||
| } | ||
|
|
||
| if (isCatchingUpToConfig && savedSearchId == null) { | ||
| prevSourceRef.current = watchedSource; | ||
| if (rawSearchedConfig.source !== watchedSource) { | ||
|
|
@@ -1552,6 +1576,7 @@ function DBSearchPageContent() { | |
| // a freshly loaded page pushes its defaults into the search config. | ||
| if (!isCatchingUpToConfig) { | ||
| pendingGroupByReconcileRef.current = watchedSource ?? null; | ||
| armTraceChartModeReset(watchedSource ?? null); | ||
| // If the user isn't in a saved search (or the source is different from the saved search source), reset fields | ||
| if (savedSearchId == null || savedSearch?.source !== watchedSource) { | ||
| setValue('select', ''); | ||
|
|
@@ -1582,6 +1607,8 @@ function DBSearchPageContent() { | |
| searchedSource?.id, | ||
| rawSearchedConfig.source, | ||
| setSearchedConfig, | ||
| armTraceChartModeReset, | ||
| disarmTraceChartModeReset, | ||
| ]); | ||
|
|
||
| const retainCompatibleFiltersAndGroupBy = useStableCallback( | ||
|
|
@@ -2123,6 +2150,43 @@ function DBSearchPageContent() { | |
| [isCustomGroupBy, histogramTimeChartConfig, searchedSource], | ||
| ); | ||
|
|
||
| // The RED/Heatmap area renders only where it fits: not on a compact viewport, | ||
| // and not with a custom group-by, which the RED tiles' fixed grouping can't | ||
| // honor (the histogram can). The chart branch, the switch and the live-tail | ||
| // guard all read this, so they agree on which chart shows. | ||
| const traceChartsSource = | ||
| traceRedMetricsSource != null && !isCompact && !isCustomGroupBy | ||
| ? traceRedMetricsSource | ||
| : null; | ||
|
|
||
| // Base config for the trace heatmap, like the delta-view heatmap's. The | ||
| // table's sort is dropped: the chart keys its uPlot instance on the config, | ||
| // so sorting a column would otherwise rebuild it. | ||
| const traceHeatmapChartConfig = useMemo( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — The delta-mode 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would change the delta view's code path, which this PR otherwise leaves alone, so I'm keeping it out of this PR.
alex-fedotyev marked this conversation as resolved.
Resolved
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| () => | ||
| chartConfig == null | ||
| ? undefined | ||
| : ({ | ||
| ...chartConfig, | ||
|
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| orderBy: undefined, | ||
| dateRange: searchedTimeRange, | ||
| with: aliasWith, | ||
| } satisfies BuilderChartConfigWithDateRange), | ||
| [chartConfig, searchedTimeRange, aliasWith], | ||
| ); | ||
|
|
||
| // While the heatmap shows, live tail stays off as in delta and pattern modes: | ||
| // the guard turns it off and the Live option and Resume Live Tail are hidden. | ||
| // Uses the chart branch's conditions, so a stale ?traceChartMode=heatmap or a | ||
| // query error that hides the chart can't take live tail away. | ||
| const isHeatmapChartVisible = | ||
| analysisMode === 'results' && | ||
| traceChartsSource != null && | ||
| traceChartMode === 'heatmap' && | ||
| traceHeatmapChartConfig != null && | ||
| !hasQueryError; | ||
| useHeatmapLiveTailGuard({ isHeatmapChartVisible, isLive, setIsLive }); | ||
|
|
||
| const histogramGroupBySelect = ( | ||
| <SearchGroupBySelect | ||
| source={searchedSource} | ||
|
|
@@ -2692,7 +2756,7 @@ function DBSearchPageContent() { | |
| setInputValue={setDisplayedTimeInputValue} | ||
| onSearch={onTimePickerSearch} | ||
| onRelativeSearch={onTimePickerRelativeSearch} | ||
| showLive={analysisMode === 'results'} | ||
| showLive={analysisMode === 'results' && !isHeatmapChartVisible} | ||
| isLiveMode={isLive} | ||
| // Default to relative time mode if the user has made changes to interval and reloaded. | ||
| defaultRelativeTimeMode={ | ||
|
|
@@ -2915,11 +2979,34 @@ function DBSearchPageContent() { | |
| totalCountConfig={totalCountConfig} | ||
| enableParallelQueries | ||
| > | ||
| {histogramGroupBySelect} | ||
| {/* The heatmap doesn't group. */} | ||
| {isHeatmapChartVisible | ||
| ? null | ||
| : histogramGroupBySelect} | ||
| </SearchResultsCountGroup> | ||
| <Group gap="sm" align="center"> | ||
| {traceChartsSource != null && ( | ||
| <SegmentedControl | ||
| size="xs" | ||
| value={traceChartMode} | ||
| // RED is the default, so it clears the param | ||
| // rather than writing traceChartMode=red. | ||
| onChange={v => | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Switch options are hand-written rather than derived from
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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback narrows find's possibly-undefined result for the type. A new mode also needs its label in the switch, which sits next to the handler, so I left the two entries inline rather than add a label map. |
||
| setTraceChartMode( | ||
|
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| TRACE_CHART_MODES.find( | ||
| mode => mode === v && mode !== 'red', | ||
| ) ?? null, | ||
| ) | ||
| } | ||
| data={[ | ||
|
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| { label: 'RED', value: 'red' }, | ||
| { label: 'Heatmap', value: 'heatmap' }, | ||
| ]} | ||
| /> | ||
| )} | ||
| {shouldShowLiveModeHint && | ||
| denoiseResults != true && ( | ||
| denoiseResults != true && | ||
| !isHeatmapChartVisible && ( | ||
| <ResumeLiveTailButton | ||
| handleResumeLiveTail={handleResumeLiveTail} | ||
| /> | ||
|
|
@@ -2941,25 +3028,22 @@ function DBSearchPageContent() { | |
| </Group> | ||
| </Box> | ||
| {!hasQueryError && | ||
| // The three side-by-side RED tiles need room, so on a | ||
| // compact (narrow/mobile) viewport fall back to the | ||
| // single histogram. The RED tiles also have fixed | ||
| // grouping (Throughput by status, Errors by status, | ||
| // Duration ungrouped), so when the user picks a custom | ||
| // group-by fall back to the histogram, which honors it. | ||
| (traceRedMetricsSource != null && | ||
| !isCompact && | ||
| !isCustomGroupBy ? ( | ||
| // RED/Heatmap where it fits, else the histogram; see | ||
| // traceChartsSource for when each one renders. | ||
| (traceChartsSource != null && | ||
| traceHeatmapChartConfig != null ? ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Remove the check from the branch condition. This branch sits inside 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's there for the type: traceHeatmapChartConfig is a memo computed above that JSX guard, so it stays possibly undefined and the prop needs the narrowing.
alex-fedotyev marked this conversation as resolved.
Resolved
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| <Box | ||
| className={searchPageStyles.timeChartContainer} | ||
| mih="0" | ||
| h={240} | ||
| > | ||
| <TraceRedMetricsChart | ||
| mode={traceChartMode} | ||
| histogramTimeChartConfig={ | ||
| histogramTimeChartConfig | ||
| } | ||
| source={traceRedMetricsSource} | ||
| heatmapChartConfig={traceHeatmapChartConfig} | ||
| source={traceChartsSource} | ||
| isReady={isReady} | ||
| queryKeyPrefix={RED_QUERY_KEY_PREFIX} | ||
| throughputQueryKeyPrefix={QUERY_KEY_PREFIX} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,12 @@ import { Flex, SegmentedControl } from '@mantine/core'; | |
|
|
||
| import { IsolatedChartSyncProvider } from '@/chartSync'; | ||
| import { ChartCard } from '@/components/charts/ChartCard'; | ||
| import DBHeatmapChart, { | ||
| HEATMAP_DURATION_NUMBER_FORMAT, | ||
| toHeatmapQuery, | ||
| } from '@/components/DBHeatmapChart'; | ||
| import { DBTimeChart, type SeriesGroupFilter } from '@/components/DBTimeChart'; | ||
| import { getDurationMsExpression } from '@/source'; | ||
|
|
||
| import { | ||
| durationConfig, | ||
|
|
@@ -18,6 +23,11 @@ import { | |
| redBaseConfig, | ||
| } from './traceRedMetrics'; | ||
|
|
||
| // The trace results chart views, RED first as the default. The type and the | ||
| // URL parser both come from this list, so they can't drift apart. | ||
| export const TRACE_CHART_MODES = ['red', 'heatmap'] as const; | ||
| export type TraceChartMode = (typeof TRACE_CHART_MODES)[number]; | ||
|
|
||
| // Each RED tile is a ChartCard flex child that fills its column; ChartCard | ||
| // supplies the dashboard-tile chrome (border, background, full-bleed header | ||
| // divider) and the card-header context, so the three headers line up on their | ||
|
|
@@ -29,6 +39,11 @@ const RED_TILE_STYLE = { | |
| height: '100%', | ||
| } satisfies CSSProperties; | ||
|
|
||
| const HEATMAP_TILE_STYLE = { | ||
| height: '100%', | ||
| minHeight: 0, | ||
| } satisfies CSSProperties; | ||
|
|
||
| /** | ||
| * RED metrics (Throughput, Errors, Duration) for the trace search results view, | ||
| * replacing the single count histogram. The three charts render side by side as | ||
|
|
@@ -40,16 +55,22 @@ const RED_TILE_STYLE = { | |
| * selected time range. | ||
| */ | ||
| export function TraceRedMetricsChart({ | ||
| mode, | ||
| histogramTimeChartConfig, | ||
| heatmapChartConfig, | ||
| source, | ||
| isReady, | ||
| queryKeyPrefix, | ||
| throughputQueryKeyPrefix, | ||
| onTimeRangeSelect, | ||
| onFocusSeries, | ||
| }: { | ||
| /** RED vs heatmap; owned by the search stats row so the switch sits inline. */ | ||
| mode: TraceChartMode; | ||
| /** The count-histogram config; RED charts spread this and swap only select. */ | ||
| histogramTimeChartConfig: BuilderChartConfigWithDateRange; | ||
| /** Base config for the heatmap tile, mirroring the delta-mode callsite. */ | ||
| heatmapChartConfig: BuilderChartConfigWithDateRange; | ||
| source: TTraceSource; | ||
| isReady: boolean; | ||
| /** Query-key prefix for the auxiliary Errors/Duration tiles, kept separate so | ||
|
|
@@ -86,6 +107,26 @@ export function TraceRedMetricsChart({ | |
| [base, durationExpression], | ||
| ); | ||
|
|
||
| // Duration distribution over time, like the dashboard heatmap tile: the query | ||
| // the delta view's heatmap builds with its default settings, fixed here | ||
| // rather than read from that view's settings drawer. | ||
| const durationMsExpression = getDurationMsExpression(source); | ||
| const heatmapQuery = useMemo( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — Duration heatmap query is copied from DBSearchHeatmapChart and marked with an Lines 121-135 rebuild the same 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dropped the @source tag in b1a88cb. I kept the query inline: the delta view reads value, count and scale from its settings drawer and only attaches the duration format when the value is the duration expression, so a shared helper would mostly be parameters, and it would touch DBSearchHeatmapChart.tsx, which this PR doesn't change.
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| () => | ||
| toHeatmapQuery({ | ||
| ...heatmapChartConfig, | ||
| select: [ | ||
| { | ||
| valueExpression: durationMsExpression, | ||
| countExpression: 'count()', | ||
| heatmapScaleType: 'log', | ||
| }, | ||
| ], | ||
| numberFormat: HEATMAP_DURATION_NUMBER_FORMAT, | ||
| }), | ||
| [heatmapChartConfig, durationMsExpression], | ||
| ); | ||
|
|
||
| const errorsModeControl = ( | ||
| <SegmentedControl | ||
| key="errors-mode" | ||
|
|
@@ -118,6 +159,19 @@ export function TraceRedMetricsChart({ | |
| // of surfacing the raw aggregate expression as a label. | ||
| const throughputGrouped = isUsingGroupBy(histogramTimeChartConfig); | ||
|
|
||
| if (mode === 'heatmap') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — The new heatmap branch of TraceRedMetricsChart has no test Add a component test that renders 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not adding a component test here: the branch is checked on the preview (duration value, ms format, log scale), and e2e for the view, which covers it end to end, is tracked in #3176.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 minor — TraceRedMetricsChart now renders two unrelated views behind a In heatmap mode the component still computes the RED configs and receives props it doesn't use (onFocusSeries, throughputQueryKeyPrefix, histogram config). In RED mode it needs 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping one component: both views take the same search config, source and ready state, and the page picks the view in one place. A second component would carry the same props without changing behavior. |
||
| return ( | ||
| <ChartCard style={HEATMAP_TILE_STYLE}> | ||
|
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| <DBHeatmapChart | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Dragging on the heatmap does nothing, unlike the RED tiles it replaces The RED tiles get 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving this out of this PR on purpose: no heatmap in the app zooms on drag today, including the dashboard tile this one mirrors, and a drag box here raises whether its duration range should filter the results too, as it does in the delta view. I'd rather settle that as its own change.
alex-fedotyev marked this conversation as resolved.
Resolved
|
||
| title="Duration" | ||
| query={heatmapQuery} | ||
| enabled={isReady} | ||
| showLegend | ||
| /> | ||
| </ChartCard> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <IsolatedChartSyncProvider> | ||
| <Flex direction="row" h="100%" gap="sm" mih="0" miw="0"> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.