mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
fix: add json compatibility for infrastructure tab (#1256)
Co-authored-by: Ruben Hias <ruben.hias@techwolf.ai>
This commit is contained in:
parent
892e43f889
commit
c5cb1d4bb0
4 changed files with 46 additions and 17 deletions
5
.changeset/tricky-dodos-report.md
Normal file
5
.changeset/tricky-dodos-report.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@hyperdx/app": patch
|
||||
---
|
||||
|
||||
fix: add json compatibility for infrastructure tab
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { useMemo } from 'react';
|
||||
import { flatten } from 'flat';
|
||||
import type { ResponseJSON } from '@hyperdx/common-utils/dist/clickhouse';
|
||||
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
|
||||
import { Box } from '@mantine/core';
|
||||
|
|
@ -36,7 +37,7 @@ export function useRowData({
|
|||
const severityTextExpr =
|
||||
source.severityTextExpression || source.statusCodeExpression;
|
||||
|
||||
return useQueriedChartConfig(
|
||||
const queryResult = useQueriedChartConfig(
|
||||
{
|
||||
connection: source.connection,
|
||||
select: [
|
||||
|
|
@ -125,6 +126,38 @@ export function useRowData({
|
|||
enabled: rowId != null,
|
||||
},
|
||||
);
|
||||
|
||||
// Normalize resource and event attributes to always use flat keys for both JSON and Map columns
|
||||
const normalizedData = useMemo(() => {
|
||||
if (!queryResult.data?.data?.[0]) {
|
||||
return queryResult.data;
|
||||
}
|
||||
|
||||
const row = queryResult.data.data[0];
|
||||
const normalizedRow = { ...row };
|
||||
|
||||
if (row[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES]) {
|
||||
normalizedRow[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES] = flatten(
|
||||
row[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES],
|
||||
);
|
||||
}
|
||||
|
||||
if (row[ROW_DATA_ALIASES.EVENT_ATTRIBUTES]) {
|
||||
normalizedRow[ROW_DATA_ALIASES.EVENT_ATTRIBUTES] = flatten(
|
||||
row[ROW_DATA_ALIASES.EVENT_ATTRIBUTES],
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
...queryResult.data,
|
||||
data: [normalizedRow],
|
||||
};
|
||||
}, [queryResult.data]);
|
||||
|
||||
return {
|
||||
...queryResult,
|
||||
data: normalizedData,
|
||||
};
|
||||
}
|
||||
|
||||
export function getJSONColumnNames(meta: ResponseJSON['meta'] | undefined) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { useCallback, useContext, useMemo } from 'react';
|
||||
import { flatten } from 'flat';
|
||||
import isString from 'lodash/isString';
|
||||
import pickBy from 'lodash/pickBy';
|
||||
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
|
||||
|
|
@ -70,17 +69,9 @@ export function RowOverviewPanel({
|
|||
return false;
|
||||
});
|
||||
|
||||
// memo
|
||||
const resourceAttributes = useMemo(() => {
|
||||
return flatten<string, Record<string, string>>(
|
||||
firstRow?.__hdx_resource_attributes ?? EMPTY_OBJ,
|
||||
);
|
||||
}, [firstRow?.__hdx_resource_attributes]);
|
||||
|
||||
const _eventAttributes = firstRow?.__hdx_event_attributes ?? EMPTY_OBJ;
|
||||
const flattenedEventAttributes = useMemo(() => {
|
||||
return flatten<string, Record<string, string>>(_eventAttributes);
|
||||
}, [_eventAttributes]);
|
||||
const resourceAttributes = firstRow?.__hdx_resource_attributes ?? EMPTY_OBJ;
|
||||
const flattenedEventAttributes =
|
||||
firstRow?.__hdx_event_attributes ?? EMPTY_OBJ;
|
||||
|
||||
const dataAttributes =
|
||||
eventAttributesExpr &&
|
||||
|
|
|
|||
|
|
@ -233,11 +233,11 @@ const DBRowSidePanel = ({
|
|||
if (!source?.resourceAttributesExpression || !normalizedRow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const resourceAttrs = normalizedRow['__hdx_resource_attributes'];
|
||||
return (
|
||||
normalizedRow[source.resourceAttributesExpression]?.['k8s.pod.uid'] !=
|
||||
null ||
|
||||
normalizedRow[source.resourceAttributesExpression]?.['k8s.node.name'] !=
|
||||
null
|
||||
resourceAttrs?.['k8s.pod.uid'] != null ||
|
||||
resourceAttrs?.['k8s.node.name'] != null
|
||||
);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
|
|
|||
Loading…
Reference in a new issue