Commit 23327fcd by Ivana Huckova Committed by GitHub

Loki: Remove appending of (?i) in Loki query editor if not added by user (#20908)

parent b4736558
......@@ -439,13 +439,13 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
case 'ADD_FILTER': {
selectorLabels = addLabelToSelector(selector, action.key, action.value);
selectorFilters = keepSelectorFilters(selector);
selector = `${selectorLabels} ${selectorFilters}`;
selector = `${selectorLabels} ${selectorFilters}`.trim();
break;
}
case 'ADD_FILTER_OUT': {
selectorLabels = addLabelToSelector(selector, action.key, action.value, '!=');
selectorFilters = keepSelectorFilters(selector);
selector = `${selectorLabels} ${selectorFilters}`;
selector = `${selectorLabels} ${selectorFilters}`.trim();
break;
}
default:
......
......@@ -26,14 +26,14 @@ describe('parseQuery', () => {
it('returns query for strings with query and search string', () => {
expect(parseQuery('x {foo="bar"}')).toEqual({
query: '{foo="bar"}',
regexp: '(?i)x',
regexp: 'x',
} as LokiExpression);
});
it('returns query for strings with query and regexp', () => {
expect(parseQuery('{foo="bar"} x|y')).toEqual({
query: '{foo="bar"}',
regexp: '(?i)x|y',
regexp: 'x|y',
} as LokiExpression);
});
......@@ -47,11 +47,11 @@ describe('parseQuery', () => {
it('returns query and regexp with quantifiers', () => {
expect(parseQuery('{foo="bar"} \\.java:[0-9]{1,5}')).toEqual({
query: '{foo="bar"}',
regexp: '(?i)\\.java:[0-9]{1,5}',
regexp: '\\.java:[0-9]{1,5}',
} as LokiExpression);
expect(parseQuery('\\.java:[0-9]{1,5} {foo="bar"}')).toEqual({
query: '{foo="bar"}',
regexp: '(?i)\\.java:[0-9]{1,5}',
regexp: '\\.java:[0-9]{1,5}',
} as LokiExpression);
});
......@@ -73,8 +73,8 @@ describe('getHighlighterExpressionsFromQuery', () => {
});
it('returns a single expressions for legacy query', () => {
expect(getHighlighterExpressionsFromQuery('{} x')).toEqual(['(?i)x']);
expect(getHighlighterExpressionsFromQuery('{foo="bar"} x')).toEqual(['(?i)x']);
expect(getHighlighterExpressionsFromQuery('{} x')).toEqual(['x']);
expect(getHighlighterExpressionsFromQuery('{foo="bar"} x')).toEqual(['x']);
});
it('returns an expression for query with filter', () => {
......
import { LokiExpression } from './types';
const selectorRegexp = /(?:^|\s){[^{]*}/g;
const caseInsensitive = '(?i)'; // Golang mode modifier for Loki, doesn't work in JavaScript
export function parseQuery(input: string): LokiExpression {
input = input || '';
const match = input.match(selectorRegexp);
......@@ -9,13 +8,11 @@ export function parseQuery(input: string): LokiExpression {
let regexp = '';
if (match) {
// Regexp result is ignored on the server side
regexp = input.replace(selectorRegexp, '').trim();
// Keep old-style regexp, otherwise take whole query
if (regexp && regexp.search(/\|=|\|~|!=|!~/) === -1) {
query = match[0].trim();
if (!regexp.startsWith(caseInsensitive)) {
regexp = `${caseInsensitive}${regexp}`;
}
} else {
regexp = '';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment