Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/trace-search-duration-heatmap.md
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.
112 changes: 98 additions & 14 deletions packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
Group,
Modal,
Paper,
SegmentedControl,
Select,
Stack,
Text,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Comment thread
alex-fedotyev marked this conversation as resolved.
Resolved
parseAsStringEnum([...TRACE_CHART_MODES]).withDefault('red'),
);

// URL-only, not saved with the search: null uses the source default.
const [groupByParam, setGroupByParam] = useQueryState(
'groupBy',
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand All @@ -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', '');
Expand Down Expand Up @@ -1582,6 +1607,8 @@ function DBSearchPageContent() {
searchedSource?.id,
rawSearchedConfig.source,
setSearchedConfig,
armTraceChartModeReset,
disarmTraceChartModeReset,
]);

const retainCompatibleFiltersAndGroupBy = useStableCallback(
Expand Down Expand Up @@ -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(

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.

🔵 minor — traceHeatmapChartConfig duplicates the delta heatmap's inline config

The delta-mode DBSearchHeatmapChart (DBSearchPage.tsx:2908-2912) builds the same {...chartConfig, dateRange: searchedTimeRange, with: aliasWith} object inline on every render. Pass the memoized traceHeatmapChartConfig there too (renamed to something like heatmapBaseChartConfig) so the base config has one source of truth.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment thread
alex-fedotyev marked this conversation as resolved.
Resolved
Comment thread
alex-fedotyev marked this conversation as resolved.
Resolved
() =>
chartConfig == null
? undefined
: ({
...chartConfig,
Comment thread
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}
Expand Down Expand Up @@ -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={
Expand Down Expand Up @@ -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 =>

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.

🔵 minor — Switch options are hand-written rather than derived from TRACE_CHART_MODES, and the ?? 'red' fallback never runs

TRACE_CHART_MODES says the view switch reads from it, but the data array lists 'red'/'heatmap' as literals. A new mode added to the list would parse from the URL but never appear in the switch. SegmentedControl only emits values from data, so the find(...) ?? 'red' fallback is dead code. Fix: build data from TRACE_CHART_MODES with a Record<TraceChartMode, string> label map, and narrow v with that list.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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(
Comment thread
alex-fedotyev marked this conversation as resolved.
Resolved
TRACE_CHART_MODES.find(
mode => mode === v && mode !== 'red',
) ?? null,
)
}
data={[
Comment thread
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}
/>
Expand All @@ -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 ? (

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.

🔵 minor — traceHeatmapChartConfig != null check can never be false here

Remove the check from the branch condition. This branch sits inside chartConfig && histogramTimeChartConfig && totalCountConfig && (line 2922). traceHeatmapChartConfig is only undefined when chartConfig == null, so the RED/Heatmap branch never falls back to the histogram because of it. Building the config inline, or typing the memo as non-null under that guard, would make that clear.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment thread
alex-fedotyev marked this conversation as resolved.
Resolved
Comment thread
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}
Expand Down
54 changes: 54 additions & 0 deletions packages/app/src/components/Search/TraceRedMetricsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(

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.

🔵 minor — Duration heatmap query is copied from DBSearchHeatmapChart and marked with an @source tag instead of shared

Lines 121-135 rebuild the same toHeatmapQuery({...config, select:[{valueExpression: getDurationMsExpression(source), countExpression:'count()', heatmapScaleType:'log'}], numberFormat: HEATMAP_DURATION_NUMBER_FORMAT}) that components/Search/DBSearchHeatmapChart.tsx:142-155 builds. The conventions reserve @source for whole-file ports across packages. Fix: extract a toDurationHeatmapQuery(config, source, {value, count, scaleType}) helper next to toHeatmapQuery and call it from both places.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment thread
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"
Expand Down Expand Up @@ -118,6 +159,19 @@ export function TraceRedMetricsChart({
// of surfacing the raw aggregate expression as a label.
const throughputGrouped = isUsingGroupBy(histogramTimeChartConfig);

if (mode === 'heatmap') {

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.

🔵 minor — The new heatmap branch of TraceRedMetricsChart has no test

Add a component test that renders mode="heatmap" and checks that DBHeatmapChart gets a distribution query whose value is getDurationMsExpression(source), uses HEATMAP_DURATION_NUMBER_FORMAT and log scale, and receives queryKeyPrefix. Today only the guard hook and useHeatmapData keys are tested, so a wrong expression or format here would still pass (there is no TraceRedMetricsChart test under components/Search/__tests__/).

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

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.

🔵 minor — TraceRedMetricsChart now renders two unrelated views behind a mode early return

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 heatmapChartConfig, and DBSearchPage now gates the RED tiles on traceHeatmapChartConfig != null. This breaks the Single Responsibility convention. Fix: add a separate small TraceDurationHeatmapChart and pick between the two in DBSearchPage on traceChartMode. TraceRedMetricsChart then stays RED-only.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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}>
Comment thread
alex-fedotyev marked this conversation as resolved.
Resolved
<DBHeatmapChart

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 — Dragging on the heatmap does nothing, unlike the RED tiles it replaces

The RED tiles get onTimeRangeSelect, so dragging across one zooms the search to that time range. The heatmap gets neither onFilter nor a time handler, and HeatmapChartView/DistributionHeatmapChart (packages/app/src/components/DBHeatmapChart/DBHeatmapChart.tsx) have no other drag path, so the same drag in Heatmap mode does nothing. Pass onFilter={(xMin, xMax) => onTimeRangeSelect?.(new Date(xMin), new Date(xMax))}, or also add a duration filter from yMin/yMax. Check what units xMin/xMax use in selection.ts first.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment thread
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">
Expand Down
Loading
Loading