Skip to content

Commit fbdfc73

Browse files
authored
Merge branch 'main' into promql-query-attribution
2 parents d323769 + 46ff1fc commit fbdfc73

3 files changed

Lines changed: 165 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@hyperdx/app': patch
3+
---
4+
5+
feat: let users permanently dismiss the metric drill-down warning
6+
7+
Drilling down from a metric chart whose source has no correlated log source
8+
shows a warning. Clicking its close button now hides the warning for good in
9+
that browser, and repeated clicks no longer stack copies of it.

‎packages/app/src/ChartUtils.tsx‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,23 @@ export function tryExpandConfigVariables<
12571257
}
12581258
}
12591259

1260+
const NO_LOG_SOURCE_WARNING_DISMISSED_KEY =
1261+
'drilldown-metric-correlated-log-warning';
1262+
1263+
// Called while rendering (chart tooltips), so it must not throw when storage is
1264+
// blocked (sandboxed iframe, disabled cookies) or missing (SSR).
1265+
function isNoLogSourceWarningDismissed(): boolean {
1266+
if (typeof window === 'undefined') return false;
1267+
try {
1268+
return (
1269+
window.localStorage.getItem(NO_LOG_SOURCE_WARNING_DISMISSED_KEY) ===
1270+
'true'
1271+
);
1272+
} catch {
1273+
return false;
1274+
}
1275+
}
1276+
12601277
/**
12611278
* Build search URL for viewing events based on group-by values
12621279
* Used by both chart clicks and table row clicks
@@ -1292,9 +1309,21 @@ export function buildEventsSearchUrl({
12921309
? source.logSourceId
12931310
: undefined;
12941311
if (logSourceId == null) {
1312+
if (isNoLogSourceWarningDismissed()) return null;
12951313
notifications.show({
12961314
color: 'yellow',
1297-
message: 'No log source is associated with the selected metric source.',
1315+
message:
1316+
'Drill-down is unavailable for metric sources that lack correlated log sources',
1317+
id: 'no-log-source-associated',
1318+
closeButtonProps: {
1319+
onClick: () => {
1320+
try {
1321+
localStorage.setItem(NO_LOG_SOURCE_WARNING_DISMISSED_KEY, 'true');
1322+
} catch {
1323+
// don't do anything
1324+
}
1325+
},
1326+
},
12981327
});
12991328
return null;
13001329
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import {
2+
BuilderChartConfigWithDateRange,
3+
DisplayType,
4+
SourceKind,
5+
TMetricSource,
6+
} from '@hyperdx/common-utils/dist/types';
7+
import { notifications } from '@mantine/notifications';
8+
import { act, screen, within } from '@testing-library/react';
9+
import userEvent from '@testing-library/user-event';
10+
11+
import { buildEventsSearchUrl } from '@/ChartUtils';
12+
13+
const DISMISSED_KEY = 'drilldown-metric-correlated-log-warning';
14+
const TOAST_ID = 'no-log-source-associated';
15+
16+
const dateRange: [Date, Date] = [
17+
new Date('2026-01-01T00:00:00.000Z'),
18+
new Date('2026-01-01T01:00:00.000Z'),
19+
];
20+
21+
const metricSource = {
22+
id: 'metrics',
23+
name: 'Metrics',
24+
kind: SourceKind.Metric,
25+
connection: 'clickhouse',
26+
from: { databaseName: 'default', tableName: '' },
27+
timestampValueExpression: 'TimeUnix',
28+
metricTables: {
29+
gauge: 'otel_metrics_gauge',
30+
histogram: '',
31+
sum: '',
32+
summary: '',
33+
'exponential histogram': '',
34+
},
35+
resourceAttributesExpression: 'ResourceAttributes',
36+
} satisfies TMetricSource;
37+
38+
const config = {
39+
displayType: DisplayType.Line,
40+
connection: 'clickhouse',
41+
from: { databaseName: 'default', tableName: '' },
42+
select: [
43+
{
44+
aggFn: 'avg',
45+
aggCondition: '',
46+
aggConditionLanguage: 'lucene',
47+
valueExpression: 'Value',
48+
},
49+
],
50+
where: '',
51+
whereLanguage: 'lucene',
52+
filters: [],
53+
timestampValueExpression: 'TimeUnix',
54+
metricTables: metricSource.metricTables,
55+
dateRange,
56+
} satisfies BuilderChartConfigWithDateRange;
57+
58+
const drillDown = () =>
59+
act(async () =>
60+
buildEventsSearchUrl({ source: metricSource, config, dateRange }),
61+
);
62+
63+
describe('metric drill-down warning without a correlated log source', () => {
64+
beforeEach(() => {
65+
localStorage.clear();
66+
notifications.clean();
67+
});
68+
69+
afterEach(() => {
70+
jest.restoreAllMocks();
71+
});
72+
73+
it('warns and returns null', async () => {
74+
renderWithMantine(<div />);
75+
76+
expect(await drillDown()).toBeNull();
77+
78+
expect(
79+
await screen.findByText(/drill-down is unavailable/i),
80+
).toBeInTheDocument();
81+
});
82+
83+
it('persists the dismissal when the close button is clicked', async () => {
84+
const user = userEvent.setup();
85+
renderWithMantine(<div />);
86+
await drillDown();
87+
const toast = await screen.findByRole('alert');
88+
expect(localStorage.getItem(DISMISSED_KEY)).toBeNull();
89+
90+
await user.click(within(toast).getByRole('button'));
91+
92+
expect(localStorage.getItem(DISMISSED_KEY)).toBe('true');
93+
const show = jest.spyOn(notifications, 'show');
94+
expect(await drillDown()).toBeNull();
95+
expect(show).not.toHaveBeenCalled();
96+
});
97+
98+
it('warns instead of throwing when localStorage is unavailable', async () => {
99+
renderWithMantine(<div />);
100+
jest.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
101+
throw new DOMException('Access denied', 'SecurityError');
102+
});
103+
104+
expect(await drillDown()).toBeNull();
105+
106+
expect(
107+
await screen.findByText(/drill-down is unavailable/i),
108+
).toBeInTheDocument();
109+
});
110+
111+
it('does not persist when the toast closes without the close button', async () => {
112+
renderWithMantine(<div />);
113+
await drillDown();
114+
await screen.findByRole('alert');
115+
116+
// Auto-close goes through the same hide path as notifications.hide.
117+
act(() => {
118+
notifications.hide(TOAST_ID);
119+
});
120+
121+
expect(localStorage.getItem(DISMISSED_KEY)).toBeNull();
122+
const show = jest.spyOn(notifications, 'show');
123+
await drillDown();
124+
expect(show).toHaveBeenCalledTimes(1);
125+
});
126+
});

0 commit comments

Comments
 (0)