Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use severity_number to determine severity_text_type #4694

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,11 @@ import cx from 'classnames';

export const SEVERITY_TEXT_TYPE = {
TRACE: 'TRACE',
TRACE2: 'TRACE2',
TRACE3: 'TRACE3',
TRACE4: 'TRACE4',
DEBUG: 'DEBUG',
DEBUG2: 'DEBUG2',
DEBUG3: 'DEBUG3',
DEBUG4: 'DEBUG4',
INFO: 'INFO',
INFO2: 'INFO2',
INFO3: 'INFO3',
INFO4: 'INFO4',
WARN: 'WARN',
WARN2: 'WARN2',
WARN3: 'WARN3',
WARN4: 'WARN4',
WARNING: 'WARNING',
ERROR: 'ERROR',
ERROR2: 'ERROR2',
ERROR3: 'ERROR3',
ERROR4: 'ERROR4',
FATAL: 'FATAL',
FATAL2: 'FATAL2',
FATAL3: 'FATAL3',
FATAL4: 'FATAL4',
} as const;

export const LogType = {
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/components/Logs/LogStateIndicator/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ILog } from 'types/api/logs/log';
import { getLogIndicatorType, getLogIndicatorTypeForTable } from './utils';

describe('getLogIndicatorType', () => {
it('should return severity type for valid log with severityText', () => {
it('should return severity type for valid log with severity_number', () => {
const log = {
date: '2024-02-29T12:34:46Z',
timestamp: 1646115296,
Expand All @@ -20,11 +20,12 @@ describe('getLogIndicatorType', () => {
attributesInt: {},
attributesFloat: {},
severity_text: 'INFO',
severity_number: 9,
};
expect(getLogIndicatorType(log)).toBe('INFO');
});

it('should return log level if severityText is missing', () => {
it('should return log level if severity_number is out of spec range', () => {
const log: ILog = {
date: '2024-02-29T12:34:58Z',
timestamp: 1646115296,
Expand All @@ -40,9 +41,10 @@ describe('getLogIndicatorType', () => {
attributesInt: {},
attributesFloat: {},
severity_text: 'FATAL',
severity_number: 0,
severityText: '',
};
expect(getLogIndicatorType(log)).toBe('FATAL');
expect(getLogIndicatorType(log)).toBe('INFO');
});
});

Expand All @@ -55,7 +57,7 @@ describe('getLogIndicatorTypeForTable', () => {
traceId: '987654',
spanId: '54321',
traceFlags: 0,
severity_number: 2,
severity_number: 13,
body: 'Sample log message',
resources_string: {},
attributesString: {},
Expand All @@ -67,23 +69,23 @@ describe('getLogIndicatorTypeForTable', () => {
expect(getLogIndicatorTypeForTable(log)).toBe('WARN');
});

it('should return log level if severityText is missing', () => {
it('should return log level if severity_number is out of spec range', () => {
const log = {
date: '2024-02-29T12:34:56Z',
timestamp: 1646115296,
id: '123456',
traceId: '987654',
spanId: '54321',
traceFlags: 0,
severityNumber: 2,
severityNumber: 0,
body: 'Sample log message',
resources_string: {},
attributesString: {},
attributes_string: {},
attributesInt: {},
attributesFloat: {},
log_level: 'INFO',
log_level: 'FATAL',
};
expect(getLogIndicatorTypeForTable(log)).toBe('INFO');
expect(getLogIndicatorTypeForTable(log)).toBe('FATAL');
});
});
62 changes: 23 additions & 39 deletions frontend/src/components/Logs/LogStateIndicator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,40 @@ import { ILog } from 'types/api/logs/log';

import { LogType, SEVERITY_TEXT_TYPE } from './LogStateIndicator';

const getSeverityType = (severityText: string): string => {
switch (severityText) {
case SEVERITY_TEXT_TYPE.TRACE:
case SEVERITY_TEXT_TYPE.TRACE2:
case SEVERITY_TEXT_TYPE.TRACE3:
case SEVERITY_TEXT_TYPE.TRACE4:
return SEVERITY_TEXT_TYPE.TRACE;
case SEVERITY_TEXT_TYPE.DEBUG:
case SEVERITY_TEXT_TYPE.DEBUG2:
case SEVERITY_TEXT_TYPE.DEBUG3:
case SEVERITY_TEXT_TYPE.DEBUG4:
return SEVERITY_TEXT_TYPE.DEBUG;
case SEVERITY_TEXT_TYPE.INFO:
case SEVERITY_TEXT_TYPE.INFO2:
case SEVERITY_TEXT_TYPE.INFO3:
case SEVERITY_TEXT_TYPE.INFO4:
return SEVERITY_TEXT_TYPE.INFO;
case SEVERITY_TEXT_TYPE.WARN:
case SEVERITY_TEXT_TYPE.WARN2:
case SEVERITY_TEXT_TYPE.WARN3:
case SEVERITY_TEXT_TYPE.WARN4:
case SEVERITY_TEXT_TYPE.WARNING:
return SEVERITY_TEXT_TYPE.WARN;
case SEVERITY_TEXT_TYPE.ERROR:
case SEVERITY_TEXT_TYPE.ERROR2:
case SEVERITY_TEXT_TYPE.ERROR3:
case SEVERITY_TEXT_TYPE.ERROR4:
return SEVERITY_TEXT_TYPE.ERROR;
case SEVERITY_TEXT_TYPE.FATAL:
case SEVERITY_TEXT_TYPE.FATAL2:
case SEVERITY_TEXT_TYPE.FATAL3:
case SEVERITY_TEXT_TYPE.FATAL4:
return SEVERITY_TEXT_TYPE.FATAL;
default:
return SEVERITY_TEXT_TYPE.INFO;
const getSeverityType = (severityNumber: number): string => {
if (severityNumber >= 1 && severityNumber <= 4) {
return SEVERITY_TEXT_TYPE.TRACE;
}
if (severityNumber >= 5 && severityNumber <= 8) {
return SEVERITY_TEXT_TYPE.DEBUG;
}
if (severityNumber >= 9 && severityNumber <= 12) {
return SEVERITY_TEXT_TYPE.INFO;
}
if (severityNumber >= 13 && severityNumber <= 16) {
return SEVERITY_TEXT_TYPE.WARN;
}
if (severityNumber >= 17 && severityNumber <= 20) {
return SEVERITY_TEXT_TYPE.ERROR;
}
if (severityNumber >= 21 && severityNumber <= 24) {
return SEVERITY_TEXT_TYPE.FATAL;
}
return SEVERITY_TEXT_TYPE.INFO;
};

export const getLogIndicatorType = (logData: ILog): string => {
if (logData.severity_text) {
return getSeverityType(logData.severity_text);
if (logData.severity_number) {
return getSeverityType(logData.severity_number);
}
return logData.attributes_string?.log_level || LogType.INFO;
};

export const getLogIndicatorTypeForTable = (
log: Record<string, unknown>,
): string => {
if (log.severity_text) {
return getSeverityType(log.severity_text as string);
if (log.severity_number) {
return getSeverityType(log.severity_number as number);
}
return (log.log_level as string) || LogType.INFO;
};
1 change: 1 addition & 0 deletions frontend/src/container/LogDetailedView/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export const aggregateAttributesResourcesToString = (logData: ILog): string => {
attributes: {},
resources: {},
severity_text: logData.severity_text,
severity_number: logData.severity_number,
};

Object.keys(logData).forEach((key) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/api/logs/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ILog {
attributesInt: Record<string, never>;
attributesFloat: Record<string, never>;
severity_text: string;
severity_number: number;
}

type OmitAttributesResources = Pick<
Expand Down
Loading