Skip to content

Commit 8a1f61e

Browse files
author
Ruben Hias
committed
fix: add json compatibility for infrastructure tab
1 parent 892e43f commit 8a1f61e

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

.changeset/tricky-dodos-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
fix: add json compatibility for infrastructure tab

packages/app/src/components/DBRowDataPanel.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useMemo } from 'react';
2+
import { flatten } from 'flat';
23
import type { ResponseJSON } from '@hyperdx/common-utils/dist/clickhouse';
34
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
45
import { Box } from '@mantine/core';
@@ -36,7 +37,7 @@ export function useRowData({
3637
const severityTextExpr =
3738
source.severityTextExpression || source.statusCodeExpression;
3839

39-
return useQueriedChartConfig(
40+
const queryResult = useQueriedChartConfig(
4041
{
4142
connection: source.connection,
4243
select: [
@@ -125,6 +126,38 @@ export function useRowData({
125126
enabled: rowId != null,
126127
},
127128
);
129+
130+
// Normalize resource and event attributes to always use flat keys for both JSON and Map columns
131+
const normalizedData = useMemo(() => {
132+
if (!queryResult.data?.data?.[0]) {
133+
return queryResult.data;
134+
}
135+
136+
const row = queryResult.data.data[0];
137+
const normalizedRow = { ...row };
138+
139+
if (row[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES]) {
140+
normalizedRow[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES] = flatten(
141+
row[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES],
142+
);
143+
}
144+
145+
if (row[ROW_DATA_ALIASES.EVENT_ATTRIBUTES]) {
146+
normalizedRow[ROW_DATA_ALIASES.EVENT_ATTRIBUTES] = flatten(
147+
row[ROW_DATA_ALIASES.EVENT_ATTRIBUTES],
148+
);
149+
}
150+
151+
return {
152+
...queryResult.data,
153+
data: [normalizedRow],
154+
};
155+
}, [queryResult.data]);
156+
157+
return {
158+
...queryResult,
159+
data: normalizedData,
160+
};
128161
}
129162

130163
export function getJSONColumnNames(meta: ResponseJSON['meta'] | undefined) {

packages/app/src/components/DBRowOverviewPanel.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useCallback, useContext, useMemo } from 'react';
2-
import { flatten } from 'flat';
32
import isString from 'lodash/isString';
43
import pickBy from 'lodash/pickBy';
54
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
@@ -70,17 +69,9 @@ export function RowOverviewPanel({
7069
return false;
7170
});
7271

73-
// memo
74-
const resourceAttributes = useMemo(() => {
75-
return flatten<string, Record<string, string>>(
76-
firstRow?.__hdx_resource_attributes ?? EMPTY_OBJ,
77-
);
78-
}, [firstRow?.__hdx_resource_attributes]);
79-
80-
const _eventAttributes = firstRow?.__hdx_event_attributes ?? EMPTY_OBJ;
81-
const flattenedEventAttributes = useMemo(() => {
82-
return flatten<string, Record<string, string>>(_eventAttributes);
83-
}, [_eventAttributes]);
72+
const resourceAttributes = firstRow?.__hdx_resource_attributes ?? EMPTY_OBJ;
73+
const flattenedEventAttributes =
74+
firstRow?.__hdx_event_attributes ?? EMPTY_OBJ;
8475

8576
const dataAttributes =
8677
eventAttributesExpr &&

packages/app/src/components/DBRowSidePanel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ const DBRowSidePanel = ({
233233
if (!source?.resourceAttributesExpression || !normalizedRow) {
234234
return false;
235235
}
236+
237+
const resourceAttrs = normalizedRow['__hdx_resource_attributes'];
236238
return (
237-
normalizedRow[source.resourceAttributesExpression]?.['k8s.pod.uid'] !=
238-
null ||
239-
normalizedRow[source.resourceAttributesExpression]?.['k8s.node.name'] !=
240-
null
239+
resourceAttrs?.['k8s.pod.uid'] != null ||
240+
resourceAttrs?.['k8s.node.name'] != null
241241
);
242242
} catch (e) {
243243
console.error(e);

0 commit comments

Comments
 (0)