Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changeset/heatmap-series-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperdx/app': minor
'@hyperdx/common-utils': minor
'@hyperdx/api': patch
---

feat: Add a series mode to builder heatmaps
2 changes: 1 addition & 1 deletion packages/api/src/mcp/tools/dashboards/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ const mcpHeatmapSelectItemSchema = z.object({
});

// Heatmap tiles are builder-only and currently restricted to Trace sources
// (see HEATMAP_ALLOWED_SOURCE_KINDS in `packages/common-utils/src/guards.ts`).
// (see HEATMAP_DISTRIBUTION_SOURCE_KINDS in `packages/common-utils/src/guards.ts`).
// The save path runs `getHeatmapTilesWithIncompatibleSources` after schema
// validation to enforce that, mirroring the REST handler.
const mcpHeatmapTileSchema = mcpTileLayoutSchema.extend({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isBuilderSavedChartConfig } from '@hyperdx/common-utils/dist/guards';
import {
DisplayType,
MetricsDataType,
OnboardingTaskId,
SourceKind,
Expand Down Expand Up @@ -2879,6 +2880,39 @@ describe('External API v2 Dashboards - new format', () => {
);
});

it('skips series-mode heatmap tiles on GET', async () => {
// Series-mode heatmaps have no external representation yet; emitting
// them as distribution tiles would corrupt them on GET -> PUT.
const dashboard = await createTestDashboard({
tiles: [
{
id: new ObjectId().toString(),
x: 0,
y: 0,
w: 6,
h: 3,
config: {
name: 'Series heatmap',
displayType: DisplayType.Heatmap,
source: traceSource._id.toString(),
select: [
{ aggFn: 'count', aggCondition: '', valueExpression: '' },
],
groupBy: 'ServiceName',
where: '',
heatmap: { mode: 'series' },
},
},
],
});

const response = await authRequest(
'get',
`${BASE_URL}/${dashboard._id}`,
).expect(200);
expect(response.body.data.tiles).toEqual([]);
});

it('round-trips a heatmap tile with only required fields', async () => {
// Covers the minimal payload path: countExpression, heatmapScaleType,
// where, whereLanguage, and numberFormat are all omitted on the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ export const EVALUATION_INERT_CONFIG_KEYS: ReadonlySet<string> = new Set([
'fitYAxisToData',
'onClick',
'alternateRowBackground',
// Heatmap tiles carry no alerts; alert display types ignore it.
'heatmap',
// Client-side null-bucket rendering; the alert task ignores it.
'fillNulls',
// Evaluation-relevant only with a groupBy, which (on variants whose shape
Expand Down
17 changes: 16 additions & 1 deletion packages/api/src/routers/external-api/v2/utils/dashboards.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getHeatmapMode } from '@hyperdx/common-utils/dist/core/heatmap';
import {
displayTypeSupportsBuilderAlerts,
displayTypeSupportsRawSqlAlerts,
Expand Down Expand Up @@ -538,6 +539,20 @@ function convertTileToExternalChart(
return undefined;
}

// Series-mode heatmaps have no external schema yet. Emitting them as
// distribution tiles would corrupt them on a GET -> PUT round-trip.
if (
Comment thread
pulpdrew marked this conversation as resolved.
Resolved

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.

🟠 major — External API/MCP GET now drops series-mode heatmap tiles, so a GET → PUT round-trip deletes them

PUT replaces the tile list, and its TileInput doc in v2/dashboards.ts says only tiles whose id matches an existing tile are kept. So any client that reads a dashboard and writes it back silently deletes every series heatmap a user built in the UI. On update, merge back the existing tiles that GET skipped (series heatmaps, and PromQL by the same reasoning), or reject the PUT. The comment saying this avoids corruption is misleading, because the tile ends up deleted instead.

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

isBuilderSavedChartConfig(tile.config) &&
tile.config.displayType === DisplayType.Heatmap &&
getHeatmapMode(tile.config) === 'series'
) {
logger.warn(
{ dashboardId, tileId: tile.id },
'Skipping series-mode heatmap tile in external API response (not yet supported)',
);
return undefined;
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
}

// Returned in case of a failure converting the saved chart config
const defaultTileConfig: ExternalDashboardTileConfig =
isRawSqlSavedChartConfig(tile.config)
Expand Down Expand Up @@ -1051,7 +1066,7 @@ function getMissingSources(
/**
* Returns source IDs referenced by heatmap tiles that exist but are not
* compatible with heatmap rendering. The heatmap UI gates the source picker
* via the same `HEATMAP_ALLOWED_SOURCE_KINDS` set used here (see
* via the same `HEATMAP_DISTRIBUTION_SOURCE_KINDS` set used here (see
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
* `packages/common-utils/src/guards.ts` and `ChartEditorControls.tsx`), so
* UI and API gates move together.
*/
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/DBDashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,17 @@ function HeatmapTile({
enabled?: boolean;
}) {
const heatmapQuery = toHeatmapQuery(queriedConfig);
const { mode } = heatmapQuery;

const [clickPos, setClickPos] = useState<{ x: number; y: number } | null>(
null,
);
const containerRef = useRef<HTMLDivElement>(null);

const eventDeltasUrl = useMemo(() => {
if (!source) return null;
// Search page event deltas only supports trace sources and distribution mode
if (!source || !isTraceSource(source) || mode !== 'distribution')
return null;
const url = buildEventsSearchUrl({
source,
config: queriedConfig,
Expand All @@ -265,7 +268,7 @@ function HeatmapTile({
if (!url) return null;
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}mode=delta`;
}, [source, queriedConfig, dateRange]);
}, [source, mode, queriedConfig, dateRange]);

const handleClick = useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
Expand Down
10 changes: 8 additions & 2 deletions packages/app/src/components/ChartDisplaySettingsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {
ChartConfigWithDateRange,
DisplayType,
HeatmapMode,
MAX_LEGEND_TEMPLATE_LENGTH,
NumberFormat,
} from '@hyperdx/common-utils/dist/types';
Expand Down Expand Up @@ -63,7 +64,7 @@ export type ChartConfigDisplaySettings = Pick<
// PromQL-only: Handlebars template over each series' Prometheus label set
// that renders the legend/tooltip name.
legendTemplate?: string;
// Heatmaps only; stored on the heatmap's select[0].
// Distribution heatmaps only; stored on the heatmap's select[0].
heatmapScaleType?: HeatmapScaleType;
};

Expand All @@ -86,6 +87,8 @@ interface ChartDisplaySettingsDrawerProps {
configType?: 'sql' | 'builder' | 'promql';
/** Whether a PromQL tile's queried expression runs over a range. */
promqlUsesRange?: boolean;
/** A builder heatmap's mode; only distribution heatmaps have a numeric y axis to scale. */
heatmapMode?: HeatmapMode;
previousDateRange?: [Date, Date];
onChange: (settings: ChartConfigDisplaySettings, isDirty: boolean) => void;
onClose: () => void;
Expand Down Expand Up @@ -127,6 +130,7 @@ export default function ChartDisplaySettingsDrawer({
displayType,
configType,
promqlUsesRange = false,
heatmapMode,
defaultNumberFormat,
onChange,
onClose,
Expand Down Expand Up @@ -248,7 +252,9 @@ export default function ChartDisplaySettingsDrawer({
? 'Available on PromQL range queries.'
: 'Available on query-builder number tiles.';

const showHeatmapScale = displayType === DisplayType.Heatmap;
// Log scale only means something on a numeric (distribution mode) y axis
const showHeatmapScale =
displayType === DisplayType.Heatmap && heatmapMode === 'distribution';

return (
<Drawer
Expand Down
Loading
Loading