Formatting legend

We have promql expressions like this on virtually all our graphs :frowning:

label_replace(x, "instance", "$1", "instance", "([^.]+).*")

We do this so we can have the hostname in the legend without the fqdn and port appearing which is entirely redundant for these metrics since they’re always coming from the same service within a cluster.

It really clutters up our promql metrics and make it a real pain to copy the metrics around. It seems like it this is really a display formatting issue and would be better handled in the legend format string, something like:

{{instance|reReplaceAll('\..*$','')}}

Better yet would be to be able to define this as a common expression in the dashboard config and then just use host as if it was a label without having to put this on every legend field.

Is anything like this possible today or is this a feature request?

I couldn’t find this before but just now I found a bug PR on this topic:

It was closed because of inactivity but it did have a lot of people asking for it and even the person closing it said he thought it was a good idea. I’m not clear why the PR wasn’t merged.

@gsstark we plan to introduce a transform for regex renames. You can follow this issue for progress.

I am running into the same issue. Did you put the whole expression (label_replace(x, “instance”, “$1”, “instance”, “([^.]+).*”)) in the legend field? or is this used in the expression field where x is you metric query?