diff --git a/app/vmselect/promql/transform.go b/app/vmselect/promql/transform.go index ded21f2a9..495a174db 100644 --- a/app/vmselect/promql/transform.go +++ b/app/vmselect/promql/transform.go @@ -526,27 +526,22 @@ func vmrangeBucketsToLE(tss []*timeseries) []*timeseries { xsPrev = xs continue } - if xs.start != xsPrev.end { - // check for duplicates at the start of bucket. - // in case of duplicate following le already exists. - // no need to add new one with zero values. - if _, ok := uniqTs[xs.startStr]; !ok { - uniqTs[xs.startStr] = xs.ts - xssNew = append(xssNew, x{ - endStr: xs.startStr, - end: xs.start, - ts: copyTS(ts, xs.startStr), - }) - } + if xs.start != xsPrev.end && uniqTs[xs.startStr] == nil { + uniqTs[xs.startStr] = xs.ts + xssNew = append(xssNew, x{ + endStr: xs.startStr, + end: xs.start, + ts: copyTS(ts, xs.startStr), + }) } ts.MetricName.AddTag("le", xs.endStr) - if prevTs, ok := uniqTs[xs.endStr]; !ok { + prevTs := uniqTs[xs.endStr] + if prevTs != nil { + // the end of the current bucket is not unique, need to merge it with the existing bucket. + mergeNonOverlappingTimeseries(prevTs, xs.ts) + } else { xssNew = append(xssNew, xs) uniqTs[xs.endStr] = xs.ts - } else { - // end of current bucket not uniq, - // need to merge it with existing bucket. - mergeNonOverlappingTimeseries(prevTs, xs.ts) } xsPrev = xs } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d13dfbe76..fdfbdcd81 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -12,6 +12,7 @@ * BUGFIX: vmagent: prevent from high CPU usage bug during failing scrapes with small `scrape_timeout` (less than a few seconds). * BUGFIX: vmagent: reduce memory usage when Kubernetes service discovery is used in big number of distinct jobs by sharing the cache. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1113 +* BUGFUX: avoid `duplicate time series` error if `prometheus_buckets()` covers a time range with distinct set of buckets. * BUGFIX: prevent exponent overflow when processing extremely small values close to zero such as `2.964393875E-314`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1114