That's correct. The "replacement" for the *labelmap* action is the new label *name*, and it defaults to $1
target_label is used for the *replace* action, and for that action the "replacement" is the *value* of the new label being created. On Friday, 1 October 2021 at 04:59:56 UTC+1 [email protected] wrote: > Great question wheresh. I had the exact same question too. And I was > extremely confused. > > I think (please someone correct me if I'm wrong) that the action > *labelmap* actually creates a new set of labels, instead of relabeling > the labels: > > * > > https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config > > <https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config>* > * "labelmap: Match regex against all label names. Then copy the values > of the matching labels to label names given by replacement..."* > > Also, I think that *labelmap* is not a replace action because all replace > actions require a target_label: > > * > > https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config > > <https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config>* > * # Label to which the resulting value is written in a replace > action. * > * # It is mandatory for replace actions. Regex capture groups are > available. * > * [ target_label: <labelname> ]* > > So I think it just creates a new set of labels. > The default replacement is $1, and in the example what is being captured > in "regex: __meta_kubernetes_service_label_(.+)" is the very last part. > So this is what I think is happening: > > *Labels that were matched > New Labels* > _meta_kubernetes_service_label_somelabel1 -> somelabel1 > _meta_kubernetes_service_label_somelabel2 -> somelabel2 > _meta_kubernetes_service_label_somelabel3 -> somelabel3 > _meta_kubernetes_service_label_somelabel4 -> somelabel4 > _meta_kubernetes_service_label_somelabel5 -> somelabel5 > > Someone please either confirm that this is what is happening, or provide > an explanation of what is actually happening. > > Thank you! > > On Tuesday, January 9, 2018 at 10:49:14 PM UTC-8 [email protected] > wrote: > >> hi, I check the demo yml file and found this : >> >> - action: labelmap regex: __meta_kubernetes_service_label_(.+) - >>> source_labels: [__meta_kubernetes_namespace] action: replace target_label: >>> kubernetes_namespace >> >> seems no target_label to replace in the action labelmap . >> then what happens to it ? >> >> 在 2017年5月3日星期三 UTC+8上午7:16:51,Julius Volz写道: >>> >>> "labelmap" maps a whole set of labels (that match a regex) over to the >>> target labels. That's typically useful if you want to copy over a whole set >>> of labels (like all starting with "__meta_kubernetes_service_label_") to >>> the target's labels. For example: >>> https://github.com/prometheus/prometheus/blob/86426c05669417cf1012fbc3a40fb7e0f5a8a101/documentation/examples/prometheus-kubernetes.yml#L113-L114 >>> >>> "replace" does a replacement of a single label only (possibly from >>> multiple source labels). Thus you can't use "replace" to copy over an >>> arbitrary number of labels (of which you possibly don't know all exact >>> names), but only one per relabeling rule. >>> >> On Wed, May 3, 2017 at 12:57 AM, Cemalettin Koc <[email protected]> >>> wrote: >>> >> I have some confusion regarding labelmap and replace usage in scrape >>>> configuration. I think that they can be used for each other. >>>> >>>> 1. What is the difference between them? For which use cases they are >>>> more suitable? >>>> 2. "replace" is using "target_label" whereas "labelmap" is using >>>> "replacement" for targeting. Why is not labelmap using "target_label" as >>>> well? >>>> >>>> Thanks >>>> >>> -- >>>> 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 post to this group, send email to [email protected]. >>> >>> >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/prometheus-users/37905bb7-539c-4f85-9231-2fe4849bde9a%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/prometheus-users/37905bb7-539c-4f85-9231-2fe4849bde9a%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- 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/e35e394f-83bd-40a0-83a8-25bc497cb4ben%40googlegroups.com.

