I am trying to relabel metrics like this, with an
app label that is coming from our cAdvisor exporter. I've removed unrelated labels for clarity:
container_cpu_system_seconds_total{container_label_marathon_app_id="active/prod/general"}
I'd like to write out a service label by taking the container_label_marathon_app_id label up until the first slash. So in the above example, service should be active,.
Here is the relabel config that I have. We first use the marathon_sd_configs to keep only the cAdvisor marathon app, and then apply the relabel:
- source_labels: ['__meta_marathon_app']
regex: (/cadvisor)
action: keep
- source_labels: [container_label_marathon_app_id]
regex: ([^/]+).*
target_label: service
I've read a bunch about regexes in Prometheus, along with how they are anchored, so my understanding is that this regex is turned into this under the hood:
^(?:([^/]+)).*$
That matches when I've tested the regex outside Prometheus. Additionally, if I query for metrics with the regex from my relabel, I find my expected time series:
container_cpu_system_seconds_total{container_label_marathon_app_id=~"([^/]+).*"}
Totally confused as to why the relabel action is not occurring.
I'm running Prometheus 2.0, if that helps. I can also share expanded parts of my config file if that is helpful.