forked from SigNoz/signoz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logs Strip color according to
severity_text
(SigNoz#4643)
* refactor: initial setup * refactor: done with setup * refactor: done with severity text split color * refactor: initial setup * refactor: done with setup * refactor: done with severity text split color * chore: added unit test case * refactor : pointed to the correct variable --------- Co-authored-by: Nityananda Gohain <nityanandagohain@gmail.com>
- Loading branch information
1 parent
62af836
commit 54c6931
Showing
8 changed files
with
246 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
frontend/src/components/Logs/LogStateIndicator/LogStateIndicator.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import LogStateIndicator from './LogStateIndicator'; | ||
|
||
describe('LogStateIndicator', () => { | ||
it('renders correctly with default props', () => { | ||
const { container } = render(<LogStateIndicator type="INFO" />); | ||
const indicator = container.firstChild as HTMLElement; | ||
expect(indicator.classList.contains('log-state-indicator')).toBe(true); | ||
expect(indicator.classList.contains('isActive')).toBe(false); | ||
expect(container.querySelector('.line')).toBeTruthy(); | ||
expect(container.querySelector('.line')?.classList.contains('INFO')).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('renders correctly when isActive is true', () => { | ||
const { container } = render(<LogStateIndicator type="INFO" isActive />); | ||
const indicator = container.firstChild as HTMLElement; | ||
expect(indicator.classList.contains('isActive')).toBe(true); | ||
}); | ||
|
||
it('renders correctly with different types', () => { | ||
const { container: containerInfo } = render( | ||
<LogStateIndicator type="INFO" />, | ||
); | ||
expect(containerInfo.querySelector('.line')?.classList.contains('INFO')).toBe( | ||
true, | ||
); | ||
|
||
const { container: containerWarning } = render( | ||
<LogStateIndicator type="WARNING" />, | ||
); | ||
expect( | ||
containerWarning.querySelector('.line')?.classList.contains('WARNING'), | ||
).toBe(true); | ||
|
||
const { container: containerError } = render( | ||
<LogStateIndicator type="ERROR" />, | ||
); | ||
expect( | ||
containerError.querySelector('.line')?.classList.contains('ERROR'), | ||
).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
frontend/src/components/Logs/LogStateIndicator/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { ILog } from 'types/api/logs/log'; | ||
|
||
import { getLogIndicatorType, getLogIndicatorTypeForTable } from './utils'; | ||
|
||
describe('getLogIndicatorType', () => { | ||
it('should return severity type for valid log with severityText', () => { | ||
const log = { | ||
date: '2024-02-29T12:34:46Z', | ||
timestamp: 1646115296, | ||
id: '123456', | ||
traceId: '987654', | ||
spanId: '54321', | ||
traceFlags: 0, | ||
severityText: 'INFO', | ||
severityNumber: 2, | ||
body: 'Sample log Message', | ||
resources_string: {}, | ||
attributesString: {}, | ||
attributes_string: {}, | ||
attributesInt: {}, | ||
attributesFloat: {}, | ||
severity_text: 'INFO', | ||
}; | ||
expect(getLogIndicatorType(log)).toBe('INFO'); | ||
}); | ||
|
||
it('should return log level if severityText is missing', () => { | ||
const log: ILog = { | ||
date: '2024-02-29T12:34:58Z', | ||
timestamp: 1646115296, | ||
id: '123456', | ||
traceId: '987654', | ||
spanId: '54321', | ||
traceFlags: 0, | ||
severityNumber: 2, | ||
body: 'Sample log', | ||
resources_string: {}, | ||
attributesString: {}, | ||
attributes_string: {}, | ||
attributesInt: {}, | ||
attributesFloat: {}, | ||
severity_text: 'FATAL', | ||
severityText: '', | ||
}; | ||
expect(getLogIndicatorType(log)).toBe('FATAL'); | ||
}); | ||
}); | ||
|
||
describe('getLogIndicatorTypeForTable', () => { | ||
it('should return severity type for valid log with severityText', () => { | ||
const log = { | ||
date: '2024-02-29T12:34:56Z', | ||
timestamp: 1646115296, | ||
id: '123456', | ||
traceId: '987654', | ||
spanId: '54321', | ||
traceFlags: 0, | ||
severity_number: 2, | ||
body: 'Sample log message', | ||
resources_string: {}, | ||
attributesString: {}, | ||
attributes_string: {}, | ||
attributesInt: {}, | ||
attributesFloat: {}, | ||
severity_text: 'WARN', | ||
}; | ||
expect(getLogIndicatorTypeForTable(log)).toBe('WARN'); | ||
}); | ||
|
||
it('should return log level if severityText is missing', () => { | ||
const log = { | ||
date: '2024-02-29T12:34:56Z', | ||
timestamp: 1646115296, | ||
id: '123456', | ||
traceId: '987654', | ||
spanId: '54321', | ||
traceFlags: 0, | ||
severityNumber: 2, | ||
body: 'Sample log message', | ||
resources_string: {}, | ||
attributesString: {}, | ||
attributes_string: {}, | ||
attributesInt: {}, | ||
attributesFloat: {}, | ||
log_level: 'INFO', | ||
}; | ||
expect(getLogIndicatorTypeForTable(log)).toBe('INFO'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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; | ||
} | ||
}; | ||
|
||
export const getLogIndicatorType = (logData: ILog): string => { | ||
if (logData.severity_text) { | ||
return getSeverityType(logData.severity_text); | ||
} | ||
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); | ||
} | ||
return (log.log_level as string) || LogType.INFO; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters