Skip to content

Commit 5fc4129

Browse files
authored
Reuse the same builder instance in relabel.process() (#4578)
1 parent 1b76368 commit 5fc4129

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/component/loki/relabel/relabel.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type Component struct {
7474
maxCacheSize int
7575

7676
debugDataPublisher livedebugging.DebugDataPublisher
77+
78+
builder labels.ScratchBuilder
7779
}
7880

7981
var (
@@ -99,6 +101,7 @@ func New(o component.Options, args Arguments) (*Component, error) {
99101
cache: cache,
100102
maxCacheSize: args.MaxCacheSize,
101103
debugDataPublisher: debugDataPublisher.(livedebugging.DebugDataPublisher),
104+
builder: labels.NewScratchBuilder(0),
102105
}
103106

104107
// Create and immediately export the receiver which remains the same for
@@ -239,12 +242,12 @@ func (c *Component) relabel(e loki.Entry) model.LabelSet {
239242
}
240243

241244
func (c *Component) process(e loki.Entry) model.LabelSet {
242-
builder := labels.NewScratchBuilder(len(e.Labels))
245+
c.builder.Reset()
243246
for k, v := range e.Labels {
244-
builder.Add(string(k), string(v))
247+
c.builder.Add(string(k), string(v))
245248
}
246-
builder.Sort()
247-
lbls := builder.Labels()
249+
c.builder.Sort()
250+
lbls := c.builder.Labels()
248251
lbls, _ = relabel.Process(lbls, c.rcs...)
249252

250253
relabeled := make(model.LabelSet, lbls.Len())

0 commit comments

Comments
 (0)