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
fe1c204d
Unverified
Commit
fe1c204d
authored
Mar 05, 2019
by
Daniel Lee
Committed by
GitHub
Mar 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15290 from mtanda/prometheus_label_names_query
(prometheus) support /api/v1/labels
parents
744bf6a7
d46bf752
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
0 deletions
+52
-0
docs/sources/features/datasources/prometheus.md
+1
-0
public/app/plugins/datasource/prometheus/datasource.ts
+18
-0
public/app/plugins/datasource/prometheus/metric_find_query.ts
+15
-0
public/app/plugins/datasource/prometheus/specs/metric_find_query.test.ts
+18
-0
No files found.
docs/sources/features/datasources/prometheus.md
View file @
fe1c204d
...
...
@@ -68,6 +68,7 @@ provides the following functions you can use in the `Query` input field.
Name | Description
---- | --------
*label_names()*
| Returns a list of label names.
*label_values(label)*
| Returns a list of label values for the
`label`
in every metric.
*label_values(metric, label)*
| Returns a list of label values for the
`label`
in the specified metric.
*metrics(metric)*
| Returns a list of metrics matching the specified
`metric`
regex.
...
...
public/app/plugins/datasource/prometheus/datasource.ts
View file @
fe1c204d
...
...
@@ -379,6 +379,24 @@ export class PrometheusDatasource implements DataSourceApi<PromQuery> {
});
}
getTagKeys
(
options
)
{
const
url
=
'/api/v1/labels'
;
return
this
.
metadataRequest
(
url
).
then
(
result
=>
{
return
_
.
map
(
result
.
data
.
data
,
value
=>
{
return
{
text
:
value
};
});
});
}
getTagValues
(
options
)
{
const
url
=
'/api/v1/label/'
+
options
.
key
+
'/values'
;
return
this
.
metadataRequest
(
url
).
then
(
result
=>
{
return
_
.
map
(
result
.
data
.
data
,
value
=>
{
return
{
text
:
value
};
});
});
}
testDatasource
()
{
const
now
=
new
Date
().
getTime
();
return
this
.
performInstantQuery
({
expr
:
'1+1'
},
now
/
1000
).
then
(
response
=>
{
...
...
public/app/plugins/datasource/prometheus/metric_find_query.ts
View file @
fe1c204d
...
...
@@ -12,10 +12,16 @@ export default class PrometheusMetricFindQuery {
}
process
()
{
const
labelNamesRegex
=
/^label_names
\(\)\s
*$/
;
const
labelValuesRegex
=
/^label_values
\((?:(
.+
)
,
\s
*
)?([
a-zA-Z_
][
a-zA-Z0-9_
]
*
)\)\s
*$/
;
const
metricNamesRegex
=
/^metrics
\((
.+
)\)\s
*$/
;
const
queryResultRegex
=
/^query_result
\((
.+
)\)\s
*$/
;
const
labelNamesQuery
=
this
.
query
.
match
(
labelNamesRegex
);
if
(
labelNamesQuery
)
{
return
this
.
labelNamesQuery
();
}
const
labelValuesQuery
=
this
.
query
.
match
(
labelValuesRegex
);
if
(
labelValuesQuery
)
{
if
(
labelValuesQuery
[
1
])
{
...
...
@@ -39,6 +45,15 @@ export default class PrometheusMetricFindQuery {
return
this
.
metricNameAndLabelsQuery
(
this
.
query
);
}
labelNamesQuery
()
{
const
url
=
'/api/v1/labels'
;
return
this
.
datasource
.
metadataRequest
(
url
).
then
(
result
=>
{
return
_
.
map
(
result
.
data
.
data
,
value
=>
{
return
{
text
:
value
};
});
});
}
labelValuesQuery
(
label
,
metric
)
{
let
url
;
...
...
public/app/plugins/datasource/prometheus/specs/metric_find_query.test.ts
View file @
fe1c204d
...
...
@@ -42,6 +42,24 @@ describe('PrometheusMetricFindQuery', () => {
});
describe
(
'When performing metricFindQuery'
,
()
=>
{
it
(
'label_names() should generate label name search query'
,
async
()
=>
{
const
query
=
ctx
.
setupMetricFindQuery
({
query
:
'label_names()'
,
response
:
{
data
:
[
'name1'
,
'name2'
,
'name3'
],
},
});
const
results
=
await
query
.
process
();
expect
(
results
).
toHaveLength
(
3
);
expect
(
ctx
.
backendSrvMock
.
datasourceRequest
).
toHaveBeenCalledTimes
(
1
);
expect
(
ctx
.
backendSrvMock
.
datasourceRequest
).
toHaveBeenCalledWith
({
method
:
'GET'
,
url
:
'proxied/api/v1/labels'
,
silent
:
true
,
});
});
it
(
'label_values(resource) should generate label search query'
,
async
()
=>
{
const
query
=
ctx
.
setupMetricFindQuery
({
query
:
'label_values(resource)'
,
...
...
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