Turn one source label into multiple target labels
#12,896 opened on Sep 27, 2023
Description
Proposal
Hey
So, we have the usecase that we have one central prometheus instance and developers do not have access to the prometheus configuration. We are scraping consul for our metrics targets. While applications can provide their own labels, there is also certain data that the application doesn't know of, for example its (dynamic) id in our deployment system. What we'd like to be able to do, is to have some generic consul tag where can extract promtheus labels from.
For example with this config:
- source_labels: [__meta_consul_tags]
regex: "(?:^|.*?,)prom_label__(.+?)=(.+?)(?:$|,.*?)"
action: replace
target_label: $1
replacement: $2
Given these consul tags:
a=b,b=c,prom_label__f=g,t=e,prom_label__z=l,l=o
I'd expect these labels in prometheus for the given target:
f=g,z=l
The workaround would be to manually list the labels for all services, which could be quite a lot.
I've already looked at the code and guess that we can easily change the regex code to use multiple matches instead of just one set of submatches. Adjusting the tests is an easy feat as well. This should imo not be a breaking change.