diff --git a/public/app/plugins/datasource/loki/modifyQuery.test.ts b/public/app/plugins/datasource/loki/modifyQuery.test.ts index 8b76c465263..608fc610992 100644 --- a/public/app/plugins/datasource/loki/modifyQuery.test.ts +++ b/public/app/plugins/datasource/loki/modifyQuery.test.ts @@ -52,6 +52,8 @@ describe('addLabelToQuery()', () => { ${'{foo="bar"} | logfmt'} | ${'query with parser with an other escaped value'} | ${'bar'} | ${'='} | ${'baz\\\\'} | ${'{foo="bar"} | logfmt | bar=`baz\\`'} ${'{foo="bar"} | logfmt'} | ${'query with parser with escaped value and regex operator'} | ${'bar'} | ${'~='} | ${'\\"baz\\"'} | ${'{foo="bar"} | logfmt | bar~=`"baz"`'} ${'{foo="bar"} | logfmt'} | ${'query with parser with escaped value and regex operator'} | ${'bar'} | ${'~='} | ${'\\"baz\\"'} | ${'{foo="bar"} | logfmt | bar~=`"baz"`'} + ${'{foo="bar"} | logfmt'} | ${'query with parser, > operator and number value'} | ${'bar'} | ${'>'} | ${'5'} | ${'{foo="bar"} | logfmt | bar>5'} + ${'{foo="bar"} | logfmt'} | ${'query with parser, < operator and non-number value'} | ${'bar'} | ${'<'} | ${'5KiB'} | ${'{foo="bar"} | logfmt | bar<`5KiB`'} `( 'should add label to query: $query, description: $description', ({ query, description, label, operator, value, expectedResult }) => { diff --git a/public/app/plugins/datasource/loki/modifyQuery.ts b/public/app/plugins/datasource/loki/modifyQuery.ts index 85c46d8d9b6..8f8ee3a880c 100644 --- a/public/app/plugins/datasource/loki/modifyQuery.ts +++ b/public/app/plugins/datasource/loki/modifyQuery.ts @@ -327,9 +327,16 @@ export function addFilterAsLabelFilter( const start = query.substring(prev, match.to); const end = isLast ? query.substring(match.to) : ''; - // we now unescape all escaped values again, because we are using backticks which can handle those cases. - // we also don't care about the operator here, because we need to unescape for both, regex and equal. - const labelFilter = ` | ${filter.label}${filter.op}\`${unescapeLabelValue(filter.value)}\``; + let labelFilter = ''; + // For < and >, if the value is number, we don't add quotes around it and use it as number + if (!Number.isNaN(Number(filter.value)) && (filter.op === '<' || filter.op === '>')) { + labelFilter = ` | ${filter.label}${filter.op}${Number(filter.value)}`; + } else { + // we now unescape all escaped values again, because we are using backticks which can handle those cases. + // we also don't care about the operator here, because we need to unescape for both, regex and equal. + labelFilter = ` | ${filter.label}${filter.op}\`${unescapeLabelValue(filter.value)}\``; + } + newQuery += start + labelFilter + end; prev = match.to; }