Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support label_replace() on range vectors? #2671

Closed
juliusv opened this Issue May 1, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@juliusv
Copy link
Member

juliusv commented May 1, 2017

Sometimes you might want to do something like rate({__name__=~".*_total"}[1m]), but since this would lose the metric name, you might want to copy the metric name into a normal label as the very first step. Currently this is not possible with label_replace() for any functions that expect a range vector, as label_replace() only supports relabeling an instant vector.

While you can do:

label_replace({__name__=~".*_total"}, "metricname", "$1", "__name__", "(.*)")

...the following is currently illegal:

label_replace({__name__=~".*_total"}[1m], "metricname", "$1", "__name__", "(.*)")

But you would need this if you wanted to pass the result into a function that requires a range vector, as you can't specify a range selector ([1m]) after arbitrary expressions, only basic series selectors.

It's unclear to me though whether we want functions to take varying argument types, or how we would solve that if not.

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented May 1, 2017

I'm against having a function of this nature.

It's expected that you know your metric names, and all uses cases we've seen for this so far were where the user had encoded a label value into the metric name. I don't think we should be adding features to work around bad data modelling - particularly as we already have metric relabelling.

I'm against functions' return types and semantics varying depending on the type of input arguments, that's just going to cause confusion.

Finally we currently have no functions that return range vectors. I'd like to keep things that way, particularly as I expect that'll mess up optimisations that LTSes will be doing.

@juliusv

This comment has been minimized.

Copy link
Member Author

juliusv commented May 1, 2017

Ok, agreed for now - let's see if a more urgent need for this comes up ever again. Closing for now.

@fortman

This comment has been minimized.

Copy link

fortman commented Oct 11, 2017

So the use case still exists where you want to change the value of a label, having nothing to do with a metric name. Our use case:

We are using cadvisor to pull in docker statistics. We are showing the image name in a grafana dashboard. The problem is our docker image names are fully qualified so they are on the long side and hard to read in grafana. The naming convention is outside my control, so when I found the label_replace function I got really excited. The following worked:

label_replace(container_cpu_user_seconds_total_counter{image!=""}, "image", "$1", "image", "./(.)")

However our grafana dashboard requires a ranged vector(because we are doing an irate), and the the following does not work

label_replace(container_cpu_user_seconds_total_counter{image!=""}[1m], "image", "$1", "image", "./(.)")
Error executing query: parse error at char 106: expected type instant vector in call to function "label_replace", got range vector

Was excited, but now I get to live with unreadable grafana dashboards and management on my .... well you know.

@fortman

This comment has been minimized.

Copy link

fortman commented Oct 11, 2017

n/m, wrapping the label_replace around the irate seems to work. Might still be useful, but I worked around it.

@wentwog

This comment has been minimized.

Copy link

wentwog commented Mar 4, 2018

I have such use-case: I have metrics like "command1_countRejected", "command2_countRejected", ...
For each command type, I want to see the maximum number of that command executions rejected within the last 30m, and draw it all as a rolling graph. I.e. use a query like
max( max_over_time({__name__=~".*countRejected"}[30m]) ) by (__name__)
to get this graph
But since __name__ is lost at {__name__=~".*countRejected"}[30m] step, I can't get stats per each command, only cumulatively.

@deeTEEcee

This comment has been minimized.

Copy link

deeTEEcee commented Nov 21, 2018

working with rabbitmq + kubernetes and a specific queue, the pod names are switching. I'd like to use avg_over_time with a certain time period but that leads to a result dependent on how many times the pod switched, so id like to ignore that pod name somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.