Skip to content

Commit e884d85

Browse files
authored
fix: metrics > logs correlation flow (#711)
Ref: HDX-1537 <img width="907" alt="Screenshot 2025-03-25 at 1 52 45 PM" src="https://github.com/user-attachments/assets/f2cc7f1c-0516-4c04-a339-ec80e4cc188d" /> If no log source is associated with metric source, the app notifies users <img width="753" alt="image" src="https://github.com/user-attachments/assets/453ea3f7-f721-4189-b035-623602483c6a" />
1 parent 50ce38f commit e884d85

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

.changeset/wet-owls-marry.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+
fix: metrics > logs correlation flow

packages/app/src/components/DBTimeChart.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import Link from 'next/link';
33
import cx from 'classnames';
44
import { add } from 'date-fns';
55
import { ClickHouseQueryError } from '@hyperdx/common-utils/dist/clickhouse';
6+
import { isMetricChartConfig } from '@hyperdx/common-utils/dist/renderChartConfig';
67
import {
78
ChartConfigWithDateRange,
89
DisplayType,
910
} from '@hyperdx/common-utils/dist/types';
1011
import { Box, Button, Code, Collapse, Text } from '@mantine/core';
1112
import { useDisclosure } from '@mantine/hooks';
13+
import { notifications } from '@mantine/notifications';
1214

1315
import {
1416
convertDateRangeToGranularityString,
@@ -132,22 +134,30 @@ export function DBTimeChart({
132134
}, [activeClickPayload]);
133135

134136
const qparams = useMemo(() => {
135-
if (!clickedActiveLabelDate || !sourceId) {
137+
if (clickedActiveLabelDate == null || !source?.id == null) {
138+
return null;
139+
}
140+
const isMetricChart = isMetricChartConfig(config);
141+
if (isMetricChart && source?.logSourceId == null) {
142+
notifications.show({
143+
color: 'yellow',
144+
message: 'No log source is associated with the selected metric source.',
145+
});
136146
return null;
137147
}
138148
const from = clickedActiveLabelDate.getTime();
139149
const to = add(clickedActiveLabelDate, {
140150
seconds: convertGranularityToSeconds(granularity),
141151
}).getTime();
142152
return new URLSearchParams({
143-
source: sourceId,
153+
source: (isMetricChart ? source?.logSourceId : source?.id) ?? '',
144154
where: config.where,
145155
whereLanguage: config.whereLanguage || 'lucene',
146156
filters: JSON.stringify(config.filters),
147157
from: from.toString(),
148158
to: to.toString(),
149159
});
150-
}, [clickedActiveLabelDate, config, granularity, sourceId]);
160+
}, [clickedActiveLabelDate, config, granularity, source]);
151161

152162
return isLoading && !data ? (
153163
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">

packages/common-utils/src/renderChartConfig.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,16 +1135,21 @@ async function translateMetricChartConfig(
11351135
throw new Error(`no query support for metric type=${metricType}`);
11361136
}
11371137

1138+
export const isMetricChartConfig = (
1139+
chartConfig: ChartConfigWithOptDateRange,
1140+
) => {
1141+
return chartConfig.metricTables != null;
1142+
};
1143+
11381144
export async function renderChartConfig(
11391145
rawChartConfig: ChartConfigWithOptDateRange,
11401146
metadata: Metadata,
11411147
): Promise<ChSql> {
11421148
// metric types require more rewriting since we know more about the schema
11431149
// but goes through the same generation process
1144-
const chartConfig =
1145-
rawChartConfig.metricTables != null
1146-
? await translateMetricChartConfig(rawChartConfig, metadata)
1147-
: rawChartConfig;
1150+
const chartConfig = isMetricChartConfig(rawChartConfig)
1151+
? await translateMetricChartConfig(rawChartConfig, metadata)
1152+
: rawChartConfig;
11481153

11491154
const withClauses = await renderWith(chartConfig, metadata);
11501155
const select = await renderSelect(chartConfig, metadata);

0 commit comments

Comments
 (0)