Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func applyRelabelConfigs(labels model.LabelSet) model.LabelSet {
}

// Sort labels as required by Process
builder.Sort()
promLabels := builder.Labels()

// Apply relabeling
Expand Down
19 changes: 19 additions & 0 deletions pkg/relabel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"testing"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -127,3 +128,21 @@ func TestParseRelabelConfigs(t *testing.T) {
})
}
}

// Process input is built by ranging a Go map, whose order is randomized.
// Without builder.Sort() the source_labels lookup intermittently misses and
// the rule silently no-ops.
func TestApplyRelabelConfigsSortsLabels(t *testing.T) {
var err error
relabelConfigs, err = parseRelabelConfigs(
`[{"source_labels":["_tst"],"regex":"^/svc/(.+)$","target_label":"out"}]`)
require.NoError(t, err)
t.Cleanup(func() { relabelConfigs = nil })

in := model.LabelSet{"_tst": "/svc/foo", "a": "1", "b": "2"}

for i := 0; i < 100; i++ {
require.Equal(t, model.LabelValue("foo"),
applyRelabelConfigs(in)["out"], "iteration %d", i)
}
}