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
9c316b55
Commit
9c316b55
authored
Nov 28, 2018
by
David Kaltschmidt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logging: fix query parsing for selectors with multiple labels
- simplify selector parsing - added tests
parent
32511533
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
16 deletions
+12
-16
public/app/plugins/datasource/logging/datasource.test.ts
+7
-0
public/app/plugins/datasource/logging/datasource.ts
+5
-16
No files found.
public/app/plugins/datasource/logging/datasource.test.ts
View file @
9c316b55
...
...
@@ -35,4 +35,11 @@ describe('parseQuery', () => {
regexp
:
'x|y'
,
});
});
it
(
'returns query for selector with two labels'
,
()
=>
{
expect
(
parseQuery
(
'{foo="bar", baz="42"}'
)).
toEqual
({
query
:
'{foo="bar", baz="42"}'
,
regexp
:
''
,
});
});
});
public/app/plugins/datasource/logging/datasource.ts
View file @
9c316b55
...
...
@@ -16,26 +16,15 @@ const DEFAULT_QUERY_PARAMS = {
query
:
''
,
};
const
QUERY_REGEXP
=
/
(
{
\w
+="
[^
"
]
+"}
)?\s
*
(\w[^
{
]
+
)?\s
*
(
{
\w
+="
[^
"
]
+"}
)?
/
;
const
selectorRegexp
=
/{
[^
{
]
*}/g
;
export
function
parseQuery
(
input
:
string
)
{
const
match
=
input
.
match
(
QUERY_REGEXP
);
const
match
=
input
.
match
(
selectorRegexp
);
let
query
=
''
;
let
regexp
=
''
;
let
regexp
=
input
;
if
(
match
)
{
if
(
match
[
1
])
{
query
=
match
[
1
];
}
if
(
match
[
2
])
{
regexp
=
match
[
2
].
trim
();
}
if
(
match
[
3
])
{
if
(
match
[
1
])
{
query
=
`
${
match
[
1
].
slice
(
0
,
-
1
)}
,
${
match
[
3
].
slice
(
1
)}
`
;
}
else
{
query
=
match
[
3
];
}
}
query
=
match
[
0
];
regexp
=
input
.
replace
(
selectorRegexp
,
''
).
trim
();
}
return
{
query
,
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