From 93eaea9754e2bcaa650e41dfd21530b2d1e6da92 Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Wed, 14 May 2025 11:50:39 +0300 Subject: [PATCH] lib/protoparser/datadogsketches: fixed duplications in datadog sketches aggregations Previously, due to bug at parsing logic sketches values were duplicated. This commit properly parsers sketches and correctly converts it to time series labels. Related issue: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8836 --- docs/victoriametrics/changelog/CHANGELOG.md | 2 ++ lib/protoparser/datadogsketches/parser.go | 36 ++++++++++--------- .../datadogsketches/parser_test.go | 33 +++++++++++++++++ 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/docs/victoriametrics/changelog/CHANGELOG.md b/docs/victoriametrics/changelog/CHANGELOG.md index 158794f909..d681c9d27f 100644 --- a/docs/victoriametrics/changelog/CHANGELOG.md +++ b/docs/victoriametrics/changelog/CHANGELOG.md @@ -20,6 +20,8 @@ See also [LTS releases](https://docs.victoriametrics.com/victoriametrics/lts-rel **Update Note 1:** `latest` and `stable` tags for docker images will no longer be updated. It is required to use specific version tags for docker images to continue receiving updates. See [#7336](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7336) for details. +* BUGFIX: [vmsingle](https://docs.victoriametrics.com/single-server-victoriametrics/), `vminsert` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/) and [vmagent](https://docs.victoriametrics.com/vmagent/): fixed duplication in Datadog sketches aggregation metrics. See [#8836](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8836) for details. + ## [v1.117.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.117.0) Released at 2025-05-09 diff --git a/lib/protoparser/datadogsketches/parser.go b/lib/protoparser/datadogsketches/parser.go index 5e240ff7ba..a60ba7ff00 100644 --- a/lib/protoparser/datadogsketches/parser.go +++ b/lib/protoparser/datadogsketches/parser.go @@ -163,6 +163,26 @@ func (s *Sketch) ToSummary() []*Metric { minPoints := make([]Point, 0, len(dogsketches)) maxPoints := make([]Point, 0, len(dogsketches)) + for _, d := range dogsketches { + timestamp := d.Ts * 1000 + sumPoints = append(sumPoints, Point{ + Timestamp: timestamp, + Value: d.Sum, + }) + countPoints = append(countPoints, Point{ + Timestamp: timestamp, + Value: float64(d.Cnt), + }) + minPoints = append(minPoints, Point{ + Timestamp: timestamp, + Value: float64(d.Min), + }) + maxPoints = append(maxPoints, Point{ + Timestamp: timestamp, + Value: float64(d.Max), + }) + } + for i, q := range quantiles { points := make([]Point, 0, len(dogsketches)) for _, d := range dogsketches { @@ -171,22 +191,6 @@ func (s *Sketch) ToSummary() []*Metric { Timestamp: timestamp, Value: d.quantile(q), }) - sumPoints = append(sumPoints, Point{ - Timestamp: timestamp, - Value: d.Sum, - }) - countPoints = append(countPoints, Point{ - Timestamp: timestamp, - Value: float64(d.Cnt), - }) - minPoints = append(minPoints, Point{ - Timestamp: timestamp, - Value: float64(d.Min), - }) - maxPoints = append(maxPoints, Point{ - Timestamp: timestamp, - Value: float64(d.Max), - }) } metrics[i] = &Metric{ Name: s.Metric, diff --git a/lib/protoparser/datadogsketches/parser_test.go b/lib/protoparser/datadogsketches/parser_test.go index c9ea5eac35..e8558a9b5e 100644 --- a/lib/protoparser/datadogsketches/parser_test.go +++ b/lib/protoparser/datadogsketches/parser_test.go @@ -29,3 +29,36 @@ func TestDogsketchQuantile(t *testing.T) { f(sketches, 0.99, 20.24) f(sketches, 1, 21) } + +func TestSketchToSummary(t *testing.T) { + f := func(s *Sketch) { + t.Helper() + for _, m := range s.ToSummary() { + if len(m.Points) != len(s.Dogsketches) { + t.Fatalf("unexpected amount of quantile points; got %d; want %d", len(m.Points), len(s.Dogsketches)) + } + } + } + + f(&Sketch{ + Metric: "test_metric", + Host: "host", + Tags: []string{"key1:value1", "key2:value2"}, + Dogsketches: []*Dogsketch{ + { + Min: 8.0, + Max: 21.0, + Cnt: 17, + N: []uint32{0x0, 0x0, 0x1, 0x0, 0x1, 0x4, 0x6, 0x1, 0x2, 0x0, 0x1, 0x0, 0x1}, + K: []int32{0, 1472, 1473, 1479, 1480, 1503, 1504, 1512, 1513, 1514, 1515, 1531, 1532}, + }, + { + Min: 8.0, + Max: 21.0, + Cnt: 17, + N: []uint32{0x0, 0x0, 0x1, 0x0, 0x1, 0x4, 0x6, 0x1, 0x2, 0x0, 0x1, 0x0, 0x1}, + K: []int32{0, 1472, 1473, 1479, 1480, 1503, 1504, 1512, 1513, 1514, 1515, 1531, 1532}, + }, + }, + }) +}