In Grafana I have some Prometheus metrics about containers. I want to display information about them by image version. That isn't a dimension that is reported by my data source, so instead I can run this query to get the results I want:
avg by (image_repository,image_tag,severity) (my_metric{namespace="$namespace"})
This gives me:
| image_repository | image_tag | my_metric |
| ---------------- | ------------- | --------- |
| foo/bar | 1.2 | 53 |
| foo/baz | 1.4 | 12 |
Then I can concatenate the results with the add field from calculation' transformation operation to make a new field, image_version, from doing an addition operation on image_repository and image_tag:
| image_version | my_metric |
| ------------- | --------- |
| foo/bar1.2 | 53 |
| foo/baz1.4 | 12 |
This does the basic job...
But I'd prefer to have some kind of delimiter between those two fields, so instead of foo/bar1.2
I'd have foo/bar:1.2
. Is such a thing possible?
I think you can also derive new fields in Promql, so maybe that's the place to do this instead of Grafana? I'm not very familiar with either toolkit, guidance very welcome.
Use Prometheus' label_join
instead of Grafana's transformation.
label_join(
avg by (image_repository,image_tag,severity) (my_metric{namespace="$namespace"}),
"image_version",":","image_repository","image_tag")
Should return what you want.
Demo of similar query online here.