From 0aad96cf00101adf5d8cc91fa67205b5182f74cc Mon Sep 17 00:00:00 2001 From: Aaron Knudtson <87577305+knudtty@users.noreply.github.com> Date: Tue, 6 Oct 2026 15:07:14 -0400 Subject: [PATCH 1/2] feat(app): let users permanently dismiss the metric drill-down warning --- .changeset/dismiss-metric-drilldown-warning.md | 9 +++++++++ packages/app/src/ChartUtils.tsx | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .changeset/dismiss-metric-drilldown-warning.md diff --git a/.changeset/dismiss-metric-drilldown-warning.md b/.changeset/dismiss-metric-drilldown-warning.md new file mode 100644 index 0000000000..83e0e05864 --- /dev/null +++ b/.changeset/dismiss-metric-drilldown-warning.md @@ -0,0 +1,9 @@ +--- +'@hyperdx/app': patch +--- + +feat: let users permanently dismiss the metric drill-down warning + +Drilling down from a metric chart whose source has no correlated log source +shows a warning. Clicking its close button now hides the warning for good in +that browser, and repeated clicks no longer stack copies of it. diff --git a/packages/app/src/ChartUtils.tsx b/packages/app/src/ChartUtils.tsx index 5e26a2e16f..5bce91a844 100644 --- a/packages/app/src/ChartUtils.tsx +++ b/packages/app/src/ChartUtils.tsx @@ -1257,6 +1257,9 @@ export function tryExpandConfigVariables< } } +const NO_LOG_SOURCE_WARNING_DISMISSED_KEY = + 'drilldown-metric-correlated-log-warning'; + /** * Build search URL for viewing events based on group-by values * Used by both chart clicks and table row clicks @@ -1292,9 +1295,22 @@ export function buildEventsSearchUrl({ ? source.logSourceId : undefined; if (logSourceId == null) { + if (localStorage.getItem(NO_LOG_SOURCE_WARNING_DISMISSED_KEY) === 'true') + return null; notifications.show({ color: 'yellow', - message: 'No log source is associated with the selected metric source.', + message: + 'Drill-down is unavailable for metric sources that lack correlated log sources', + id: 'no-log-source-associated', + closeButtonProps: { + onClick: () => { + try { + localStorage.setItem(NO_LOG_SOURCE_WARNING_DISMISSED_KEY, 'true'); + } catch { + // don't do anything + } + }, + }, }); return null; } From 7ade70953f1db1d014a76d62dd186e35e092d217 Mon Sep 17 00:00:00 2001 From: Aaron Knudtson <87577305+knudtty@users.noreply.github.com> Date: Tue, 6 Oct 2026 15:26:51 -0400 Subject: [PATCH 2/2] fix: pr suggestions --- packages/app/src/ChartUtils.tsx | 17 ++- .../__tests__/metricDrilldownWarning.test.tsx | 126 ++++++++++++++++++ 2 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 packages/app/src/__tests__/metricDrilldownWarning.test.tsx diff --git a/packages/app/src/ChartUtils.tsx b/packages/app/src/ChartUtils.tsx index 5bce91a844..9868c778aa 100644 --- a/packages/app/src/ChartUtils.tsx +++ b/packages/app/src/ChartUtils.tsx @@ -1260,6 +1260,20 @@ export function tryExpandConfigVariables< const NO_LOG_SOURCE_WARNING_DISMISSED_KEY = 'drilldown-metric-correlated-log-warning'; +// Called while rendering (chart tooltips), so it must not throw when storage is +// blocked (sandboxed iframe, disabled cookies) or missing (SSR). +function isNoLogSourceWarningDismissed(): boolean { + if (typeof window === 'undefined') return false; + try { + return ( + window.localStorage.getItem(NO_LOG_SOURCE_WARNING_DISMISSED_KEY) === + 'true' + ); + } catch { + return false; + } +} + /** * Build search URL for viewing events based on group-by values * Used by both chart clicks and table row clicks @@ -1295,8 +1309,7 @@ export function buildEventsSearchUrl({ ? source.logSourceId : undefined; if (logSourceId == null) { - if (localStorage.getItem(NO_LOG_SOURCE_WARNING_DISMISSED_KEY) === 'true') - return null; + if (isNoLogSourceWarningDismissed()) return null; notifications.show({ color: 'yellow', message: diff --git a/packages/app/src/__tests__/metricDrilldownWarning.test.tsx b/packages/app/src/__tests__/metricDrilldownWarning.test.tsx new file mode 100644 index 0000000000..e63fa64a87 --- /dev/null +++ b/packages/app/src/__tests__/metricDrilldownWarning.test.tsx @@ -0,0 +1,126 @@ +import { + BuilderChartConfigWithDateRange, + DisplayType, + SourceKind, + TMetricSource, +} from '@hyperdx/common-utils/dist/types'; +import { notifications } from '@mantine/notifications'; +import { act, screen, within } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; + +import { buildEventsSearchUrl } from '@/ChartUtils'; + +const DISMISSED_KEY = 'drilldown-metric-correlated-log-warning'; +const TOAST_ID = 'no-log-source-associated'; + +const dateRange: [Date, Date] = [ + new Date('2026-01-01T00:00:00.000Z'), + new Date('2026-01-01T01:00:00.000Z'), +]; + +const metricSource = { + id: 'metrics', + name: 'Metrics', + kind: SourceKind.Metric, + connection: 'clickhouse', + from: { databaseName: 'default', tableName: '' }, + timestampValueExpression: 'TimeUnix', + metricTables: { + gauge: 'otel_metrics_gauge', + histogram: '', + sum: '', + summary: '', + 'exponential histogram': '', + }, + resourceAttributesExpression: 'ResourceAttributes', +} satisfies TMetricSource; + +const config = { + displayType: DisplayType.Line, + connection: 'clickhouse', + from: { databaseName: 'default', tableName: '' }, + select: [ + { + aggFn: 'avg', + aggCondition: '', + aggConditionLanguage: 'lucene', + valueExpression: 'Value', + }, + ], + where: '', + whereLanguage: 'lucene', + filters: [], + timestampValueExpression: 'TimeUnix', + metricTables: metricSource.metricTables, + dateRange, +} satisfies BuilderChartConfigWithDateRange; + +const drillDown = () => + act(async () => + buildEventsSearchUrl({ source: metricSource, config, dateRange }), + ); + +describe('metric drill-down warning without a correlated log source', () => { + beforeEach(() => { + localStorage.clear(); + notifications.clean(); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('warns and returns null', async () => { + renderWithMantine(
); + + expect(await drillDown()).toBeNull(); + + expect( + await screen.findByText(/drill-down is unavailable/i), + ).toBeInTheDocument(); + }); + + it('persists the dismissal when the close button is clicked', async () => { + const user = userEvent.setup(); + renderWithMantine(
); + await drillDown(); + const toast = await screen.findByRole('alert'); + expect(localStorage.getItem(DISMISSED_KEY)).toBeNull(); + + await user.click(within(toast).getByRole('button')); + + expect(localStorage.getItem(DISMISSED_KEY)).toBe('true'); + const show = jest.spyOn(notifications, 'show'); + expect(await drillDown()).toBeNull(); + expect(show).not.toHaveBeenCalled(); + }); + + it('warns instead of throwing when localStorage is unavailable', async () => { + renderWithMantine(
); + jest.spyOn(Storage.prototype, 'getItem').mockImplementation(() => { + throw new DOMException('Access denied', 'SecurityError'); + }); + + expect(await drillDown()).toBeNull(); + + expect( + await screen.findByText(/drill-down is unavailable/i), + ).toBeInTheDocument(); + }); + + it('does not persist when the toast closes without the close button', async () => { + renderWithMantine(
); + await drillDown(); + await screen.findByRole('alert'); + + // Auto-close goes through the same hide path as notifications.hide. + act(() => { + notifications.hide(TOAST_ID); + }); + + expect(localStorage.getItem(DISMISSED_KEY)).toBeNull(); + const show = jest.spyOn(notifications, 'show'); + await drillDown(); + expect(show).toHaveBeenCalledTimes(1); + }); +});