Log volume: Fix functionality if query has multiple comments (#61306)

* Log volume: Fix functionality if query has comments

* Add additional test
This commit is contained in:
Ivana Huckova 2023-01-11 17:21:02 +01:00 committed by GitHub
parent b4e1e1871f
commit 8bda8b8272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -152,6 +152,8 @@ describe('removeCommentsFromQuery', () => {
${'{job="grafana"}#hello'} | ${'{job="grafana"}'}
${'{job="grafana"} | logfmt #hello'} | ${'{job="grafana"} | logfmt '}
${'{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`}
`('strips comments in log query: {$query}', ({ query, expectedResult }) => {
expect(removeCommentsFromQuery(query)).toBe(expectedResult);
});

View File

@ -128,10 +128,7 @@ export function removeCommentsFromQuery(query: string): string {
let prev = 0;
for (let lineCommentPosition of lineCommentPositions) {
const beforeComment = query.substring(prev, lineCommentPosition.from);
const afterComment = query.substring(lineCommentPosition.to);
newQuery += beforeComment + afterComment;
newQuery = newQuery + query.substring(prev, lineCommentPosition.from);
prev = lineCommentPosition.to;
}
return newQuery;