mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
b4e1e1871f
commit
8bda8b8272
@ -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);
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user