Skip to content
Closed
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/nice-cows-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@hyperdx/common-utils": patch
"@hyperdx/api": patch
"@hyperdx/app": patch
---

feat: Support distribution heatmaps calculated from promql data
6 changes: 6 additions & 0 deletions .changeset/promql-histogram-heatmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@hyperdx/common-utils": patch
"@hyperdx/app": patch
---

feat: Support histogram heatmaps from PromQL bucket metrics
44 changes: 30 additions & 14 deletions packages/app/src/components/ChartDisplaySettingsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { isTimeSeriesDisplayType } from '@hyperdx/common-utils/dist/core/utils';
import {
ChartConfigWithDateRange,
DisplayType,
HeatmapMode,
MAX_LEGEND_TEMPLATE_LENGTH,
NumberFormat,
PromqlHeatmapMode,
} from '@hyperdx/common-utils/dist/types';
import {
Alert,
Expand Down Expand Up @@ -65,7 +65,8 @@ export type ChartConfigDisplaySettings = Pick<
// PromQL-only: Handlebars template over each series' Prometheus label set
// that renders the legend/tooltip name.
legendTemplate?: string;
// Distribution heatmaps only; stored on the heatmap's select[0].
// Distribution heatmaps only; stored on a builder heatmap's select[0] and
// on a PromQL heatmap's `heatmap.scaleType`.
heatmapScaleType?: HeatmapScaleType;
};

Expand All @@ -88,8 +89,10 @@ 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;
/** A heatmap's mode; only distribution heatmaps have a numeric y axis to scale. */
heatmapMode?: PromqlHeatmapMode;
/** The heatmap scale used when the tile has none set. */
defaultHeatmapScaleType?: HeatmapScaleType;
previousDateRange?: [Date, Date];
onChange: (settings: ChartConfigDisplaySettings, isDirty: boolean) => void;
onClose: () => void;
Expand All @@ -98,7 +101,8 @@ interface ChartDisplaySettingsDrawerProps {

function applyDefaultSettings(
settings: ChartConfigDisplaySettings,
fallbackNumberFormat?: NumberFormat,
fallbackNumberFormat: NumberFormat | undefined,
defaultHeatmapScaleType: HeatmapScaleType,
): DrawerFormValues {
return {
numberFormat:
Expand All @@ -121,7 +125,7 @@ function applyDefaultSettings(
? attachLocalIds(settings.colorRules)
: undefined,
backgroundChart: settings.backgroundChart,
heatmapScaleType: settings.heatmapScaleType ?? 'log',
heatmapScaleType: settings.heatmapScaleType ?? defaultHeatmapScaleType,
};
}

Expand All @@ -132,15 +136,21 @@ export default function ChartDisplaySettingsDrawer({
configType,
promqlUsesRange = false,
heatmapMode,
defaultHeatmapScaleType = 'log',
defaultNumberFormat,
onChange,
onClose,
previousDateRange,
isPerSeriesNumberFormatAllowed = false,
}: ChartDisplaySettingsDrawerProps) {
const appliedDefaults = useMemo(
() => applyDefaultSettings(settings, defaultNumberFormat),
[settings, defaultNumberFormat],
() =>
applyDefaultSettings(
settings,
defaultNumberFormat,
defaultHeatmapScaleType,
),
[settings, defaultNumberFormat, defaultHeatmapScaleType],
);

const {
Expand Down Expand Up @@ -197,9 +207,10 @@ export default function ChartDisplaySettingsDrawer({
applyDefaultSettings(
{} as ChartConfigDisplaySettings,
defaultNumberFormat,
defaultHeatmapScaleType,
),
);
}, [reset, defaultNumberFormat]);
}, [reset, defaultNumberFormat, defaultHeatmapScaleType]);

const isTimeChart = isTimeSeriesDisplayType(displayType);

Expand All @@ -212,12 +223,18 @@ export default function ChartDisplaySettingsDrawer({
const isClientSideSeriesLimit =
showSeriesLimit && (configType === 'sql' || configType === 'promql');

const isDistributionHeatmap =
displayType === DisplayType.Heatmap && heatmapMode === 'distribution';

// Every PromQL display that surfaces a series name. A number tile shows one
// value and a table gives each label its own column, so neither has a legend.
// value, a table gives each label its own column, a distribution heatmap
// merges every series into one, and a histogram heatmap labels rows by
// bucket, so none has a legend.
const showLegendTemplate =
configType === 'promql' &&
displayType !== DisplayType.Number &&
displayType !== DisplayType.Table;
displayType !== DisplayType.Table &&
!(displayType === DisplayType.Heatmap && heatmapMode !== 'series');

// On pie/bar builder charts, seriesLimit becomes a plain SQL LIMIT on the
// number of slices/bars; on PromQL it trims the reduced series client-side
Expand Down Expand Up @@ -254,8 +271,7 @@ export default function ChartDisplaySettingsDrawer({
: 'Available on query-builder number tiles.';

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

return (
<Drawer
Expand Down Expand Up @@ -343,7 +359,7 @@ export default function ChartDisplaySettingsDrawer({
name="heatmapScaleType"
render={({ field: { onChange, value } }) => (
<HeatmapScaleControl
value={value ?? 'log'}
value={value ?? defaultHeatmapScaleType}
onChange={onChange}
/>
)}
Expand Down
20 changes: 19 additions & 1 deletion packages/app/src/components/ChartEditor/PromqlChartEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,39 @@ import {
} from '@hyperdx/common-utils/dist/core/promql';
import { isTimeSeriesDisplayType } from '@hyperdx/common-utils/dist/core/utils';
import {
DisplayType,
MAX_PROMQL_EXPRESSIONS,
PromqlHeatmapMode,
SourceKind,
} from '@hyperdx/common-utils/dist/types';
import { Button, Divider, Flex, Group, Text } from '@mantine/core';
import { Box, Button, Divider, Flex, Group, Text } from '@mantine/core';
import { IconCirclePlus } from '@tabler/icons-react';

import { HeatmapModeControl } from '@/components/DBEditTimeChartForm/HeatmapModeControl';
import { SourceSelectControlled } from '@/components/SourceSelect';
import { usePromqlMetricNames } from '@/hooks/usePromqlMetadata';
import { useSource } from '@/source';

import PromqlExpressionEditor from './PromqlExpressionEditor';
import { ChartEditorFormState } from './types';
import { promqlExpressionPlaceholder } from './utils';

export default function PromqlChartEditor({
control,
getValues,
allowedSourceKinds,
onSubmit,
onOpenDisplaySettings,
heatmapMode,
onHeatmapModeChange,
}: {
control: Control<ChartEditorFormState>;
getValues: UseFormGetValues<ChartEditorFormState>;
allowedSourceKinds: SourceKind[];
onSubmit: (suppressErrorNotification?: boolean) => void;
onOpenDisplaySettings: () => void;
heatmapMode: PromqlHeatmapMode;
onHeatmapModeChange: (mode: PromqlHeatmapMode) => void;
}) {
const {
fields: expressions,
Expand Down Expand Up @@ -106,13 +114,23 @@ export default function PromqlChartEditor({
allowedSourceKinds={allowedSourceKinds}
/>
</Group>
{displayType === DisplayType.Heatmap && (
<Box mt="md">
<HeatmapModeControl
mode={heatmapMode}
onModeChange={onHeatmapModeChange}
allowHistogram
/>
</Box>
)}
{expressions.map((field, index) => (
<PromqlExpressionEditor
key={field.id}
control={control}
index={index}
length={expressions.length}
metricNames={metricNames}
placeholder={promqlExpressionPlaceholder(displayType, heatmapMode)}
isIgnored={!displayTypeSupportsMultiExpression && index > 0}
isInstantQuerySupported={displayTypeSupportsInstantQuery({
displayType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function PromqlExpressionEditor({
index,
length,
metricNames,
placeholder,
isIgnored,
isInstantQuerySupported,
isReducerSupported,
Expand All @@ -26,6 +27,7 @@ export default function PromqlExpressionEditor({
index: number;
length: number;
metricNames: string[] | undefined;
placeholder: string;
/** Whether the display type leaves this expression unqueried. */
isIgnored: boolean;
/** Whether the display type lets this expression choose between instant and range queries. */
Expand Down Expand Up @@ -62,7 +64,7 @@ export default function PromqlExpressionEditor({
value={expressionField.value ?? ''}
onChange={expressionField.onChange}
onSubmit={() => onSubmit()}
placeholder="rate(http_requests_total{service='api'}[5m])"
placeholder={placeholder}
metricNames={metricNames}
enableMacros
/>
Expand Down
Loading
Loading