fix: Fix K8s events query for JSON schema (#1605)

Closes HDX-2738
Closes #1327

# Summary

This PR fixes the Kubernetes Warning Events table for JSON schemas.

## Before

JSON schema was broken

<img width="1200" height="361" alt="Screenshot 2026-01-14 at 2 49 05 PM" src="https://github.com/user-attachments/assets/7484599d-2f48-4386-a577-eeb58b224f28" />

## After

Map-schema and JSON schema both work:

<img width="1189" height="368" alt="Screenshot 2026-01-14 at 2 00 10 PM" src="https://github.com/user-attachments/assets/b6932d33-517f-4449-9503-a9f15d6072bb" />
<img width="1193" height="374" alt="Screenshot 2026-01-14 at 1 59 59 PM" src="https://github.com/user-attachments/assets/e47c0268-a2da-4e7a-a229-a6f5d3d9c448" />
This commit is contained in:
Drew Davis 2026-01-15 10:58:48 -05:00 committed by GitHub
parent ac3082a5ac
commit acefcbeda7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 34 deletions

View file

@ -0,0 +1,5 @@
---
"@hyperdx/app": patch
---
fix: Fix K8s events query for JSON schema

View file

@ -44,6 +44,7 @@ import SourceSchemaPreview from './components/SourceSchemaPreview';
import { SourceSelectControlled } from './components/SourceSelect';
import { useQueriedChartConfig } from './hooks/useChartConfig';
import { useDashboardRefresh } from './hooks/useDashboardRefresh';
import { useJsonColumns } from './hooks/useMetadata';
import {
convertV1ChartConfigToV2,
K8S_CPU_PERCENTAGE_NUMBER_FORMAT,
@ -1168,27 +1169,49 @@ function KubernetesDashboardPage() {
],
});
// For future use if Live button is added
const [isLive, setIsLive] = React.useState(false);
const { manualRefreshCooloff, refresh } = useDashboardRefresh({
searchedTimeRange: dateRange,
onTimeRangeSelect,
isLive,
isLive: false,
});
const whereClause = searchQuery;
const [_searchQuery, _setSearchQuery] = React.useState<string | null>(null);
const searchInputRef = React.useRef<HTMLTextAreaElement>(null);
const onSearchSubmit = React.useCallback(
(e: React.FormEvent) => {
e.preventDefault();
setSearchQuery(_searchQuery || null);
},
[_searchQuery, setSearchQuery],
);
const { data: logSourceJsonColumns, isLoading: isLoadingJsonColumns } =
useJsonColumns(
logSource && {
databaseName: logSource.from.databaseName,
tableName: logSource.from.tableName,
connectionId: logSource.connection,
},
);
const eventAttributeExpressions = useMemo(() => {
if (isLoadingJsonColumns || !logSource) {
return undefined;
}
if (
logSource.eventAttributesExpression &&
logSourceJsonColumns?.includes(logSource.eventAttributesExpression)
) {
return {
Severity: `${logSource.eventAttributesExpression}.object.type.:String`,
Kind: `${logSource.eventAttributesExpression}.object.regarding.kind.:String`,
Name: `${logSource.eventAttributesExpression}.object.regarding.name.:String`,
Message: `${logSource.eventAttributesExpression}.object.note.:String`,
};
}
return {
Severity: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'type')`,
Kind: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'regarding', 'kind')`,
Name: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'regarding', 'name')`,
Message: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'note')`,
};
}, [isLoadingJsonColumns, logSource, logSourceJsonColumns]);
return (
<Box data-testid="kubernetes-dashboard-page" p="sm">
@ -1379,27 +1402,10 @@ function KubernetesDashboardPage() {
<Card.Section p="md" py="xs">
<Flex justify="space-between">
Latest Kubernetes Warning Events
{/*
<Link
href={`/search?q=${encodeURIComponent(
`${
whereClause.trim().length > 0
? `(${whereClause.trim()}) `
: ''
}(k8s.resource.name:"events" -level:"normal")`,
)}&from=${dateRange[0].getTime()}&to=${dateRange[1].getTime()}`}
passHref
legacyBehavior
>
<Anchor size="xs" color="dimmed">
Search <IconExternalLink size={12} style={{ display: 'inline' }} />
</Anchor>
</Link>
*/}
</Flex>
</Card.Section>
<Card.Section p="md" py="sm" h={CHART_HEIGHT}>
{logSource && (
{logSource && eventAttributeExpressions && (
<DBSqlRowTableWithSideBar
sourceId={logSource.id}
config={{
@ -1417,19 +1423,21 @@ function KubernetesDashboardPage() {
alias: 'Timestamp',
},
{
valueExpression: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'type')`,
valueExpression:
eventAttributeExpressions.Severity,
alias: 'Severity',
},
{
valueExpression: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'regarding', 'kind')`,
valueExpression: eventAttributeExpressions.Kind,
alias: 'Kind',
},
{
valueExpression: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'regarding', 'name')`,
valueExpression: eventAttributeExpressions.Name,
alias: 'Name',
},
{
valueExpression: `JSONExtractString(${logSource.eventAttributesExpression}['object'], 'note')`,
valueExpression:
eventAttributeExpressions.Message,
alias: 'Message',
},
],