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
9 changes: 9 additions & 0 deletions .changeset/dismiss-metric-drilldown-warning.md
Original file line number Diff line number Diff line change
@@ -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.
31 changes: 30 additions & 1 deletion packages/app/src/ChartUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,23 @@ export function tryExpandConfigVariables<
}
}

const NO_LOG_SOURCE_WARNING_DISMISSED_KEY =
Comment thread
knudtty marked this conversation as resolved.
Resolved
'drilldown-metric-correlated-log-warning';

// Called while rendering (chart tooltips), so it must not throw when storage is
Comment thread
knudtty marked this conversation as resolved.
Resolved
// 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
Expand Down Expand Up @@ -1292,9 +1309,21 @@ export function buildEventsSearchUrl({
? source.logSourceId
: undefined;
if (logSourceId == null) {
Comment thread
knudtty marked this conversation as resolved.
Resolved
if (isNoLogSourceWarningDismissed()) 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: {
Comment thread
knudtty marked this conversation as resolved.
Resolved
onClick: () => {
try {
localStorage.setItem(NO_LOG_SOURCE_WARNING_DISMISSED_KEY, 'true');
} catch {
// don't do anything
}
},
},
});
return null;
}
Expand Down
126 changes: 126 additions & 0 deletions packages/app/src/__tests__/metricDrilldownWarning.test.tsx
Original file line number Diff line number Diff line change
@@ -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(<div />);

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(<div />);
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(<div />);
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(<div />);
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);
});
});
Loading