Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .changeset/severity-class-classifier.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
---

Add `core/severity` with the OpenTelemetry log severity rules:
`getSeverityClass` (from SeverityNumber 1-24, falling back to a case-insensitive
severity text prefix), `getSeverityShortName` and `getSeverityLabel`.
`getSeverityClass` (from SeverityNumber 1 and up, falling back to a
case-insensitive severity text prefix), `getSeverityShortName` and
`getSeverityLabel`.
12 changes: 12 additions & 0 deletions .changeset/severity-class-filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@hyperdx/common-utils': minor
'@hyperdx/app': patch
'@hyperdx/api': patch
---

Log sources with a Severity Number Expression get a Severity filter with the
OpenTelemetry classes (TRACE to FATAL, plus OTHER), from SeverityNumber with a
severity text fallback. The severity text filter stays. Kubernetes "Errors" log
tables and LLM error counts match FATAL and ERROR, and alert notifications show
`Severity: ERROR` instead of the filter SQL. Materialized views keyed only on
severity text can't serve this filter; add SeverityNumber to their dimensions.
6 changes: 3 additions & 3 deletions .changeset/severity-number-display.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ add the stored text in parentheses when it differs, as in
`INFO (Informational)`, and take their color from the number. The search results
and pattern table use the number only when the expression names a stored numeric
column. Copy and filter actions still use the stored text. Rows without a number
in 1-24, and sources without the field, show the stored text as before. Level
labels and the waterfall flags also treat `panic`, `dpanic`, `ftl` and `severe`
as errors and `wrn` as a warning.
in 1-24, and sources without the field, show the stored text as before, and the
severity text fallback also recognizes `panic`, `severe` and Serilog short names
(`FTL`, `WRN`, `INF`, `DBG`, `TRC`, `VRB`).
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { buildSeverityClassExpressionV1 } from '@hyperdx/common-utils/dist/core/severity';
import {
AlertState,
AlertThresholdType,
Expand Down Expand Up @@ -721,6 +722,24 @@ describe('enriched message fields', () => {
});
});

it('reports a severity class filter by its classes', async () => {
const key = buildSeverityClassExpressionV1({
numberExpr: 'SeverityNumber',
textExpr: 'SeverityText',
});
const { dispatched } = await renderWithWebhook(AlertState.ALERT, {
where: '',
filters: [
{ type: 'sql', condition: `${key} IN ('ERROR')` },
{ type: 'sql', condition: "SeverityText IN ('error')" },
] satisfies Filter[],
});

expect(dispatched[0].message.sourceQuery).toBe(
"(Severity: ERROR) AND (SeverityText IN ('error'))",
);
});

it('applies the saved search pinned filters to the sample log query', async () => {
const seenQueries: string[] = [];
mockClickhouseQuery.mockImplementation(async ({ query }) => {
Expand Down
7 changes: 1 addition & 6 deletions packages/api/src/tasks/checkAlerts/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getPromqlSeries } from '@hyperdx/common-utils/dist/core/promql';
import { renderChartConfig } from '@hyperdx/common-utils/dist/core/renderChartConfig';
import { buildSearchChartConfig } from '@hyperdx/common-utils/dist/core/searchChartConfig';
import { formatDate, objectHash } from '@hyperdx/common-utils/dist/core/utils';
import { describeFilter } from '@hyperdx/common-utils/dist/filters';
import {
isPromqlSavedChartConfig,
isRawSqlSavedChartConfig,
Expand All @@ -13,7 +14,6 @@ import {
AlertThresholdType,
BuilderChartConfigWithOptDateRange,
ChartConfigWithOptDateRange,
Filter,
isRangeThresholdType,
SavedChartConfig,
SourceKind,
Expand Down Expand Up @@ -113,11 +113,6 @@ const describeThreshold = (alert: AlertInput): string => {
: `${alert.threshold}`;
};

const describeFilter = (filter: Filter): string =>
filter.type === 'sql_ast'
? `${filter.left} ${filter.operator} ${filter.right}`
: filter.condition;

const joinConditions = (...parts: (string | undefined)[]): string => {
const present = parts
.map(part => part?.trim())
Expand Down
11 changes: 7 additions & 4 deletions packages/app/src/DBSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
isBrowser,
splitAndTrimWithBracket,
} from '@hyperdx/common-utils/dist/core/utils';
import { describeFilter } from '@hyperdx/common-utils/dist/filters';
import {
BuilderChartConfigWithDateRange,
ChartConfigWithDateRange,
Expand Down Expand Up @@ -177,6 +178,7 @@ import {
parseAsSortingStateString,
parseAsStringEncoded,
} from './utils/queryParsers';
import { getSeverityClassKey } from './utils/severityClass';
import { LOCAL_STORE_CONNECTIONS_KEY } from './connection';
import { DBSearchPageAlertModal } from './DBSearchPageAlertModal';
import { SearchConfig } from './types';
Expand Down Expand Up @@ -649,9 +651,7 @@ function SaveSearchModalComponent({
<Stack gap="xs">
{searchedConfig.filters.map((filter, idx) => (
<Text key={idx} size="xs" c="dimmed">
{filter.type === 'sql_ast'
? `${filter.left} ${filter.operator} ${filter.right}`
: filter.condition}
{describeFilter(filter)}
</Text>
))}
</Stack>
Expand Down Expand Up @@ -1547,7 +1547,10 @@ function DBSearchPageContent() {

if (pendingFilterReconcileRef.current === watchedSource) {
pendingFilterReconcileRef.current = null;
const dropped = searchFilters.retainFiltersByColumns(allowed);
const dropped = searchFilters.retainFiltersByColumns(
allowed,
getSeverityClassKey(watchedSourceObj) ?? null,
);
if (dropped.length > 0) {
notifications.show({
color: 'yellow',
Expand Down
5 changes: 2 additions & 3 deletions packages/app/src/NamespaceDetailsSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DrawerBody, DrawerHeader } from '@/components/DrawerUtils';
import { useQueriedChartConfig } from '@/hooks/useChartConfig';
import { InfraPodsStatusTable } from '@/KubernetesDashboardPage';
import { getEventBody } from '@/source';
import { getLogsResultTypeQuery } from '@/utils/severityClass';
import { useZIndex, ZIndexContext } from '@/zIndex';

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

const _where = where + (resultType === 'error' ? ' Severity:err' : '');

return (
<Card p="md">
<Card.Section p="md" py="xs">
Expand Down Expand Up @@ -166,7 +165,7 @@ function NamespaceLogs({
sourceId={logSource.id}
config={{
...logSource,
where: _where,
...getLogsResultTypeQuery({ source: logSource, where, resultType }),
whereLanguage: 'lucene',
select: [
{
Expand Down
5 changes: 2 additions & 3 deletions packages/app/src/NodeDetailsSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DrawerBody, DrawerHeader } from '@/components/DrawerUtils';
import { InfraPodsStatusTable } from '@/KubernetesDashboardPage';
import { getEventBody } from '@/source';
import { formatUptime } from '@/utils';
import { getLogsResultTypeQuery } from '@/utils/severityClass';
import { useZIndex, ZIndexContext } from '@/zIndex';

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

const _where = where + (resultType === 'error' ? ' Severity:err' : '');

return (
<Card p="md">
<Card.Section p="md" py="xs">
Expand Down Expand Up @@ -179,7 +178,7 @@ function NodeLogs({
sourceId={logSource.id}
config={{
...logSource,
where: _where,
...getLogsResultTypeQuery({ source: logSource, where, resultType }),
whereLanguage: 'lucene',
select: [
{
Expand Down
7 changes: 3 additions & 4 deletions packages/app/src/PodDetailsSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { DBTimeChart } from '@/components/DBTimeChart';
import { DrawerBody, DrawerHeader } from '@/components/DrawerUtils';
import { KubeTimeline, useV2LogBatch } from '@/components/KubeComponents';
import { WithClause } from '@/hooks/useRowWhere';
import { getLogsResultTypeQuery } from '@/utils/severityClass';
import { useZIndex, ZIndexContext } from '@/zIndex';

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

const _where = where + (resultType === 'error' ? ' Severity:err' : '');

// Create a properly typed config object for DBSqlRowTable
const tableConfig = React.useMemo(() => {
return {
from: logSource.from,
where: _where,
...getLogsResultTypeQuery({ source: logSource, where, resultType }),
whereLanguage: 'lucene' as const,
timestampValueExpression: logSource.timestampValueExpression,
implicitColumnExpression: logSource.implicitColumnExpression,
Expand Down Expand Up @@ -175,7 +174,7 @@ function PodLogs({
limit: { limit: 200, offset: 0 },
dateRange,
};
}, [_where, dateRange, logSource]);
}, [where, resultType, dateRange, logSource]);

return (
<Card p="md">
Expand Down
78 changes: 78 additions & 0 deletions packages/app/src/__tests__/searchFilters.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { enableMapSet } from 'immer';
import { buildSeverityClassExpressionV1 } from '@hyperdx/common-utils/dist/core/severity';
import { filtersToQuery } from '@hyperdx/common-utils/dist/filters';
import { act, renderHook } from '@testing-library/react';

Expand Down Expand Up @@ -1252,6 +1253,83 @@ describe('searchFilters', () => {
{ type: 'sql', condition: `ServiceName IN ('app')` },
]);
});

describe('with a severity class key', () => {
const OLD = buildSeverityClassExpressionV1({
numberExpr: 'OldSeverityNumber',
textExpr: 'SeverityText',
});
const NEW = buildSeverityClassExpressionV1({
numberExpr: 'SeverityNumber',
textExpr: 'SeverityText',
});
const sql = (condition: string): ConditionFilter => ({
type: 'sql',
condition,
});

it.each([
[
'renames a stale key',
[sql(`${OLD} IN ('ERROR')`), sql(`ServiceName IN ('app')`)],
NEW,
[],
[sql(`${NEW} IN ('ERROR')`), sql(`ServiceName IN ('app')`)],
],
[
'keeps the current key without a URL update',
[sql(`${NEW} IN ('ERROR')`)],
NEW,
[],
null,
],
[
'drops class keys for a source without one',
[sql(`${OLD} IN ('ERROR')`), sql(`ServiceName IN ('app')`)],
null,
[OLD],
[sql(`ServiceName IN ('app')`)],
],
[
'merges a stale key into the current one, the later key winning',
[
sql(`${OLD} IN ('ERROR', 'WARN')`),
sql(`${NEW} IN ('FATAL')`),
sql(`${NEW} NOT IN ('ERROR')`),
],
NEW,
[],
[
sql(`${NEW} IN ('WARN', 'FATAL')`),
sql(`${NEW} NOT IN ('ERROR')`),
],
],
])('%s', (_, searchQuery, classKey, expectedDropped, expectedUrl) => {
const onFilterChangeLocal = jest.fn();
const { result } = renderHook(() =>
useSearchPageFilterState({
searchQuery,
onFilterChange: onFilterChangeLocal,
knownColumns: new Set(),
}),
);

let dropped: string[] = [];
act(() => {
dropped = result.current.retainFiltersByColumns(
new Set(['ServiceName']),
classKey,
);
});

expect(dropped).toEqual(expectedDropped);
if (expectedUrl == null) {
expect(onFilterChangeLocal).not.toHaveBeenCalled();
} else {
expect(onFilterChangeLocal).toHaveBeenLastCalledWith(expectedUrl);
}
});
});
});
});
});
17 changes: 10 additions & 7 deletions packages/app/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1553,8 +1553,11 @@ describe('getLogSeverityLevel', () => {
[undefined, 'Warning', 'warn'],
['', 'fatal', 'error'],
[undefined, 'info', undefined],
[25, 'warn', 'warn'],
[25, 'warn', 'error'],
[0, 'panic', 'error'],
[0, 'SEVERE', 'error'],
[0, 'WRN', 'warn'],
[0, 'dbug', undefined],
])('maps %p and %p to %p', (severityNumber, severityText, expected) => {
expect(getLogSeverityLevel({ severityNumber, severityText })).toBe(
expected,
Expand All @@ -1563,8 +1566,8 @@ describe('getLogSeverityLevel', () => {
});

describe('getLogLevelClass', () => {
// Log-only vocabulary that trace StatusCode and chart colors don't take.
const LOG_ONLY_PREFIXES = [
// getLogLevelClass also colors chart series and predates these logger spellings.
const NEWER_PREFIXES = [
'panic',
'dpanic',
'ftl',
Expand All @@ -1573,15 +1576,15 @@ describe('getLogLevelClass', () => {
'inf',
'dbg',
'trc',
'vrb',
];

it.each(TEXT_PREFIX_RULES.filter(r => !LOG_ONLY_PREFIXES.includes(r.prefix)))(
it.each(TEXT_PREFIX_RULES.filter(r => !NEWER_PREFIXES.includes(r.prefix)))(
'agrees with the log severity class on $prefix',
({ prefix }) => {
const severityClass = getSeverityClass({ severityText: prefix });
expect(getLogLevelClass(prefix)).toBe(
collapseSeverityClass(severityClass) ??
(severityClass === 'UNKNOWN' ? undefined : 'info'),
collapseSeverityClass(getSeverityClass({ severityText: prefix })) ??
'info',
);
},
);
Expand Down
Loading
Loading