mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 22:37:27 -08:00
Merge pull request #6350 from geobeau/fix-exported-relabel
Fix relabaling collision when using exported labels
This commit is contained in:
commit
bd1c66861a
|
@ -451,9 +451,9 @@ func mutateSampleLabels(lset labels.Labels, target *Target, honor bool, rc []*re
|
|||
for _, l := range target.Labels() {
|
||||
// existingValue will be empty if l.Name doesn't exist.
|
||||
existingValue := lset.Get(l.Name)
|
||||
// Because setting a label with an empty value is a no-op,
|
||||
// this will only create the prefixed label if necessary.
|
||||
lb.Set(model.ExportedLabelPrefix+l.Name, existingValue)
|
||||
if existingValue != "" {
|
||||
lb.Set(model.ExportedLabelPrefix+l.Name, existingValue)
|
||||
}
|
||||
// It is now safe to set the target label.
|
||||
lb.Set(l.Name, l.Value)
|
||||
}
|
||||
|
|
|
@ -935,6 +935,15 @@ func TestScrapeLoopAppend(t *testing.T) {
|
|||
discoveryLabels: []string{"n", "2"},
|
||||
expLset: labels.FromStrings("__name__", "metric", "exported_n", "1", "n", "2"),
|
||||
expValue: 0,
|
||||
}, {
|
||||
// When "honor_labels" is not set
|
||||
// exported label from discovery don't get overwritten
|
||||
title: "Label name collision",
|
||||
honorLabels: false,
|
||||
scrapeLabels: `metric 0`,
|
||||
discoveryLabels: []string{"n", "2", "exported_n", "2"},
|
||||
expLset: labels.FromStrings("__name__", "metric", "n", "2", "exported_n", "2"),
|
||||
expValue: 0,
|
||||
}, {
|
||||
// Labels with no value need to be removed as these should not be ingested.
|
||||
title: "Delete Empty labels",
|
||||
|
|
Loading…
Reference in a new issue