Skip to content

Commit 022e85c

Browse files
Merge branch 'main' into dependabot/npm_and_yarn/ip-address-10.7.1
2 parents be64528 + 4570d5e commit 022e85c

46 files changed

Lines changed: 1818 additions & 281 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/promql-macros.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@hyperdx/common-utils': minor
3+
'@hyperdx/app': minor
4+
---
5+
6+
feat: Support macros in PromQL charts

‎.changeset/promql-pie-bar-tiles.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@hyperdx/common-utils': patch
3+
'@hyperdx/app': patch
4+
---
5+
6+
feat: Support pie and bar tiles on PromQL sources
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@hyperdx/app': patch
3+
---
4+
5+
feat: add an option to show MATERIALIZED and ALIAS columns in the row details panel
6+
7+
ClickHouse leaves MATERIALIZED and ALIAS columns out of `SELECT *`, so the row
8+
details panel never showed them. A new "Show materialized and alias columns"
9+
item in the properties view options menu, off by default, adds
10+
`asterisk_include_materialized_columns` and `asterisk_include_alias_columns` to
11+
the row query. It has no effect on a source with a Known Columns List, and a
12+
value that the source's query settings give for either setting wins. If the row
13+
fails to load while the option is on (for example, because the connection's user
14+
is `readonly = 1`, or an ALIAS column cannot be evaluated), the error state
15+
offers to turn the option off.

‎packages/app/src/ChartUtils.tsx‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,39 @@ function getAlignedRangeAndGranularity(
147147
}
148148

149149
/**
150-
* A PromQL number tile's queried config, shared by the value and the sparkline
151-
* drawn behind it.
150+
* Converts the given config into one that is suitable for a tile that shows
151+
* 1 value per series (number, pie, and bar tiles). The reducer defaults to
152+
* the last value.
152153
*/
153-
export function convertToPromqlNumberChartConfig(
154+
export function convertToReducedPromqlChartConfig(
154155
config: PromqlChartConfig & DateRange,
155-
{ withReducer }: { withReducer: boolean },
156156
): PromqlChartConfig & DateRange {
157157
return {
158158
...config,
159159
...getAlignedRangeAndGranularity(config),
160160
promqlExpression: getQueriedPromqlSeries(config).map(series => ({
161161
...series,
162-
reducer: withReducer
163-
? (series.reducer ?? DEFAULT_PROMQL_REDUCER)
164-
: undefined,
162+
reducer: series.reducer ?? DEFAULT_PROMQL_REDUCER,
163+
})),
164+
};
165+
}
166+
167+
/**
168+
* The config for the sparkline behind a PromQL number tile: the tile's query
169+
* with no reducer, so the buckets are plotted rather than collapsed.
170+
*
171+
* Intentionally matches convertToReducedPromqlChartConfig except for the reducer,
172+
* so that react-query keys remain consistent between the reduced and sparkline versions.
173+
*/
174+
export function convertToPromqlSparklineChartConfig(
175+
config: PromqlChartConfig & DateRange,
176+
): PromqlChartConfig & DateRange {
177+
const reduced = convertToReducedPromqlChartConfig(config);
178+
return {
179+
...reduced,
180+
promqlExpression: getQueriedPromqlSeries(reduced).map(series => ({
181+
...series,
182+
reducer: undefined,
165183
})),
166184
};
167185
}

‎packages/app/src/__tests__/ChartUtils.test.ts‎

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {
1010
import {
1111
ChartKeyJoiner,
1212
convertToNumberChartConfig,
13-
convertToPromqlNumberChartConfig,
13+
convertToPromqlSparklineChartConfig,
1414
convertToPromqlTableChartConfig,
15+
convertToReducedPromqlChartConfig,
1516
convertToTableChartConfig,
1617
convertToTimeChartConfig,
1718
findNearestSeriesKey,
@@ -1318,7 +1319,7 @@ describe('ChartUtils', () => {
13181319
});
13191320
});
13201321

1321-
describe('convertToPromqlNumberChartConfig', () => {
1322+
describe('convertToReducedPromqlChartConfig and convertToPromqlSparklineChartConfig', () => {
13221323
const promqlConfig = {
13231324
configType: 'promql' as const,
13241325
displayType: DisplayType.Number,
@@ -1337,9 +1338,7 @@ describe('ChartUtils', () => {
13371338
// unresolved step puts the samples between the buckets the sparkline plots
13381339
// on -- which the empty-bucket filler then fills with zeros.
13391340
it('aligns the date range and resolves the granularity', () => {
1340-
const result = convertToPromqlNumberChartConfig(promqlConfig, {
1341-
withReducer: true,
1342-
});
1341+
const result = convertToReducedPromqlChartConfig(promqlConfig);
13431342

13441343
expect(result.dateRange).toEqual([
13451344
new Date('2025-11-26T00:00:00Z'),
@@ -1349,17 +1348,14 @@ describe('ChartUtils', () => {
13491348
});
13501349

13511350
it('leaves the date range unaligned for an instant query', () => {
1352-
const result = convertToPromqlNumberChartConfig(
1353-
{
1354-
...promqlConfig,
1355-
promqlExpression: [{ expression: 'up', queryType: 'instant' }],
1356-
dateRange: [
1357-
new Date('2025-11-26T00:00:14.076Z'),
1358-
new Date('2025-11-27T00:00:14.076Z'),
1359-
],
1360-
},
1361-
{ withReducer: true },
1362-
);
1351+
const result = convertToReducedPromqlChartConfig({
1352+
...promqlConfig,
1353+
promqlExpression: [{ expression: 'up', queryType: 'instant' }],
1354+
dateRange: [
1355+
new Date('2025-11-26T00:00:14.076Z'),
1356+
new Date('2025-11-27T00:00:14.076Z'),
1357+
],
1358+
});
13631359

13641360
expect(result.dateRange).toEqual([
13651361
new Date('2025-11-26T00:00:14.076Z'),
@@ -1369,9 +1365,7 @@ describe('ChartUtils', () => {
13691365
});
13701366

13711367
it('names the reducer, defaulting it, and queries one expression', () => {
1372-
const result = convertToPromqlNumberChartConfig(promqlConfig, {
1373-
withReducer: true,
1374-
});
1368+
const result = convertToReducedPromqlChartConfig(promqlConfig);
13751369

13761370
expect(result).toEqual(
13771371
expect.objectContaining({
@@ -1387,19 +1381,16 @@ describe('ChartUtils', () => {
13871381
});
13881382

13891383
it('keeps a chosen reducer', () => {
1390-
const result = convertToPromqlNumberChartConfig(
1391-
{
1392-
...promqlConfig,
1393-
promqlExpression: [
1394-
{
1395-
expression: 'up',
1396-
queryType: 'range' as const,
1397-
reducer: PromqlReducer.Max,
1398-
},
1399-
],
1400-
},
1401-
{ withReducer: true },
1402-
);
1384+
const result = convertToReducedPromqlChartConfig({
1385+
...promqlConfig,
1386+
promqlExpression: [
1387+
{
1388+
expression: 'up',
1389+
queryType: 'range' as const,
1390+
reducer: PromqlReducer.Max,
1391+
},
1392+
],
1393+
});
14031394

14041395
expect(result).toEqual(
14051396
expect.objectContaining({
@@ -1417,12 +1408,8 @@ describe('ChartUtils', () => {
14171408
// Without a reducer named, the hook leaves the buckets alone -- which is
14181409
// how the sparkline reads the same response as the value.
14191410
it('names no reducer for the sparkline, otherwise matching the value', () => {
1420-
const value = convertToPromqlNumberChartConfig(promqlConfig, {
1421-
withReducer: true,
1422-
});
1423-
const sparkline = convertToPromqlNumberChartConfig(promqlConfig, {
1424-
withReducer: false,
1425-
});
1411+
const value = convertToReducedPromqlChartConfig(promqlConfig);
1412+
const sparkline = convertToPromqlSparklineChartConfig(promqlConfig);
14261413

14271414
expect(sparkline).toEqual({
14281415
...value,

‎packages/app/src/components/ChartEditor/PromqlExpressionEditor.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default function PromqlExpressionEditor({
6464
onSubmit={() => onSubmit()}
6565
placeholder="rate(http_requests_total{service='api'}[5m])"
6666
metricNames={metricNames}
67+
enableMacros
6768
/>
6869
</Box>
6970
{isIgnored ? (

‎packages/app/src/components/ChartEditor/PromqlQueryTypeControls.tsx‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,12 @@ export default function PromqlQueryTypeControls({
4848
name: `promqlExpressions.${index}.reducer`,
4949
});
5050
const queryTypeValue = queryType.value ?? DEFAULT_PROMQL_QUERY_TYPE;
51-
const isRange = queryTypeValue === 'range';
52-
const showReducer = isRange && isReducerSupported;
5351
const reducerValue = reducer.value ?? DEFAULT_PROMQL_REDUCER;
5452
const reducerLabel = REDUCER_OPTIONS.find(
5553
o => o.value === reducerValue,
5654
)?.label;
57-
const summary = isRange
58-
? `Settings: Range${showReducer ? ` / ${reducerLabel}` : ''}`
59-
: 'Settings: Instant';
55+
const queryTypeLabel = queryTypeValue === 'range' ? 'Range' : 'Instant';
56+
const summary = `Settings: ${queryTypeLabel}${isReducerSupported ? ` / ${reducerLabel}` : ''}`;
6057

6158
return (
6259
<>
@@ -75,7 +72,7 @@ export default function PromqlQueryTypeControls({
7572
}}
7673
data-testid={`promql-query-type-input-${index}`}
7774
/>
78-
{showReducer && (
75+
{isReducerSupported && (
7976
<>
8077
<Text size="xxs" c="dimmed">
8178
Reduced to
@@ -87,7 +84,7 @@ export default function PromqlQueryTypeControls({
8784
value={reducerValue}
8885
allowDeselect={false}
8986
comboboxProps={{ withinPortal: false }}
90-
aria-label="PromQL range reducer"
87+
aria-label="PromQL reducer"
9188
onChange={next => {
9289
if (next == null) return;
9390
reducer.onChange(next);

‎packages/app/src/components/DBEditTimeChartForm/__tests__/ChartPreviewPanel.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ describe('ChartPreviewPanel', () => {
415415
await userEvent.hover(wrapper!);
416416

417417
expect(
418-
await screen.findByText(/Variables could not be expanded/),
418+
await screen.findByText(/Expression could not be expanded/),
419419
).toBeInTheDocument();
420420
expect(
421421
screen.queryByTestId('chart-promql-preview'),

‎packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts‎

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ describe('buildRenderedPromqlExpression', () => {
222222
promqlExpression?: PromqlExpressionList;
223223
displayType?: DisplayType;
224224
variables?: ChartVariable[];
225+
granularity?: string;
225226
} = {},
226227
): ChartConfigWithDateRange => ({
227228
configType: 'promql',
@@ -302,6 +303,67 @@ describe('buildRenderedPromqlExpression', () => {
302303
).toEqual(['up{service=~"api"}', 'errors{service=~"api"}']);
303304
});
304305

306+
it('expands macros with the granularity the chart queries with', () => {
307+
const expression = 'rate(up[$__rate_interval]) / $__interval / $__range';
308+
const render = (displayType: DisplayType, granularity?: string) =>
309+
buildRenderedPromqlExpression(
310+
promqlConfig({
311+
displayType,
312+
granularity,
313+
promqlExpression: [{ expression }],
314+
}),
315+
)?.expressions?.[0].expression;
316+
317+
expect(render(DisplayType.Line, '5 minute')).toBe(
318+
'rate(up[315s]) / 300s / 86400s',
319+
);
320+
// `auto` resolves to the chart's 80-bucket granularity (30 minutes for a
321+
// day), not promqlStep's own fallback.
322+
expect(render(DisplayType.Line, 'auto')).toBe(
323+
'rate(up[1815s]) / 1800s / 86400s',
324+
);
325+
expect(render(DisplayType.Number, 'auto')).toBe(
326+
'rate(up[1815s]) / 1800s / 86400s',
327+
);
328+
});
329+
330+
it('expands macros with the granularity a table queries with', () => {
331+
const seventyMinutes: [Date, Date] = [
332+
new Date('2024-01-01T00:00:00Z'),
333+
new Date('2024-01-01T01:10:00Z'),
334+
];
335+
expect(
336+
buildRenderedPromqlExpression({
337+
...promqlConfig({
338+
displayType: DisplayType.Table,
339+
granularity: 'auto',
340+
promqlExpression: [{ expression: 'rate(up[$__interval])' }],
341+
}),
342+
dateRange: seventyMinutes,
343+
})?.expressions?.[0].expression,
344+
).toBe('rate(up[60s])');
345+
});
346+
347+
it.each([DisplayType.Pie, DisplayType.Bar])(
348+
'expands macros with the aligned range a %s tile queries with',
349+
displayType => {
350+
const unaligned: [Date, Date] = [
351+
new Date('2024-01-01T00:00:14Z'),
352+
new Date('2024-01-01T01:10:14Z'),
353+
];
354+
expect(
355+
buildRenderedPromqlExpression({
356+
...promqlConfig({
357+
displayType,
358+
granularity: 'auto',
359+
promqlExpression: [{ expression: 'up[$__interval] / $__range' }],
360+
}),
361+
dateRange: unaligned,
362+
})?.expressions?.[0].expression,
363+
).toBe('up[60s] / 4260s');
364+
},
365+
);
366+
305367
it('reports a substitution failure instead of an expression', () => {
306368
const result = buildRenderedPromqlExpression(
307369
promqlConfig({
@@ -310,7 +372,7 @@ describe('buildRenderedPromqlExpression', () => {
310372
}),
311373
);
312374
expect(result?.expressions).toBeUndefined();
313-
expect(result?.error).toMatch(/Variables could not be expanded/);
375+
expect(result?.error).toMatch(/Expression could not be expanded/);
314376
});
315377
});
316378

0 commit comments

Comments
 (0)