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
c1164f5c
Unverified
Commit
c1164f5c
authored
Oct 09, 2018
by
David
Committed by
GitHub
Oct 09, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13570 from praveensastry/skip-duplicate-labels
Remove duplicate labels in the datasource query
parents
c1fd2e55
61bbe280
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
public/app/plugins/datasource/prometheus/add_label_to_query.ts
+1
-0
public/app/plugins/datasource/prometheus/specs/add_label_to_query.test.ts
+15
-0
No files found.
public/app/plugins/datasource/prometheus/add_label_to_query.ts
View file @
c1164f5c
...
...
@@ -77,6 +77,7 @@ function addLabelToSelector(selector: string, labelKey: string, labelValue: stri
// Sort labels by key and put them together
return
_
.
chain
(
parsedLabels
)
.
uniqWith
(
_
.
isEqual
)
.
compact
()
.
sortBy
(
'key'
)
.
map
(({
key
,
operator
,
value
})
=>
`
${
key
}${
operator
}${
value
}
`
)
...
...
public/app/plugins/datasource/prometheus/specs/add_label_to_query.test.ts
View file @
c1164f5c
...
...
@@ -40,4 +40,19 @@ describe('addLabelToQuery()', () => {
'foo{bar="baz",x="yy"} * metric{a="bb",bar="baz",y="zz"} * metric2{bar="baz"}'
);
});
it
(
'should not add duplicate labels to aquery'
,
()
=>
{
expect
(
addLabelToQuery
(
addLabelToQuery
(
'foo{x="yy"}'
,
'bar'
,
'baz'
,
'!='
),
'bar'
,
'baz'
,
'!='
)).
toBe
(
'foo{bar!="baz",x="yy"}'
);
expect
(
addLabelToQuery
(
addLabelToQuery
(
'rate(metric[1m])'
,
'foo'
,
'bar'
),
'foo'
,
'bar'
)).
toBe
(
'rate(metric{foo="bar"}[1m])'
);
expect
(
addLabelToQuery
(
addLabelToQuery
(
'foo{list="a,b,c"}'
,
'bar'
,
'baz'
),
'bar'
,
'baz'
)).
toBe
(
'foo{bar="baz",list="a,b,c"}'
);
expect
(
addLabelToQuery
(
addLabelToQuery
(
'avg(foo) + sum(xx_yy)'
,
'bar'
,
'baz'
),
'bar'
,
'baz'
)).
toBe
(
'avg(foo{bar="baz"}) + sum(xx_yy{bar="baz"})'
);
});
});
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