Skip to content

Commit cc5cb2d

Browse files
author
Ruben Hias
committed
fix: add json compatibility for infrastructure tab
1 parent dbf1682 commit cc5cb2d

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

packages/app/src/components/DBInfraPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const InfraSubpanelGroup = ({
119119
where,
120120
groupBy: [],
121121
aggFn: 'avg',
122-
field: `${fieldPrefix}cpu.utilization - Gauge`,
122+
field: `${fieldPrefix}cpu.usage - Gauge`,
123123
table: 'metrics',
124124
numberFormat: K8S_CPU_PERCENTAGE_NUMBER_FORMAT,
125125
},

packages/app/src/components/DBRowDataPanel.tsx

Lines changed: 32 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';
@@ -23,7 +24,7 @@ export function useRowData({
2324
const severityTextExpr =
2425
source.severityTextExpression || source.statusCodeExpression;
2526

26-
return useQueriedChartConfig(
27+
const queryResult = useQueriedChartConfig(
2728
{
2829
connection: source.connection,
2930
select: [
@@ -112,6 +113,36 @@ export function useRowData({
112113
enabled: rowId != null,
113114
},
114115
);
116+
117+
// Normalize resource and event attributes to always use flat keys for both JSON and Map columns
118+
const normalizedData = useMemo(() => {
119+
if (!queryResult.data?.data?.[0]) {
120+
return queryResult.data;
121+
}
122+
123+
const row = queryResult.data.data[0];
124+
const normalizedRow = { ...row };
125+
126+
if (row.__hdx_resource_attributes) {
127+
normalizedRow.__hdx_resource_attributes = flatten(
128+
row.__hdx_resource_attributes,
129+
);
130+
}
131+
132+
if (row.__hdx_event_attributes) {
133+
normalizedRow.__hdx_event_attributes = flatten(row.__hdx_event_attributes);
134+
}
135+
136+
return {
137+
...queryResult.data,
138+
data: [normalizedRow],
139+
};
140+
}, [queryResult.data]);
141+
142+
return {
143+
...queryResult,
144+
data: normalizedData,
145+
};
115146
}
116147

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

packages/app/src/components/DBRowOverviewPanel.tsx

Lines changed: 2 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,8 @@ 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 = firstRow?.__hdx_event_attributes ?? EMPTY_OBJ;
8474

8575
const dataAttributes =
8676
eventAttributesExpr &&

packages/app/src/components/DBRowSidePanel.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ const DBRowSidePanel = ({
231231
if (!source?.resourceAttributesExpression || !normalizedRow) {
232232
return false;
233233
}
234+
235+
const resourceAttrs = normalizedRow['__hdx_resource_attributes'];
234236
return (
235-
normalizedRow[source.resourceAttributesExpression]?.['k8s.pod.uid'] !=
236-
null ||
237-
normalizedRow[source.resourceAttributesExpression]?.['k8s.node.name'] !=
238-
null
237+
resourceAttrs?.['k8s.pod.uid'] != null ||
238+
resourceAttrs?.['k8s.node.name'] != null
239239
);
240240
} catch (e) {
241241
console.error(e);

0 commit comments

Comments
 (0)