Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Full Prometheus query support in label_values function #12715

Closed
mttradebyte opened this issue Jul 25, 2018 · 2 comments
Closed

Full Prometheus query support in label_values function #12715

mttradebyte opened this issue Jul 25, 2018 · 2 comments

Comments

@mttradebyte
Copy link

mttradebyte commented Jul 25, 2018

Please include this information:

What Grafana version are you using?

5.2.1

What datasource are you using?

MariaDB

What OS are you running grafana on?

CentOS 7.4

What did you do?

Attempted to use a valid Prometheus query as the first argument to the label_values function

What was the expected result?

Correct population of variable.

What happened instead?

Received the following error:
Template variables could not be initialized: parse error at char 1: vector selector must contain label matchers or metric name

I asked this question on the community page a week ago but didn't get a response. You can see this here: https://community.grafana.com/t/full-query-support-when-creating-variable/8906.

As stated in the ticket, I don't understand why I can't use a full and proper query as the first argument to label_values. Both the first and second example in the ticket should theoretically produce identical output, and this would be really handy.

@marefr
Copy link
Contributor

marefr commented Jul 25, 2018

Github is mainly for features and bug reports, but as you've already created a topic on the community site I'll answer here.

The label_values function is something specific for Grafana (not prometheus) and we have no plans at the moment to extend that to support full queries.

Use the query_result(query) instead and extract the values using regex. We recently merged #12597 which will be released in Grafana v5.3. I think that may be the missing point which enables you to do for example:

This variable returns the busiest 5 request instances based on average QPS over the time range shown in the dashboard.

Query: query_result(topk(5, sum(rate(http_requests_total[$__range])) by (instance))) 
Regexp: /"([^"]+)"/

Make sure to set the variable's refresh trigger to be On Time Range Change to get the correct instances when changing the time range on the dashboard.

@marefr marefr closed this as completed Jul 25, 2018
@marefr
Copy link
Contributor

marefr commented Jul 25, 2018

Duplicate of #11047

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants