diff --git a/frontend/src/components/Logs/LogStateIndicator/LogStateIndicator.tsx b/frontend/src/components/Logs/LogStateIndicator/LogStateIndicator.tsx index 5355e38017..0a9661013e 100644 --- a/frontend/src/components/Logs/LogStateIndicator/LogStateIndicator.tsx +++ b/frontend/src/components/Logs/LogStateIndicator/LogStateIndicator.tsx @@ -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 = { diff --git a/frontend/src/components/Logs/LogStateIndicator/utils.test.ts b/frontend/src/components/Logs/LogStateIndicator/utils.test.ts index 65f6b9664d..3affc5bc11 100644 --- a/frontend/src/components/Logs/LogStateIndicator/utils.test.ts +++ b/frontend/src/components/Logs/LogStateIndicator/utils.test.ts @@ -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, @@ -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, @@ -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'); }); }); @@ -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: {}, @@ -67,7 +69,7 @@ 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, @@ -75,15 +77,15 @@ describe('getLogIndicatorTypeForTable', () => { 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'); }); }); diff --git a/frontend/src/components/Logs/LogStateIndicator/utils.ts b/frontend/src/components/Logs/LogStateIndicator/utils.ts index 7bfe7a430a..f255996d8c 100644 --- a/frontend/src/components/Logs/LogStateIndicator/utils.ts +++ b/frontend/src/components/Logs/LogStateIndicator/utils.ts @@ -2,47 +2,31 @@ 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; }; @@ -50,8 +34,8 @@ export const getLogIndicatorType = (logData: ILog): string => { export const getLogIndicatorTypeForTable = ( log: Record, ): 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; }; diff --git a/frontend/src/container/LogDetailedView/utils.tsx b/frontend/src/container/LogDetailedView/utils.tsx index c81b7dc9ed..f5d7d7e325 100644 --- a/frontend/src/container/LogDetailedView/utils.tsx +++ b/frontend/src/container/LogDetailedView/utils.tsx @@ -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) => { diff --git a/frontend/src/types/api/logs/log.ts b/frontend/src/types/api/logs/log.ts index 15b7f24c74..85574248f7 100644 --- a/frontend/src/types/api/logs/log.ts +++ b/frontend/src/types/api/logs/log.ts @@ -14,6 +14,7 @@ export interface ILog { attributesInt: Record; attributesFloat: Record; severity_text: string; + severity_number: number; } type OmitAttributesResources = Pick<