| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import { calculateLogsLabelStats, dedupLogRows, LogsDedupStrategy, LogsModel } from '../logs_model';
- describe('dedupLogRows()', () => {
- test('should return rows as is when dedup is set to none', () => {
- const logs = {
- rows: [
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- ],
- };
- expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.none).rows).toMatchObject(logs.rows);
- });
- test('should dedup on exact matches', () => {
- const logs = {
- rows: [
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- {
- entry: 'INFO test 2.44 on [xxx]',
- },
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- ],
- };
- expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.exact).rows).toEqual([
- {
- duplicates: 1,
- entry: 'WARN test 1.23 on [xxx]',
- },
- {
- duplicates: 0,
- entry: 'INFO test 2.44 on [xxx]',
- },
- {
- duplicates: 0,
- entry: 'WARN test 1.23 on [xxx]',
- },
- ]);
- });
- test('should dedup on number matches', () => {
- const logs = {
- rows: [
- {
- entry: 'WARN test 1.2323423 on [xxx]',
- },
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- {
- entry: 'INFO test 2.44 on [xxx]',
- },
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- ],
- };
- expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.numbers).rows).toEqual([
- {
- duplicates: 1,
- entry: 'WARN test 1.2323423 on [xxx]',
- },
- {
- duplicates: 0,
- entry: 'INFO test 2.44 on [xxx]',
- },
- {
- duplicates: 0,
- entry: 'WARN test 1.23 on [xxx]',
- },
- ]);
- });
- test('should dedup on signature matches', () => {
- const logs = {
- rows: [
- {
- entry: 'WARN test 1.2323423 on [xxx]',
- },
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- {
- entry: 'INFO test 2.44 on [xxx]',
- },
- {
- entry: 'WARN test 1.23 on [xxx]',
- },
- ],
- };
- expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.signature).rows).toEqual([
- {
- duplicates: 3,
- entry: 'WARN test 1.2323423 on [xxx]',
- },
- ]);
- });
- });
- describe('calculateLogsLabelStats()', () => {
- test('should return no stats for empty rows', () => {
- expect(calculateLogsLabelStats([], '')).toEqual([]);
- });
- test('should return no stats of label is not found', () => {
- const rows = [
- {
- entry: 'foo 1',
- labels: {
- foo: 'bar',
- },
- },
- ];
- expect(calculateLogsLabelStats(rows as any, 'baz')).toEqual([]);
- });
- test('should return stats for found labels', () => {
- const rows = [
- {
- entry: 'foo 1',
- labels: {
- foo: 'bar',
- },
- },
- {
- entry: 'foo 0',
- labels: {
- foo: 'xxx',
- },
- },
- {
- entry: 'foo 2',
- labels: {
- foo: 'bar',
- },
- },
- ];
- expect(calculateLogsLabelStats(rows as any, 'foo')).toMatchObject([
- {
- value: 'bar',
- count: 2,
- },
- {
- value: 'xxx',
- count: 1,
- },
- ]);
- });
- });
|