Skip to content

Commit

Permalink
fix basemap usage for IntoMap as well
Browse files Browse the repository at this point in the history
Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Jan 5, 2024
1 parent ffb171a commit 6a63bf8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/logql/log/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ func (lf *LineFormatter) Process(ts int64, line []byte, lbs *LabelsBuilder) ([]b
lf.currentLine = line
lf.currentTs = ts

// map now is taking from a pool
m := lbs.Map()
m := smp.Get()
lbs.IntoMap(m)
defer smp.Put(m)
if err := lf.Template.Execute(lf.buf, m); err != nil {
lbs.SetErr(errTemplateFormat)
Expand Down
4 changes: 0 additions & 4 deletions pkg/logql/log/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,8 +948,4 @@ func TestMapPool(t *testing.T) {
}
wg.Done()
time.Sleep(2 * time.Second)

//require.Equal(t, tt.want, newMustLineFormatter(tt.fmt).RequiredLabelNames())
//})
//}
}
6 changes: 6 additions & 0 deletions pkg/logql/log/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,17 @@ var smp = newStringMapPool()
// properly clear the map if it is going to be reused
func (b *LabelsBuilder) IntoMap(m map[string]string) {
if !b.hasDel() && !b.hasAdd() && !b.HasErr() {
b.mapLock.RLock()
if b.baseMap == nil {
b.mapLock.RUnlock()
b.mapLock.Lock()
b.baseMap = b.base.Map()
b.mapLock.Unlock()
for k, v := range b.baseMap {
m[k] = v
}
} else {
b.mapLock.RUnlock()
}
return
}
Expand Down

0 comments on commit 6a63bf8

Please sign in to comment.