From 0c0f013a60c812f46df1b8fa2863d1038e0e0208 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 30 Sep 2024 14:06:20 +0200 Subject: [PATCH] lib/logstorage: skip values with zero hits for 'uniq', 'top' and 'field_values' pipes See https://github.com/VictoriaMetrics/victorialogs-datasource/issues/72#issuecomment-2352078483 --- docs/VictoriaLogs/CHANGELOG.md | 2 ++ lib/logstorage/pipe_top.go | 4 ++++ lib/logstorage/pipe_uniq.go | 32 +++++++++++++++----------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index b6516630c..f01ed1c59 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -15,6 +15,8 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta ## tip +* BUGFIX: do not return field values with zero matching logs from [`field_values`](https://docs.victoriametrics.com/victorialogs/logsql/#field_values-pipe), [`top`](https://docs.victoriametrics.com/victorialogs/logsql/#top-pipe) and [`uniq`](https://docs.victoriametrics.com/victorialogs/logsql/#uniq-pipe) pipes. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/72#issuecomment-2352078483). + ## [v0.32.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.32.0-victorialogs) Released at 2024-09-29 diff --git a/lib/logstorage/pipe_top.go b/lib/logstorage/pipe_top.go index 034038b0a..fb196cacb 100644 --- a/lib/logstorage/pipe_top.go +++ b/lib/logstorage/pipe_top.go @@ -207,6 +207,10 @@ func (shard *pipeTopProcessorShard) writeBlock(br *blockResult) { } func (shard *pipeTopProcessorShard) updateState(v string, hits uint64) { + if hits == 0 { + return + } + m := shard.getM() pHits, ok := m[v] if !ok { diff --git a/lib/logstorage/pipe_uniq.go b/lib/logstorage/pipe_uniq.go index c33cfc7f0..4803ac45a 100644 --- a/lib/logstorage/pipe_uniq.go +++ b/lib/logstorage/pipe_uniq.go @@ -166,24 +166,18 @@ func (shard *pipeUniqProcessorShard) writeBlock(br *blockResult) bool { return true } if c.valueType == valueTypeDict { - if needHits { - a := encoding.GetUint64s(len(c.dictValues)) - hits := a.A - clear(hits) - valuesEncoded := c.getValuesEncoded(br) - for _, v := range valuesEncoded { - idx := unmarshalUint8(v) - hits[idx]++ - } - for i, v := range c.dictValues { - shard.updateState(v, hits[i]) - } - encoding.PutUint64s(a) - } else { - for _, v := range c.dictValues { - shard.updateState(v, 0) - } + a := encoding.GetUint64s(len(c.dictValues)) + hits := a.A + clear(hits) + valuesEncoded := c.getValuesEncoded(br) + for _, v := range valuesEncoded { + idx := unmarshalUint8(v) + hits[idx]++ } + for i, v := range c.dictValues { + shard.updateState(v, hits[i]) + } + encoding.PutUint64s(a) return true } @@ -230,6 +224,10 @@ func (shard *pipeUniqProcessorShard) writeBlock(br *blockResult) bool { } func (shard *pipeUniqProcessorShard) updateState(v string, hits uint64) { + if hits == 0 { + return + } + m := shard.getM() pHits, ok := m[v] if !ok {