Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
0a1bb97a
Unverified
Commit
0a1bb97a
authored
Jul 02, 2019
by
kay delaney
Committed by
GitHub
Jul 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loki: getHighlighterExpressionsFromQuery Returns null if filter term is not quoted (#17852)
Closes #17687
parent
8f150c67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
2 deletions
+17
-2
public/app/plugins/datasource/loki/query_utils.test.ts
+8
-0
public/app/plugins/datasource/loki/query_utils.ts
+9
-2
No files found.
public/app/plugins/datasource/loki/query_utils.test.ts
View file @
0a1bb97a
...
...
@@ -71,17 +71,25 @@ describe('getHighlighterExpressionsFromQuery', () => {
it
(
'returns no expressions for empty query'
,
()
=>
{
expect
(
getHighlighterExpressionsFromQuery
(
''
)).
toEqual
([]);
});
it
(
'returns a single expressions for legacy query'
,
()
=>
{
expect
(
getHighlighterExpressionsFromQuery
(
'{} x'
)).
toEqual
([
'(?i)x'
]);
expect
(
getHighlighterExpressionsFromQuery
(
'{foo="bar"} x'
)).
toEqual
([
'(?i)x'
]);
});
it
(
'returns an expression for query with filter'
,
()
=>
{
expect
(
getHighlighterExpressionsFromQuery
(
'{foo="bar"} |= "x"'
)).
toEqual
([
'x'
]);
});
it
(
'returns expressions for query with filter chain'
,
()
=>
{
expect
(
getHighlighterExpressionsFromQuery
(
'{foo="bar"} |= "x" |~ "y"'
)).
toEqual
([
'x'
,
'y'
]);
});
it
(
'returns drops expressions for query with negative filter chain'
,
()
=>
{
expect
(
getHighlighterExpressionsFromQuery
(
'{foo="bar"} |= "x" != "y"'
)).
toEqual
([
'x'
]);
});
it
(
'returns null if filter term is not wrapped in double quotes'
,
()
=>
{
expect
(
getHighlighterExpressionsFromQuery
(
'{foo="bar"} |= x'
)).
toEqual
(
null
);
});
});
public/app/plugins/datasource/loki/query_utils.ts
View file @
0a1bb97a
...
...
@@ -59,12 +59,19 @@ export function getHighlighterExpressionsFromQuery(input: string): string[] {
if
(
filterEnd
===
-
1
)
{
filterTerm
=
expression
.
trim
();
}
else
{
filterTerm
=
expression
.
substr
(
0
,
filterEnd
);
filterTerm
=
expression
.
substr
(
0
,
filterEnd
)
.
trim
()
;
expression
=
expression
.
substr
(
filterEnd
);
}
// Unwrap the filter term by removing quotes
results
.
push
(
filterTerm
.
replace
(
/^
\s
*"/g
,
''
).
replace
(
/"
\s
*$/g
,
''
));
const
quotedTerm
=
filterTerm
.
match
(
/^"
((?:[^\\
"
]
|
\\
"
)
*
)
"$/
);
if
(
quotedTerm
)
{
const
unwrappedFilterTerm
=
quotedTerm
[
1
];
results
.
push
(
unwrappedFilterTerm
);
}
else
{
return
null
;
}
}
return
results
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment