[REFACTOR] Relabel: Remove unnecessary Process() function

All uses can be replaced by ProcessBuilder, which is more efficient.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2025-11-13 18:31:54 +00:00
parent 3155c95c1f
commit 258fcbda6b
2 changed files with 8 additions and 19 deletions

View file

@ -269,22 +269,8 @@ func (re Regexp) String() string {
return str[5 : len(str)-2]
}
// Process returns a relabeled version of the given label set. The relabel configurations
// are applied in order of input.
// There are circumstances where Process will modify the input label.
// If you want to avoid issues with the input label set being modified, at the cost of
// higher memory usage, you can use lbls.Copy().
// If a label set is dropped, EmptyLabels and false is returned.
func Process(lbls labels.Labels, cfgs ...*Config) (ret labels.Labels, keep bool) {
lb := labels.NewBuilder(lbls)
if !ProcessBuilder(lb, cfgs...) {
return labels.EmptyLabels(), false
}
return lb.Labels(), true
}
// ProcessBuilder is like Process, but the caller passes a labels.Builder
// containing the initial set of labels, which is mutated by the rules.
// ProcessBuilder applies relabeling configurations (rules) to the labels in lb.
// The rules are applied in order of input. Returns false if the rule says to drop.
func ProcessBuilder(lb *labels.Builder, cfgs ...*Config) (keep bool) {
for _, cfg := range cfgs {
keep = relabel(cfg, lb)

View file

@ -751,10 +751,11 @@ func TestRelabel(t *testing.T) {
require.NoError(t, cfg.Validate(model.UTF8Validation))
}
res, keep := Process(test.input, test.relabel...)
lb := labels.NewBuilder(test.input)
keep := ProcessBuilder(lb, test.relabel...)
require.Equal(t, !test.drop, keep)
if keep {
testutil.RequireEqual(t, test.output, res)
testutil.RequireEqual(t, test.output, lb.Labels())
}
}
}
@ -1064,9 +1065,11 @@ func BenchmarkRelabel(b *testing.B) {
require.NoError(b, err)
}
for _, tt := range tests {
lb := labels.NewBuilder(labels.EmptyLabels())
b.Run(tt.name, func(b *testing.B) {
for b.Loop() {
_, _ = Process(tt.lbls, tt.cfgs...)
lb.Reset(tt.lbls)
_ = ProcessBuilder(lb, tt.cfgs...)
}
})
}