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
https://github.com/google/re2/wiki/Syntax

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


On Tuesday, 14 June 2022 at 18:38:55 UTC+2 [email protected] wrote:

> Wonder if I can get some help.  We are seeing an oddity here.  Within my 
> configuration, we are using kubernetes_sd_configs and I have the following 
> in the relabel section of my scrape config:
>
> - source_labels: [__meta_kubernetes_namespace] 
>   separator: ; 
>   regex: (^mykub-test--[^-]*) 
>   target_label: kubernetes_customer_env_name 
>   replacement: $1 
>   action: replace
>
> This works fine if the namespace is just mykub-test--herenow  but not for 
> namespaces like mykub-test--anothertest2--test123 .  Basically, I want to 
> strip off the "--test123" (or ignore it) in the later example.  Any 
> suggestions? 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/ebec1e70-d9d3-415d-970d-44bed596e9a9n%40googlegroups.com.

Reply via email to