Skip to content

Commit

Permalink
use strings.Map instead of bytes.Map and add additional benchmark case
Browse files Browse the repository at this point in the history
Signed-off-by: Callum Styan <[email protected]>
  • Loading branch information
cstyan committed Nov 26, 2024
1 parent 53927f1 commit da0dd5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 1 addition & 2 deletions pkg/logql/log/pipeline.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package log

import (
"bytes"
"context"
"strings"
"sync"
Expand Down Expand Up @@ -231,7 +230,7 @@ func (p *streamPipeline) Process(ts int64, line []byte, structuredMetadata ...la
for i, lb := range structuredMetadata {
structuredMetadata[i].Name = prometheus.NormalizeLabel(lb.Name)
if strings.ContainsRune(structuredMetadata[i].Value, utf8.RuneError) {
structuredMetadata[i].Value = string(bytes.Map(removeInvalidUtf, []byte(structuredMetadata[i].Value)))
structuredMetadata[i].Value = strings.Map(removeInvalidUtf, structuredMetadata[i].Value)
}
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/logql/log/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,18 @@ func Benchmark_Pipeline(b *testing.B) {
resLine, resLbs, resMatches = sp.Process(0, line, labels.Label{Name: "valid_name", Value: "foo"})
}
})
b.Run("pipeline string with invalid structured metadata", func(b *testing.B) {
b.Run("pipeline string with invalid structured metadata name", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
resLine, resLbs, resMatches = sp.Process(0, line, labels.Label{Name: "invalid-name", Value: "foo"}, labels.Label{Name: "other-invalid-name", Value: "foo"})
}
})
b.Run("pipeline string with invalid structured metadata value", func(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
resLine, resLbs, resMatches = sp.Process(0, line, labels.Label{Name: "valid_name", Value: "foo"}, labels.Label{Name: "valid_name_2", Value: "foo�"})
}
})

extractor, err := NewLineSampleExtractor(CountExtractor, stages, []string{"cluster", "level"}, false, false)
require.NoError(b, err)
Expand Down

0 comments on commit da0dd5f

Please sign in to comment.