-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #473 from grafana/matyax/service-scene-filtering
Service selection scene: filter logs by the selected level in the chart
- Loading branch information
Showing
5 changed files
with
244 additions
and
47 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { SeriesVisibilityChangeMode } from '@grafana/ui'; | ||
import { getLabelsFromSeries, toggleLevelFromFilter } from './levels'; | ||
import { FieldType, toDataFrame } from '@grafana/data'; | ||
|
||
const ALL_LEVELS = ['logs', 'debug', 'info', 'warn', 'error', 'crit']; | ||
|
||
describe('toggleLevelFromFilter', () => { | ||
describe('Visibility mode toggle selection', () => { | ||
it('adds the level', () => { | ||
expect(toggleLevelFromFilter('error', [], SeriesVisibilityChangeMode.ToggleSelection, ALL_LEVELS)).toEqual([ | ||
'error', | ||
]); | ||
expect(toggleLevelFromFilter('error', undefined, SeriesVisibilityChangeMode.ToggleSelection, ALL_LEVELS)).toEqual( | ||
['error'] | ||
); | ||
}); | ||
it('adds the level if the filter was not empty', () => { | ||
expect( | ||
toggleLevelFromFilter('error', ['info', 'debug'], SeriesVisibilityChangeMode.ToggleSelection, ALL_LEVELS) | ||
).toEqual(['error']); | ||
}); | ||
it('removes the level if the filter contained only the same level', () => { | ||
expect(toggleLevelFromFilter('error', ['error'], SeriesVisibilityChangeMode.ToggleSelection, ALL_LEVELS)).toEqual( | ||
[] | ||
); | ||
}); | ||
}); | ||
describe('Visibility mode append to selection', () => { | ||
it('appends the label to other levels', () => { | ||
expect( | ||
toggleLevelFromFilter('error', ['info'], SeriesVisibilityChangeMode.AppendToSelection, ALL_LEVELS) | ||
).toEqual(['info', 'error']); | ||
}); | ||
it('removes the label if already present', () => { | ||
expect( | ||
toggleLevelFromFilter('error', ['info', 'error'], SeriesVisibilityChangeMode.AppendToSelection, ALL_LEVELS) | ||
).toEqual(['info']); | ||
}); | ||
it('appends all levels except the provided level if the filter was previously empty', () => { | ||
const allButError = ALL_LEVELS.filter((level) => level !== 'error'); | ||
expect(toggleLevelFromFilter('error', [], SeriesVisibilityChangeMode.AppendToSelection, ALL_LEVELS)).toEqual( | ||
allButError | ||
); | ||
expect( | ||
toggleLevelFromFilter('error', undefined, SeriesVisibilityChangeMode.AppendToSelection, ALL_LEVELS) | ||
).toEqual(allButError); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getLabelsFromSeries', () => { | ||
const series = [ | ||
toDataFrame({ | ||
fields: [ | ||
{ name: 'Time', type: FieldType.time, values: [0] }, | ||
{ | ||
name: 'Value', | ||
type: FieldType.number, | ||
values: [1], | ||
labels: { | ||
detected_level: 'error', | ||
}, | ||
}, | ||
], | ||
}), | ||
toDataFrame({ | ||
fields: [ | ||
{ name: 'Time', type: FieldType.time, values: [0] }, | ||
{ | ||
name: 'Value', | ||
type: FieldType.number, | ||
values: [1], | ||
labels: { | ||
detected_level: 'warn', | ||
}, | ||
}, | ||
], | ||
}), | ||
toDataFrame({ | ||
fields: [ | ||
{ name: 'Time', type: FieldType.time, values: [0] }, | ||
{ | ||
name: 'Value', | ||
type: FieldType.number, | ||
values: [1], | ||
labels: {}, | ||
}, | ||
], | ||
}), | ||
]; | ||
it('returns the label value from time series', () => { | ||
expect(getLabelsFromSeries(series)).toEqual(['error', 'warn', 'logs']); | ||
}); | ||
}); |
Oops, something went wrong.