|
|
|
@ -7,6 +7,7 @@ import { |
|
|
|
|
isValidQuery, |
|
|
|
|
parseToNodeNamesArray, |
|
|
|
|
getParserFromQuery, |
|
|
|
|
obfuscate, |
|
|
|
|
} from './queryUtils'; |
|
|
|
|
import { LokiQuery, LokiQueryType } from './types'; |
|
|
|
|
|
|
|
|
@ -168,7 +169,7 @@ describe('isValidQuery', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('parseToArray', () => { |
|
|
|
|
describe('parseToNodeNamesArray', () => { |
|
|
|
|
it('returns on empty query', () => { |
|
|
|
|
expect(parseToNodeNamesArray('{}')).toEqual(['LogQL', 'Expr', 'LogExpr', 'Selector', '⚠']); |
|
|
|
|
}); |
|
|
|
@ -201,6 +202,34 @@ describe('parseToArray', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('obfuscate', () => { |
|
|
|
|
it('obfuscates on invalid query', () => { |
|
|
|
|
expect(obfuscate('{job="grafana"')).toEqual('{Identifier=String'); |
|
|
|
|
}); |
|
|
|
|
it('obfuscates on valid query', () => { |
|
|
|
|
expect( |
|
|
|
|
obfuscate('sum(sum_over_time({test="test"} |= `` | logfmt | __error__=`` | unwrap test | __error__=`` [10m]))') |
|
|
|
|
).toEqual( |
|
|
|
|
'sum(sum_over_time({Identifier=String} |= String | logfmt | __error__=String | unwrap Identifier | __error__=String [10m]))' |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
it('obfuscates on arithmetic operation', () => { |
|
|
|
|
expect(obfuscate('2 + 3')).toEqual('Number + Number'); |
|
|
|
|
}); |
|
|
|
|
it('obfuscates a comment', () => { |
|
|
|
|
expect(obfuscate('{job="grafana"} # test comment')).toEqual('{Identifier=String} LineComment'); |
|
|
|
|
}); |
|
|
|
|
it('does not obfuscate interval variables', () => { |
|
|
|
|
expect( |
|
|
|
|
obfuscate( |
|
|
|
|
'sum(quantile_over_time(0.5, {label="$var"} | logfmt | __error__=`` | unwrap latency | __error__=`` [$__interval]))' |
|
|
|
|
) |
|
|
|
|
).toEqual( |
|
|
|
|
'sum(quantile_over_time(Number, {Identifier=String} | logfmt | __error__=String | unwrap Identifier | __error__=String [$__interval]))' |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
describe('isLogsQuery', () => { |
|
|
|
|
it('returns false if metrics query', () => { |
|
|
|
|
expect(isLogsQuery('rate({job="grafana"}[5m])')).toBe(false); |
|
|
|
|