Drop labels of a metric not entire job

46 views
Skip to first unread message

Fynn Dröges

unread,
Nov 20, 2024, 7:42:31 AM11/20/24
to Prometheus Users

I am new to Prometheus and relabeling. I am working with a job 'A' which has a lot of metrics and one of these metrics 'B' has 150 labels. Of these 150 labels I only want to keep 3 (D,E,F) and drop the rest. But I want to make sure that my relabeling rule only affects this one metric series 'B' and not the entire job.

How can I achieve this?

I tried drop and labeldrop but they affect the whole series or job.

Brian Candler

unread,
Nov 20, 2024, 4:28:22 PM11/20/24
to Prometheus Users
Checking in the source code:

        if c.Action == LabelDrop || c.Action == LabelKeep {
                if c.SourceLabels != nil ||
                        c.TargetLabel != DefaultRelabelConfig.TargetLabel ||
                        c.Modulus != DefaultRelabelConfig.Modulus ||
                        c.Separator != DefaultRelabelConfig.Separator ||
                        c.Replacement != DefaultRelabelConfig.Replacement {
                        return fmt.Errorf("%s action requires only 'regex', and no other fields", c.Action)
                }
        }

AFAICS, there's no way that labelkeep or labeldrop can be made conditional on the metric name.

I *think* it should be possible to drop a label by replacing its value with empty string, in which case:

- source_labels: [__name__]
  regex: B
  target_label: junk_label
  replacement: ""

But you'll have to do that 147 times.

In any case, I would question:

1. Why do you want to drop the labels? Presumably these are static (otherwise you'd have an explosion in time series), in which case, the overhead is very small and you're going to save almost no storage by removing them.

2. If these labels are superfluous, why are they being generated in the first place? Can you fix the exporter?
Reply all
Reply to author
Forward
0 new messages