From 17283fab6ca649684b58cc301a0576a8f9dbb0b5 Mon Sep 17 00:00:00 2001 From: hagen1778 Date: Mon, 13 May 2024 15:35:11 +0200 Subject: [PATCH] lib/logstorage: make linter happy Signed-off-by: hagen1778 --- lib/logstorage/block_result.go | 4 ++-- lib/logstorage/pipe_offset.go | 2 +- lib/logstorage/pipe_sort.go | 12 +++++------ lib/logstorage/stats_count_uniq.go | 4 +--- lib/logstorage/storage_search.go | 26 ---------------------- lib/logstorage/storage_search_test.go | 31 ++++++++++++++++----------- 6 files changed, 29 insertions(+), 50 deletions(-) diff --git a/lib/logstorage/block_result.go b/lib/logstorage/block_result.go index abce4a318..de6de0721 100644 --- a/lib/logstorage/block_result.go +++ b/lib/logstorage/block_result.go @@ -1512,7 +1512,7 @@ func (c *blockResultColumn) getFloatValueAtRow(rowIdx int) float64 { } } -func (c *blockResultColumn) getMaxValue(br *blockResult) float64 { +func (c *blockResultColumn) getMaxValue(_ *blockResult) float64 { if c.isConst { v := c.encodedValues[0] f, ok := tryParseFloat64(v) @@ -1620,7 +1620,7 @@ func (c *blockResultColumn) getMaxValue(br *blockResult) float64 { } } -func (c *blockResultColumn) getMinValue(br *blockResult) float64 { +func (c *blockResultColumn) getMinValue(_ *blockResult) float64 { if c.isConst { v := c.encodedValues[0] f, ok := tryParseFloat64(v) diff --git a/lib/logstorage/pipe_offset.go b/lib/logstorage/pipe_offset.go index 99af79357..61219989a 100644 --- a/lib/logstorage/pipe_offset.go +++ b/lib/logstorage/pipe_offset.go @@ -19,7 +19,7 @@ func (po *pipeOffset) String() string { func (po *pipeOffset) updateNeededFields(_, _ fieldsSet) { } -func (po *pipeOffset) newPipeProcessor(workersCount int, _ <-chan struct{}, _ func(), ppBase pipeProcessor) pipeProcessor { +func (po *pipeOffset) newPipeProcessor(_ int, _ <-chan struct{}, _ func(), ppBase pipeProcessor) pipeProcessor { return &pipeOffsetProcessor{ po: po, ppBase: ppBase, diff --git a/lib/logstorage/pipe_sort.go b/lib/logstorage/pipe_sort.go index 961029c41..1d406e081 100644 --- a/lib/logstorage/pipe_sort.go +++ b/lib/logstorage/pipe_sort.go @@ -315,17 +315,17 @@ func (shard *pipeSortProcessorShard) createFloat64Values(values []string) []floa return a } -func (psp *pipeSortProcessorShard) Len() int { - return len(psp.rowRefs) +func (shard *pipeSortProcessorShard) Len() int { + return len(shard.rowRefs) } -func (psp *pipeSortProcessorShard) Swap(i, j int) { - rowRefs := psp.rowRefs +func (shard *pipeSortProcessorShard) Swap(i, j int) { + rowRefs := shard.rowRefs rowRefs[i], rowRefs[j] = rowRefs[j], rowRefs[i] } -func (psp *pipeSortProcessorShard) Less(i, j int) bool { - return sortBlockLess(psp, i, psp, j) +func (shard *pipeSortProcessorShard) Less(i, j int) bool { + return sortBlockLess(shard, i, shard, j) } func (psp *pipeSortProcessor) writeBlock(workerID uint, br *blockResult) { diff --git a/lib/logstorage/stats_count_uniq.go b/lib/logstorage/stats_count_uniq.go index 6b0885961..3999bab48 100644 --- a/lib/logstorage/stats_count_uniq.go +++ b/lib/logstorage/stats_count_uniq.go @@ -175,7 +175,6 @@ func (sup *statsCountUniqProcessor) updateStatsForAllRows(br *blockResult) int { stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof("")) } } - keyBuf = sup.keyBuf return stateSizeIncrease } @@ -308,7 +307,7 @@ func (sup *statsCountUniqProcessor) updateStatsForRow(br *blockResult, rowIdx in m[string(keyBuf)] = struct{}{} stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof("")) } - sup.keyBuf = keyBuf + //sup.keyBuf = keyBuf return stateSizeIncrease } @@ -325,7 +324,6 @@ func (sup *statsCountUniqProcessor) updateStatsForRow(br *blockResult, rowIdx in m[string(keyBuf)] = struct{}{} stateSizeIncrease += len(keyBuf) + int(unsafe.Sizeof("")) } - keyBuf = sup.keyBuf return stateSizeIncrease } diff --git a/lib/logstorage/storage_search.go b/lib/logstorage/storage_search.go index 68f27f648..10e924697 100644 --- a/lib/logstorage/storage_search.go +++ b/lib/logstorage/storage_search.go @@ -164,32 +164,6 @@ func (c *BlockColumn) reset() { c.Values = nil } -func getBlockColumnIndex(columns []BlockColumn, columnName string) int { - for i, c := range columns { - if c.Name == columnName { - return i - } - } - return -1 -} - -func getBlockColumnValues(columns []BlockColumn, columnName string, rowsCount int) []string { - for _, c := range columns { - if c.Name == columnName { - return c.Values - } - } - return getEmptyStrings(rowsCount) -} - -func appendBlockColumnValues(dst [][]string, columns []BlockColumn, fields []string, rowsCount int) [][]string { - for _, f := range fields { - values := getBlockColumnValues(columns, f, rowsCount) - dst = append(dst, values) - } - return dst -} - func getEmptyStrings(rowsCount int) []string { p := emptyStrings.Load() if p == nil { diff --git a/lib/logstorage/storage_search_test.go b/lib/logstorage/storage_search_test.go index 0958c9190..4eab5127d 100644 --- a/lib/logstorage/storage_search_test.go +++ b/lib/logstorage/storage_search_test.go @@ -89,7 +89,7 @@ func TestStorageRunQuery(t *testing.T) { panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) }) t.Run("missing-message-text", func(_ *testing.T) { q := mustParseQuery(`foobar`) @@ -101,7 +101,7 @@ func TestStorageRunQuery(t *testing.T) { panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) }) t.Run("matching-tenant-id", func(t *testing.T) { q := mustParseQuery(`tenant.id:*`) @@ -135,7 +135,7 @@ func TestStorageRunQuery(t *testing.T) { rowsCountTotal.Add(uint32(len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) expectedRowsCount := streamsPerTenant * blocksPerStream * rowsPerBlock if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { @@ -149,7 +149,7 @@ func TestStorageRunQuery(t *testing.T) { writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) { rowsCountTotal.Add(uint32(len(timestamps))) } - s.RunQuery(context.Background(), allTenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), allTenantIDs, q, writeBlock)) expectedRowsCount := tenantsCount * streamsPerTenant * blocksPerStream * rowsPerBlock if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { @@ -162,7 +162,7 @@ func TestStorageRunQuery(t *testing.T) { writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) { rowsCountTotal.Add(uint32(len(timestamps))) } - s.RunQuery(context.Background(), allTenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), allTenantIDs, q, writeBlock)) expectedRowsCount := tenantsCount * streamsPerTenant * blocksPerStream * rowsPerBlock if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { @@ -174,7 +174,7 @@ func TestStorageRunQuery(t *testing.T) { writeBlock := func(_ uint, timestamps []int64, _ []BlockColumn) { panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) } - s.RunQuery(context.Background(), allTenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), allTenantIDs, q, writeBlock)) }) t.Run("matching-stream-id", func(t *testing.T) { for i := 0; i < streamsPerTenant; i++ { @@ -208,7 +208,7 @@ func TestStorageRunQuery(t *testing.T) { rowsCountTotal.Add(uint32(len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) expectedRowsCount := blocksPerStream * rowsPerBlock if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { @@ -227,7 +227,7 @@ func TestStorageRunQuery(t *testing.T) { rowsCountTotal.Add(uint32(len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) expectedRowsCount := streamsPerTenant * blocksPerStream * 2 if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { @@ -247,7 +247,7 @@ func TestStorageRunQuery(t *testing.T) { rowsCountTotal.Add(uint32(len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) expectedRowsCount := streamsPerTenant * blocksPerStream if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { @@ -267,7 +267,7 @@ func TestStorageRunQuery(t *testing.T) { rowsCountTotal.Add(uint32(len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) expectedRowsCount := blocksPerStream if n := rowsCountTotal.Load(); n != uint32(expectedRowsCount) { @@ -286,7 +286,7 @@ func TestStorageRunQuery(t *testing.T) { panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) }) t.Run("missing-time-range", func(_ *testing.T) { minTimestamp := baseTimestamp + (rowsPerBlock+1)*1e9 @@ -300,7 +300,7 @@ func TestStorageRunQuery(t *testing.T) { panic(fmt.Errorf("unexpected match for %d rows", len(timestamps))) } tenantIDs := []TenantID{tenantID} - s.RunQuery(context.Background(), tenantIDs, q, writeBlock) + checkErr(t, s.RunQuery(context.Background(), tenantIDs, q, writeBlock)) }) // Close the storage and delete its data @@ -308,6 +308,13 @@ func TestStorageRunQuery(t *testing.T) { fs.MustRemoveAll(path) } +func checkErr(t *testing.T, err error) { + t.Helper() + if err != nil { + t.Fatalf("unexpected err: %s", err) + } +} + func mustParseQuery(query string) *Query { q, err := ParseQuery(query) if err != nil {