Skip to content

Commit

Permalink
only return the map to the pool if we created a new map, not if we
Browse files Browse the repository at this point in the history
returned the base map from the labels builder

Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Jan 8, 2024
1 parent d44061a commit e49a7da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions pkg/logql/log/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ func (lf *LineFormatter) Process(ts int64, line []byte, lbs *LabelsBuilder) ([]b
lf.currentTs = ts

// map now is taking from a pool
m := lbs.Map()
defer smp.Put(m)
m, ret := lbs.Map()
defer func() {
if ret { // if we return the base map from the labels builder we should not put it back in the pool
smp.Put(m)
}
}()
if err := lf.Template.Execute(lf.buf, m); err != nil {
lbs.SetErr(errTemplateFormat)
lbs.SetErrorDetails(err.Error())
Expand Down
6 changes: 3 additions & 3 deletions pkg/logql/log/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,12 @@ func (b *LabelsBuilder) IntoMap(m map[string]string) {
}
}

func (b *LabelsBuilder) Map() map[string]string {
func (b *LabelsBuilder) Map() (map[string]string, bool) {
if !b.hasDel() && !b.hasAdd() && !b.HasErr() {
if b.baseMap == nil {
b.baseMap = b.base.Map()
}
return b.baseMap
return b.baseMap, false
}
b.buf = b.UnsortedLabels(b.buf)
// todo should we also cache maps since limited by the result ?
Expand All @@ -509,7 +509,7 @@ func (b *LabelsBuilder) Map() map[string]string {
for _, l := range b.buf {
res[l.Name] = l.Value
}
return res
return res, true
}

// LabelsResult returns the LabelsResult from the builder.
Expand Down

0 comments on commit e49a7da

Please sign in to comment.