From 930f1ee153bbcee08021ec394fdc7f747a2e5aee Mon Sep 17 00:00:00 2001 From: Siqi Liu Date: Thu, 13 Oct 2022 16:57:16 +0800 Subject: [PATCH] BUGFIX: properly calculate histogram_quantile with the same value and different string le (#3225) Co-authored-by: 647(siki.liu) --- app/vmselect/promql/transform.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index fe0baec8e..65d45390a 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -942,6 +942,7 @@ func transformHistogramQuantile(tfa *transformFuncArg) ([]*timeseries, error) { } rvs := make([]*timeseries, 0, len(m)) for _, xss := range m { + xss = mergeSameLE(xss) sort.Slice(xss, func(i, j int) bool { return xss[i].le < xss[j].le }) @@ -1034,6 +1035,37 @@ func fixBrokenBuckets(i int, xss []leTimeseries) { } } +func mergeSameLE(xss []leTimeseries) []leTimeseries { + hit := false + m := make(map[float64]leTimeseries) + for _, xs := range xss { + i, ok := m[xs.le] + if ok { + ts := ×eries{} + ts.CopyFromShallowTimestamps(i.ts) + for k := range ts.Values { + ts.Values[k] += xs.ts.Values[k] + } + m[xs.le] = leTimeseries{ + le: xs.le, + ts: ts, + } + hit = true + continue + } + m[xs.le] = xs + } + if (!hit) { + return xss + } + + r := make([]leTimeseries, 0, len(m)) + for _, v := range m { + r = append(r, v) + } + return r +} + func transformHour(t time.Time) int { return t.Hour() }