Loki: Fix wrong query expression with inline comments (#70947)

fix remove comments from query
This commit is contained in:
Sven Grossmann 2023-06-30 11:35:43 +02:00 committed by GitHub
parent 2084cc9955
commit 13dd821961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 0 deletions

View File

@ -161,6 +161,7 @@ describe('removeCommentsFromQuery', () => {
${'{job="grafana", bar="baz"} |="test" | logfmt | label_format level=lvl #hello'} | ${'{job="grafana", bar="baz"} |="test" | logfmt | label_format level=lvl '}
${`#sum(rate(\n{host="containers"}\n#[1m]))`} | ${`\n{host="containers"}\n`}
${`#sum(rate(\n{host="containers"}\n#| logfmt\n#[1m]))`} | ${`\n{host="containers"}\n\n`}
${'{job="grafana"}\n#hello\n| logfmt'} | ${'{job="grafana"}\n\n| logfmt'}
`('strips comments in log query: {$query}', ({ query, expectedResult }) => {
expect(removeCommentsFromQuery(query)).toBe(expectedResult);
});

View File

@ -241,6 +241,7 @@ export function removeCommentsFromQuery(query: string): string {
newQuery = newQuery + query.substring(prev, lineCommentPosition.from);
prev = lineCommentPosition.to;
}
newQuery = newQuery + query.substring(prev);
return newQuery;
}