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
23327fcd
Unverified
Commit
23327fcd
authored
Dec 06, 2019
by
Ivana Huckova
Committed by
GitHub
Dec 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loki: Remove appending of (?i) in Loki query editor if not added by user (#20908)
parent
b4736558
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
12 deletions
+9
-12
public/app/plugins/datasource/loki/datasource.ts
+2
-2
public/app/plugins/datasource/loki/query_utils.test.ts
+6
-6
public/app/plugins/datasource/loki/query_utils.ts
+1
-4
No files found.
public/app/plugins/datasource/loki/datasource.ts
View file @
23327fcd
...
...
@@ -439,13 +439,13 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
case
'ADD_FILTER'
:
{
selectorLabels
=
addLabelToSelector
(
selector
,
action
.
key
,
action
.
value
);
selectorFilters
=
keepSelectorFilters
(
selector
);
selector
=
`
${
selectorLabels
}
${
selectorFilters
}
`
;
selector
=
`
${
selectorLabels
}
${
selectorFilters
}
`
.
trim
()
;
break
;
}
case
'ADD_FILTER_OUT'
:
{
selectorLabels
=
addLabelToSelector
(
selector
,
action
.
key
,
action
.
value
,
'!='
);
selectorFilters
=
keepSelectorFilters
(
selector
);
selector
=
`
${
selectorLabels
}
${
selectorFilters
}
`
;
selector
=
`
${
selectorLabels
}
${
selectorFilters
}
`
.
trim
()
;
break
;
}
default
:
...
...
public/app/plugins/datasource/loki/query_utils.test.ts
View file @
23327fcd
...
...
@@ -26,14 +26,14 @@ describe('parseQuery', () => {
it
(
'returns query for strings with query and search string'
,
()
=>
{
expect
(
parseQuery
(
'x {foo="bar"}'
)).
toEqual
({
query
:
'{foo="bar"}'
,
regexp
:
'
(?i)
x'
,
regexp
:
'x'
,
}
as
LokiExpression
);
});
it
(
'returns query for strings with query and regexp'
,
()
=>
{
expect
(
parseQuery
(
'{foo="bar"} x|y'
)).
toEqual
({
query
:
'{foo="bar"}'
,
regexp
:
'
(?i)
x|y'
,
regexp
:
'x|y'
,
}
as
LokiExpression
);
});
...
...
@@ -47,11 +47,11 @@ describe('parseQuery', () => {
it
(
'returns query and regexp with quantifiers'
,
()
=>
{
expect
(
parseQuery
(
'{foo="bar"}
\\
.java:[0-9]{1,5}'
)).
toEqual
({
query
:
'{foo="bar"}'
,
regexp
:
'
(?i)
\\
.java:[0-9]{1,5}'
,
regexp
:
'
\\
.java:[0-9]{1,5}'
,
}
as
LokiExpression
);
expect
(
parseQuery
(
'
\\
.java:[0-9]{1,5} {foo="bar"}'
)).
toEqual
({
query
:
'{foo="bar"}'
,
regexp
:
'
(?i)
\\
.java:[0-9]{1,5}'
,
regexp
:
'
\\
.java:[0-9]{1,5}'
,
}
as
LokiExpression
);
});
...
...
@@ -73,8 +73,8 @@ describe('getHighlighterExpressionsFromQuery', () => {
});
it
(
'returns a single expressions for legacy query'
,
()
=>
{
expect
(
getHighlighterExpressionsFromQuery
(
'{} x'
)).
toEqual
([
'
(?i)
x'
]);
expect
(
getHighlighterExpressionsFromQuery
(
'{foo="bar"} x'
)).
toEqual
([
'
(?i)
x'
]);
expect
(
getHighlighterExpressionsFromQuery
(
'{} x'
)).
toEqual
([
'x'
]);
expect
(
getHighlighterExpressionsFromQuery
(
'{foo="bar"} x'
)).
toEqual
([
'x'
]);
});
it
(
'returns an expression for query with filter'
,
()
=>
{
...
...
public/app/plugins/datasource/loki/query_utils.ts
View file @
23327fcd
import
{
LokiExpression
}
from
'./types'
;
const
selectorRegexp
=
/
(?:
^|
\s)
{
[^
{
]
*}/g
;
const
caseInsensitive
=
'(?i)'
;
// Golang mode modifier for Loki, doesn't work in JavaScript
export
function
parseQuery
(
input
:
string
):
LokiExpression
{
input
=
input
||
''
;
const
match
=
input
.
match
(
selectorRegexp
);
...
...
@@ -9,13 +8,11 @@ export function parseQuery(input: string): LokiExpression {
let
regexp
=
''
;
if
(
match
)
{
// Regexp result is ignored on the server side
regexp
=
input
.
replace
(
selectorRegexp
,
''
).
trim
();
// Keep old-style regexp, otherwise take whole query
if
(
regexp
&&
regexp
.
search
(
/
\|
=|
\|
~|!=|!~/
)
===
-
1
)
{
query
=
match
[
0
].
trim
();
if
(
!
regexp
.
startsWith
(
caseInsensitive
))
{
regexp
=
`
${
caseInsensitive
}${
regexp
}
`
;
}
}
else
{
regexp
=
''
;
}
...
...
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