Merging based on field name

Hi,
I’d like to visualize different stats of pods in Deployments and StatefulSets in my Kubernetes cluster, but group by pod-name-prefix. I am aware that I could assign labels to my pods and then use a solution like outlined here. For the sake of understanding Grafana better, I would still like to know if there is a solution to this particular problem. What I tried and failed to do is rename the pod names with the regex field rename transformation to remove the random stuff at the end, and then somehow merge the fields with the same name. Even if this is not the most elegant way to do this, I would like to know if this is possible at all.
As an example, I have attached a screenshot of a plot showing the pod restarts. Here you can see multiple grafana-k8s-monitoring-alloy pods and I would like to merge those into one plot line. I am aware that this will only work for Deployments and StatefulSets with 1 replica.
Thanks a lot!
Alexander

  • What Grafana version and what operating system are you using?

    • Grafana v11.3.0-75420 (d1dc595692) in Grafana Cloud
  • What are you trying to achieve?

    • Regex-rename fields, then merge fields with the same name.
  • How are you trying to achieve it?

    • Ideally via some transformation.
  • What happened?

    • I do not know which transformation to use. Multiple fields with the same name are shown in my visualization.
  • What did you expect to happen?

    • A transformation exists that merges fields with the same name, so I get one continuous time series for each unique field name.

Hi,

Unfortunately, even if you would succeed in changing the series names by regex (I’m not regex expert, but something like (.*)-(.*)-(.*) would suffice IMO - worked for me). There won’t be any automagical merging of the series (I also couldn’t do that).

But it might not be necessary. I guess that your datasource is Prometheus or something prometheus-compatible (at least looks like it). If so, take a look at label replace function in PromQL. With that you could create a new label (let’s say deployment or something like this) and then aggregate your query with grouping by the deployment label. Would that work for you? (Tip: if you’re by any chance using VictoriaMetrics, there are also other label transforming functions you could use).

1 Like

Thanks @dawiddebowski!
That indeed did the trick. I have attached a screenshot for anyone looking for something like this in the future.
Alexander

1 Like