It's not clear what your requirements are. Is it possible that values after the double-dash might themselves contain a single dash, like
mykub-test--another-test--test-123
and if so, what should happen?
Could there be additional double-dash separated sections like
mykub-test--anothertest--test123--test456
and if so, what should happen?
If you want mykub-test--a-a--b-b--c-c to become mykub-test--a-a, then you could try this (untested):
- source_labels: [__meta_kubernetes_namespace]
regex: (mykub-test--.*?)(--.*)?
target_label: kubernetes_customer_env_name
replacement: $1
action: replace
.*? applies the "non-greedy" modifier to make the first .* match the smallest possible number of times, whereas (xxx)? means match the subexpression zero or one times. For more info see
If you need to do more complex multi-step processing then you can use temporary labels. Names starting __tmp_ are reserved for this purpose (i.e. are guaranteed not to clash with other prometheus-internal labels).
The following will split the label into two, on the first instance of "--" which appears in the string, requiring at least one instance to occur:
- source_labels: [__meta_kubernetes_namespace]
regex: (.*?)--(.*)
target_label: __tmp_nsprefix
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_namespace]
regex: (.*?)--(.*)
target_label: __tmp_nssuffix
replacement: $2
action: replace