Extract substrings from prometheus query

We use this prometheus query to extract the installed k8s chart names in our cluster:

sum(label_join(kube_deployment_labels{namespace="mynamspace"}, "mylabel", "", "label_chart", "label_helm_sh_chart") ) by (mylabel)

The results (in mylabel) are looking like that (plus some noise we hide in the table view)

    super-nice-chart-12.34-0
    even-better-chart-2.12.0-32
    notsogood-0.36.0
    another-amazing-thing-0.1.12

We want to show the name and the version in separate colums of a table.
The regex for splitting mylabel is ([a-z-]+)-([0-9.-]*) for name (matching group 1) and version (matching group 2)

    super-nice-chart                    12.34-0
    even-better-chart                   2.12.0-32
    notsogood                           0.36.0
    another-amazing-thing               0.1.12

But I have no idea how to implement this regex into the query or $(which is the right place?)
Any suggestions?

No idea there in the world?

no one has any idea?

hey, did you find a solution to this yet?

To apply regex to the legend(don’t think that’s what you want though), use the transform tab and choose rename by regex(use $1 in the replace field),

Or if it’s not the legend you want to change but a value in a field, add a new value mappings and choose regex there.

But since you want to create 2 fields out of one, I’m not sure how you would go about that. Maybe duplicating your query and messing around with value mappings.

Little late for OP but maybe the new guy will find it useful.

1 Like