Skip to content

Commit 2faf6d1

Browse files
committed
feat: Severity filter for logs that considers SeverityNumber and SeverityText
1 parent ea511ac commit 2faf6d1

37 files changed

Lines changed: 1719 additions & 136 deletions

‎.changeset/severity-class-classifier.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
---
44

55
Add `core/severity` with the OpenTelemetry log severity rules:
6-
`getSeverityClass` (from SeverityNumber 1-24, falling back to a case-insensitive
7-
severity text prefix), `getSeverityShortName` and `getSeverityLabel`.
6+
`getSeverityClass` (from SeverityNumber 1 and up, falling back to a
7+
case-insensitive severity text prefix), `getSeverityShortName` and
8+
`getSeverityLabel`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@hyperdx/common-utils': minor
3+
'@hyperdx/app': patch
4+
'@hyperdx/api': patch
5+
---
6+
7+
Log sources with a Severity Number Expression get a Severity filter with the
8+
OpenTelemetry classes (TRACE to FATAL, plus OTHER), from SeverityNumber with a
9+
severity text fallback. The severity text filter stays. Kubernetes "Errors" log
10+
tables and LLM error counts match FATAL and ERROR, and alert notifications show
11+
`Severity: ERROR` instead of the filter SQL. Materialized views keyed only on
12+
severity text can't serve this filter; add SeverityNumber to their dimensions.

‎.changeset/severity-number-display.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ add the stored text in parentheses when it differs, as in
1010
`INFO (Informational)`, and take their color from the number. The search results
1111
and pattern table use the number only when the expression names a stored numeric
1212
column. Copy and filter actions still use the stored text. Rows without a number
13-
in 1-24, and sources without the field, show the stored text as before. Level
14-
labels and the waterfall flags also treat `panic`, `dpanic`, `ftl` and `severe`
15-
as errors and `wrn` as a warning.
13+
in 1-24, and sources without the field, show the stored text as before, and the
14+
severity text fallback also recognizes `panic`, `severe` and Serilog short names
15+
(`FTL`, `WRN`, `INF`, `DBG`, `TRC`, `VRB`).

‎packages/api/src/tasks/checkAlerts/__tests__/renderAlertTemplate.int.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { buildSeverityClassExpressionV1 } from '@hyperdx/common-utils/dist/core/severity';
12
import {
23
AlertState,
34
AlertThresholdType,
@@ -721,6 +722,24 @@ describe('enriched message fields', () => {
721722
});
722723
});
723724

725+
it('reports a severity class filter by its classes', async () => {
726+
const key = buildSeverityClassExpressionV1({
727+
numberExpr: 'SeverityNumber',
728+
textExpr: 'SeverityText',
729+
});
730+
const { dispatched } = await renderWithWebhook(AlertState.ALERT, {
731+
where: '',
732+
filters: [
733+
{ type: 'sql', condition: `${key} IN ('ERROR')` },
734+
{ type: 'sql', condition: "SeverityText IN ('error')" },
735+
] satisfies Filter[],
736+
});
737+
738+
expect(dispatched[0].message.sourceQuery).toBe(
739+
"(Severity: ERROR) AND (SeverityText IN ('error'))",
740+
);
741+
});
742+
724743
it('applies the saved search pinned filters to the sample log query', async () => {
725744
const seenQueries: string[] = [];
726745
mockClickhouseQuery.mockImplementation(async ({ query }) => {

‎packages/api/src/tasks/checkAlerts/template.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getPromqlSeries } from '@hyperdx/common-utils/dist/core/promql';
44
import { renderChartConfig } from '@hyperdx/common-utils/dist/core/renderChartConfig';
55
import { buildSearchChartConfig } from '@hyperdx/common-utils/dist/core/searchChartConfig';
66
import { formatDate, objectHash } from '@hyperdx/common-utils/dist/core/utils';
7+
import { describeFilter } from '@hyperdx/common-utils/dist/filters';
78
import {
89
isPromqlSavedChartConfig,
910
isRawSqlSavedChartConfig,
@@ -13,7 +14,6 @@ import {
1314
AlertThresholdType,
1415
BuilderChartConfigWithOptDateRange,
1516
ChartConfigWithOptDateRange,
16-
Filter,
1717
isRangeThresholdType,
1818
SavedChartConfig,
1919
SourceKind,
@@ -113,11 +113,6 @@ const describeThreshold = (alert: AlertInput): string => {
113113
: `${alert.threshold}`;
114114
};
115115

116-
const describeFilter = (filter: Filter): string =>
117-
filter.type === 'sql_ast'
118-
? `${filter.left} ${filter.operator} ${filter.right}`
119-
: filter.condition;
120-
121116
const joinConditions = (...parts: (string | undefined)[]): string => {
122117
const present = parts
123118
.map(part => part?.trim())

‎packages/app/src/DBSearchPage.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
isBrowser,
3939
splitAndTrimWithBracket,
4040
} from '@hyperdx/common-utils/dist/core/utils';
41+
import { describeFilter } from '@hyperdx/common-utils/dist/filters';
4142
import {
4243
BuilderChartConfigWithDateRange,
4344
ChartConfigWithDateRange,
@@ -177,6 +178,7 @@ import {
177178
parseAsSortingStateString,
178179
parseAsStringEncoded,
179180
} from './utils/queryParsers';
181+
import { getSeverityClassKey } from './utils/severityClass';
180182
import { LOCAL_STORE_CONNECTIONS_KEY } from './connection';
181183
import { DBSearchPageAlertModal } from './DBSearchPageAlertModal';
182184
import { SearchConfig } from './types';
@@ -649,9 +651,7 @@ function SaveSearchModalComponent({
649651
<Stack gap="xs">
650652
{searchedConfig.filters.map((filter, idx) => (
651653
<Text key={idx} size="xs" c="dimmed">
652-
{filter.type === 'sql_ast'
653-
? `${filter.left} ${filter.operator} ${filter.right}`
654-
: filter.condition}
654+
{describeFilter(filter)}
655655
</Text>
656656
))}
657657
</Stack>
@@ -1547,7 +1547,10 @@ function DBSearchPageContent() {
15471547

15481548
if (pendingFilterReconcileRef.current === watchedSource) {
15491549
pendingFilterReconcileRef.current = null;
1550-
const dropped = searchFilters.retainFiltersByColumns(allowed);
1550+
const dropped = searchFilters.retainFiltersByColumns(
1551+
allowed,
1552+
getSeverityClassKey(watchedSourceObj) ?? null,
1553+
);
15511554
if (dropped.length > 0) {
15521555
notifications.show({
15531556
color: 'yellow',

‎packages/app/src/NamespaceDetailsSidePanel.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { DrawerBody, DrawerHeader } from '@/components/DrawerUtils';
2424
import { useQueriedChartConfig } from '@/hooks/useChartConfig';
2525
import { InfraPodsStatusTable } from '@/KubernetesDashboardPage';
2626
import { getEventBody } from '@/source';
27+
import { getLogsResultTypeQuery } from '@/utils/severityClass';
2728
import { useZIndex, ZIndexContext } from '@/zIndex';
2829

2930
import DBSqlRowTableWithSideBar from './components/DBSqlRowTableWithSidebar';
@@ -126,8 +127,6 @@ function NamespaceLogs({
126127
}) {
127128
const [resultType, setResultType] = React.useState<'all' | 'error'>('all');
128129

129-
const _where = where + (resultType === 'error' ? ' Severity:err' : '');
130-
131130
return (
132131
<Card p="md">
133132
<Card.Section p="md" py="xs">
@@ -166,7 +165,7 @@ function NamespaceLogs({
166165
sourceId={logSource.id}
167166
config={{
168167
...logSource,
169-
where: _where,
168+
...getLogsResultTypeQuery({ source: logSource, where, resultType }),
170169
whereLanguage: 'lucene',
171170
select: [
172171
{

‎packages/app/src/NodeDetailsSidePanel.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { DrawerBody, DrawerHeader } from '@/components/DrawerUtils';
2424
import { InfraPodsStatusTable } from '@/KubernetesDashboardPage';
2525
import { getEventBody } from '@/source';
2626
import { formatUptime } from '@/utils';
27+
import { getLogsResultTypeQuery } from '@/utils/severityClass';
2728
import { useZIndex, ZIndexContext } from '@/zIndex';
2829

2930
import DBSqlRowTableWithSideBar from './components/DBSqlRowTableWithSidebar';
@@ -139,8 +140,6 @@ function NodeLogs({
139140
}) {
140141
const [resultType, setResultType] = React.useState<'all' | 'error'>('all');
141142

142-
const _where = where + (resultType === 'error' ? ' Severity:err' : '');
143-
144143
return (
145144
<Card p="md">
146145
<Card.Section p="md" py="xs">
@@ -179,7 +178,7 @@ function NodeLogs({
179178
sourceId={logSource.id}
180179
config={{
181180
...logSource,
182-
where: _where,
181+
...getLogsResultTypeQuery({ source: logSource, where, resultType }),
183182
whereLanguage: 'lucene',
184183
select: [
185184
{

‎packages/app/src/PodDetailsSidePanel.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { DBTimeChart } from '@/components/DBTimeChart';
2525
import { DrawerBody, DrawerHeader } from '@/components/DrawerUtils';
2626
import { KubeTimeline, useV2LogBatch } from '@/components/KubeComponents';
2727
import { WithClause } from '@/hooks/useRowWhere';
28+
import { getLogsResultTypeQuery } from '@/utils/severityClass';
2829
import { useZIndex, ZIndexContext } from '@/zIndex';
2930

3031
import DBSqlRowTableWithSideBar from './components/DBSqlRowTableWithSidebar';
@@ -136,13 +137,11 @@ function PodLogs({
136137
}) {
137138
const [resultType, setResultType] = React.useState<'all' | 'error'>('all');
138139

139-
const _where = where + (resultType === 'error' ? ' Severity:err' : '');
140-
141140
// Create a properly typed config object for DBSqlRowTable
142141
const tableConfig = React.useMemo(() => {
143142
return {
144143
from: logSource.from,
145-
where: _where,
144+
...getLogsResultTypeQuery({ source: logSource, where, resultType }),
146145
whereLanguage: 'lucene' as const,
147146
timestampValueExpression: logSource.timestampValueExpression,
148147
implicitColumnExpression: logSource.implicitColumnExpression,
@@ -175,7 +174,7 @@ function PodLogs({
175174
limit: { limit: 200, offset: 0 },
176175
dateRange,
177176
};
178-
}, [_where, dateRange, logSource]);
177+
}, [where, resultType, dateRange, logSource]);
179178

180179
return (
181180
<Card p="md">

‎packages/app/src/__tests__/searchFilters.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { enableMapSet } from 'immer';
2+
import { buildSeverityClassExpressionV1 } from '@hyperdx/common-utils/dist/core/severity';
23
import { filtersToQuery } from '@hyperdx/common-utils/dist/filters';
34
import { act, renderHook } from '@testing-library/react';
45

@@ -1252,6 +1253,83 @@ describe('searchFilters', () => {
12521253
{ type: 'sql', condition: `ServiceName IN ('app')` },
12531254
]);
12541255
});
1256+
1257+
describe('with a severity class key', () => {
1258+
const OLD = buildSeverityClassExpressionV1({
1259+
numberExpr: 'OldSeverityNumber',
1260+
textExpr: 'SeverityText',
1261+
});
1262+
const NEW = buildSeverityClassExpressionV1({
1263+
numberExpr: 'SeverityNumber',
1264+
textExpr: 'SeverityText',
1265+
});
1266+
const sql = (condition: string): ConditionFilter => ({
1267+
type: 'sql',
1268+
condition,
1269+
});
1270+
1271+
it.each([
1272+
[
1273+
'renames a stale key',
1274+
[sql(`${OLD} IN ('ERROR')`), sql(`ServiceName IN ('app')`)],
1275+
NEW,
1276+
[],
1277+
[sql(`${NEW} IN ('ERROR')`), sql(`ServiceName IN ('app')`)],
1278+
],
1279+
[
1280+
'keeps the current key without a URL update',
1281+
[sql(`${NEW} IN ('ERROR')`)],
1282+
NEW,
1283+
[],
1284+
null,
1285+
],
1286+
[
1287+
'drops class keys for a source without one',
1288+
[sql(`${OLD} IN ('ERROR')`), sql(`ServiceName IN ('app')`)],
1289+
null,
1290+
[OLD],
1291+
[sql(`ServiceName IN ('app')`)],
1292+
],
1293+
[
1294+
'merges a stale key into the current one, the later key winning',
1295+
[
1296+
sql(`${OLD} IN ('ERROR', 'WARN')`),
1297+
sql(`${NEW} IN ('FATAL')`),
1298+
sql(`${NEW} NOT IN ('ERROR')`),
1299+
],
1300+
NEW,
1301+
[],
1302+
[
1303+
sql(`${NEW} IN ('WARN', 'FATAL')`),
1304+
sql(`${NEW} NOT IN ('ERROR')`),
1305+
],
1306+
],
1307+
])('%s', (_, searchQuery, classKey, expectedDropped, expectedUrl) => {
1308+
const onFilterChangeLocal = jest.fn();
1309+
const { result } = renderHook(() =>
1310+
useSearchPageFilterState({
1311+
searchQuery,
1312+
onFilterChange: onFilterChangeLocal,
1313+
knownColumns: new Set(),
1314+
}),
1315+
);
1316+
1317+
let dropped: string[] = [];
1318+
act(() => {
1319+
dropped = result.current.retainFiltersByColumns(
1320+
new Set(['ServiceName']),
1321+
classKey,
1322+
);
1323+
});
1324+
1325+
expect(dropped).toEqual(expectedDropped);
1326+
if (expectedUrl == null) {
1327+
expect(onFilterChangeLocal).not.toHaveBeenCalled();
1328+
} else {
1329+
expect(onFilterChangeLocal).toHaveBeenLastCalledWith(expectedUrl);
1330+
}
1331+
});
1332+
});
12551333
});
12561334
});
12571335
});

0 commit comments

Comments
 (0)