From 2f1ce74d97184215a20a83e5cf4ed2a1205c37c6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 8 Nov 2024 23:09:55 +0100 Subject: [PATCH] lib/logstorage: properly clone field values at `values` stats function Previously field values weren't properly cloned, which could lead to garbage output for `values` stats function Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7458 --- docs/VictoriaLogs/CHANGELOG.md | 1 + lib/logstorage/stats_values.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/VictoriaLogs/CHANGELOG.md b/docs/VictoriaLogs/CHANGELOG.md index 9a181a8f6..c4886648d 100644 --- a/docs/VictoriaLogs/CHANGELOG.md +++ b/docs/VictoriaLogs/CHANGELOG.md @@ -25,6 +25,7 @@ according to [these docs](https://docs.victoriametrics.com/victorialogs/quicksta * FEATURE: [syslog data ingestion](https://docs.victoriametrics.com/victorialogs/data-ingestion/syslog/): allow adding the specified [log fields](https://docs.victoriametrics.com/victorialogs/keyconcepts/#data-model) during data ingestion. See [these docs](https://docs.victoriametrics.com/victorialogs/data-ingestion/syslog/#adding-extra-fields). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7354). * FEATURE: [Loki data ingestion](https://docs.victoriametrics.com/victorialogs/data-ingestion/#loki-json-api): show the original request body on parse errors. This should simplify debugging. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7490). +* BUGFIX: [`values` stats function](https://docs.victoriametrics.com/victorialogs/logsql/#values-stats): fix a bug, which could lead to corrupted results. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7458). * BUGFIX: [HTTP querying APIs](https://docs.victoriametrics.com/victorialogs/querying/#http-api): properly take into account the `end` query arg when calculating time range for [`_time:duration` filter](https://docs.victoriametrics.com/victorialogs/logsql/#time-filter). Previously the `_time:duration` filter was treated as `_time:[now-duration, now)`, while it should be treated as `_time:[end-duration, end)`. ## [v0.41.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v0.41.0-victorialogs) diff --git a/lib/logstorage/stats_values.go b/lib/logstorage/stats_values.go index eb9c100de..5d79bec5e 100644 --- a/lib/logstorage/stats_values.go +++ b/lib/logstorage/stats_values.go @@ -91,12 +91,13 @@ func (svp *statsValuesProcessor) updateStatsForAllRowsColumn(c *blockResultColum } values := svp.values + vPrev := "" for _, v := range c.getValues(br) { - if len(values) == 0 || values[len(values)-1] != v { - v = strings.Clone(v) - stateSizeIncrease += len(v) + if len(values) == 0 || v != vPrev { + vPrev = strings.Clone(v) + stateSizeIncrease += len(vPrev) } - values = append(values, v) + values = append(values, vPrev) } svp.values = values