[v10.0.x] Loki: Fix wrong query expression with inline comments (#70948)
Loki: Fix wrong query expression with inline comments (#70947)
fix remove comments from query
(cherry picked from commit 13dd821961)
Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
This commit is contained in:
co-authored by
Sven Grossmann
parent
b2bbe10fbc
commit
0e092ba6a1
@@ -156,6 +156,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);
|
||||
});
|
||||
|
||||
@@ -131,6 +131,7 @@ export function removeCommentsFromQuery(query: string): string {
|
||||
newQuery = newQuery + query.substring(prev, lineCommentPosition.from);
|
||||
prev = lineCommentPosition.to;
|
||||
}
|
||||
newQuery = newQuery + query.substring(prev);
|
||||
return newQuery;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user