chore: Final batch of linting cleanup for Go 1.23 and newer golangci (#14120)

pull/14107/head
Paul Rogers 8 months ago committed by GitHub
parent 93009d4e8c
commit f226b598a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      pkg/kafka/ingester/consumer.go
  2. 2
      pkg/kafka/ingester/partition_reader_test.go
  3. 7
      pkg/logql/log/pipeline.go
  4. 36
      pkg/logql/log/pipeline_test.go
  5. 9
      pkg/logql/sketch/topk.go
  6. 2
      pkg/storage/bloom/v1/builder_test.go
  7. 7
      pkg/storage/chunk/chunk.go

@ -249,7 +249,7 @@ func (c *consumer) flush(ctx context.Context) error {
wal.ReportSegmentStats(stats, c.metrics.segmentMetrics) wal.ReportSegmentStats(stats, c.metrics.segmentMetrics)
id := ulid.MustNew(ulid.Timestamp(time.Now()), rand.Reader).String() id := ulid.MustNew(ulid.Timestamp(time.Now()), rand.Reader).String()
if err := c.storage.PutObject(ctx, fmt.Sprintf(wal.Dir+id), c.flushBuf); err != nil { if err := c.storage.PutObject(ctx, wal.Dir+id, c.flushBuf); err != nil {
return fmt.Errorf("failed to put object to object storage: %w", err) return fmt.Errorf("failed to put object to object storage: %w", err)
} }

@ -56,7 +56,7 @@ func TestPartitionReader_BasicFunctionality(t *testing.T) {
_, kafkaCfg := testkafka.CreateCluster(t, 1, "test-topic") _, kafkaCfg := testkafka.CreateCluster(t, 1, "test-topic")
consumer := newMockConsumer() consumer := newMockConsumer()
consumerFactory := func(committer Committer) (Consumer, error) { consumerFactory := func(_ Committer) (Consumer, error) {
return consumer, nil return consumer, nil
} }

@ -2,7 +2,6 @@ package log
import ( import (
"context" "context"
"reflect"
"sync" "sync"
"unsafe" "unsafe"
@ -383,11 +382,7 @@ func ReduceStages(stages []Stage) Stage {
} }
func unsafeGetBytes(s string) []byte { func unsafeGetBytes(s string) []byte {
var buf []byte return unsafe.Slice(unsafe.StringData(s), len(s))
p := unsafe.Pointer(&buf)
*(*string)(p) = s
(*reflect.SliceHeader)(p).Cap = len(s)
return buf
} }
func unsafeGetString(buf []byte) string { func unsafeGetString(buf []byte) string {

@ -546,6 +546,42 @@ func TestKeepLabelsPipeline(t *testing.T) {
} }
func TestUnsafeGetBytes(t *testing.T) {
tests := []struct {
name string
input string
want []byte
}{
{
name: "empty string",
input: "",
want: nil,
},
{
name: "simple string",
input: "hello",
want: []byte{'h', 'e', 'l', 'l', 'o'},
},
{
name: "string with spaces",
input: "hello world",
want: []byte{'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'},
},
{
name: "string with special characters",
input: "hello\nworld\t!",
want: []byte{'h', 'e', 'l', 'l', 'o', '\n', 'w', 'o', 'r', 'l', 'd', '\t', '!'},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := unsafeGetBytes(tt.input)
require.Equal(t, tt.want, got)
})
}
}
func Benchmark_Pipeline(b *testing.B) { func Benchmark_Pipeline(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()

@ -2,7 +2,6 @@ package sketch
import ( import (
"container/heap" "container/heap"
"reflect"
"sort" "sort"
"unsafe" "unsafe"
@ -210,14 +209,8 @@ func (t *Topk) updateBF(removed, added string) {
} }
} }
// todo: is there a way to save more bytes/allocs via a pool?
func unsafeGetBytes(s string) []byte { func unsafeGetBytes(s string) []byte {
if s == "" { return unsafe.Slice(unsafe.StringData(s), len(s))
return nil // or []byte{}
}
return (*[0x7fff0000]byte)(unsafe.Pointer(
(*reflect.StringHeader)(unsafe.Pointer(&s)).Data),
)[:len(s):len(s)]
} }
// Observe is our sketch event observation function, which is a bit more complex than the original count min sketch + heap TopK // Observe is our sketch event observation function, which is a bit more complex than the original count min sketch + heap TopK

@ -356,7 +356,7 @@ func TestMergeBuilderFingerprintCollision(t *testing.T) {
} }
// We're not testing the ability to extend a bloom in this test // We're not testing the ability to extend a bloom in this test
pop := func(s *Series, _ iter.SizedIterator[*Bloom], _ ChunkRefs, ch chan *BloomCreation) { pop := func(_ *Series, _ iter.SizedIterator[*Bloom], _ ChunkRefs, ch chan *BloomCreation) {
bloom := NewBloom() bloom := NewBloom()
stats := indexingInfo{ stats := indexingInfo{
sourceBytes: int(bloom.Capacity()) / 8, sourceBytes: int(bloom.Capacity()) / 8,

@ -5,7 +5,6 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"hash/crc32" "hash/crc32"
"reflect"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -215,11 +214,7 @@ func readOneHexPart(hex []byte) (part []byte, i int) {
} }
func unsafeGetBytes(s string) []byte { func unsafeGetBytes(s string) []byte {
var buf []byte return unsafe.Slice(unsafe.StringData(s), len(s))
p := unsafe.Pointer(&buf)
*(*string)(p) = s
(*reflect.SliceHeader)(p).Cap = len(s)
return buf
} }
func unsafeGetString(buf []byte) string { func unsafeGetString(buf []byte) string {

Loading…
Cancel
Save