app/vmselect/promql: follow-up for 79e1c6a6fc

- Document the fix at docs/CHANGELOG.md
- Add tests with multiple adjancent zero buckets
- Simplify the fix a bit

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/296
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4021
This commit is contained in:
Aliaksandr Valialkin 2023-03-27 18:02:26 -07:00
parent 680a661ec0
commit 54b9537a76
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
3 changed files with 41 additions and 26 deletions

View File

@ -552,26 +552,23 @@ func vmrangeBucketsToLE(tss []*timeseries) []*timeseries {
sort.Slice(xss, func(i, j int) bool { return xss[i].end < xss[j].end }) sort.Slice(xss, func(i, j int) bool { return xss[i].end < xss[j].end })
xssNew := make([]x, 0, len(xss)+2) xssNew := make([]x, 0, len(xss)+2)
var xsPrev x var xsPrev x
hasNonEmpty := false
uniqTs := make(map[string]*timeseries, len(xss)) uniqTs := make(map[string]*timeseries, len(xss))
for _, xs := range xss { for _, xs := range xss {
ts := xs.ts ts := xs.ts
if isZeroTS(ts) { if isZeroTS(ts) {
xsPrev = xs // Skip buckets with zero values - they will be merged into a single bucket
// when the next non-zero bucket appears.
if uniqTs[xs.endStr] == nil { // Do not store xs in xsPrev in order to properly create `le` time series
uniqTs[xs.endStr] = xs.ts // for zero buckets.
xssNew = append(xssNew, x{ // See https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4021
endStr: xs.endStr,
end: xs.end,
ts: copyTS(ts, xs.endStr),
})
}
continue continue
} }
if xs.start != xsPrev.end {
hasNonEmpty = true // There is a gap between the previous bucket and the current bucket
if xs.start != xsPrev.end && uniqTs[xs.startStr] == nil { // or the previous bucket is skipped because it was zero.
// Fill it with a time series with le=xs.start.
if uniqTs[xs.startStr] == nil {
uniqTs[xs.startStr] = xs.ts uniqTs[xs.startStr] = xs.ts
xssNew = append(xssNew, x{ xssNew = append(xssNew, x{
endStr: xs.startStr, endStr: xs.startStr,
@ -579,6 +576,8 @@ func vmrangeBucketsToLE(tss []*timeseries) []*timeseries {
ts: copyTS(ts, xs.startStr), ts: copyTS(ts, xs.startStr),
}) })
} }
}
// Convert the current time series to a time series with le=xs.end
ts.MetricName.AddTag("le", xs.endStr) ts.MetricName.AddTag("le", xs.endStr)
prevTs := uniqTs[xs.endStr] prevTs := uniqTs[xs.endStr]
if prevTs != nil { if prevTs != nil {
@ -590,13 +589,7 @@ func vmrangeBucketsToLE(tss []*timeseries) []*timeseries {
} }
xsPrev = xs xsPrev = xs
} }
if xsPrev.ts != nil && !math.IsInf(xsPrev.end, 1) && !isZeroTS(xsPrev.ts) {
if !hasNonEmpty {
xssNew = []x{}
continue
}
if !math.IsInf(xsPrev.end, 1) && !isZeroTS(xsPrev.ts) {
xssNew = append(xssNew, x{ xssNew = append(xssNew, x{
endStr: "+Inf", endStr: "+Inf",
end: math.Inf(1), end: math.Inf(1),

View File

@ -87,6 +87,27 @@ foo{le="8.799e+05"} 5 123
foo{le="+Inf"} 5 123`, foo{le="+Inf"} 5 123`,
) )
// Multiple adjacent empty vmrange bucket
f(
`foo{vmrange="7.743e+05...8.799e+05"} 5 123
foo{vmrange="6.813e+05...7.743e+05"} 0 123
foo{vmrange="5.813e+05...6.813e+05"} 0 123
`,
`foo{le="7.743e+05"} 0 123
foo{le="8.799e+05"} 5 123
foo{le="+Inf"} 5 123`,
)
f(
`foo{vmrange="8.799e+05...9.813e+05"} 0 123
foo{vmrange="7.743e+05...8.799e+05"} 5 123
foo{vmrange="6.813e+05...7.743e+05"} 0 123
foo{vmrange="5.813e+05...6.813e+05"} 0 123
`,
`foo{le="7.743e+05"} 0 123
foo{le="8.799e+05"} 5 123
foo{le="+Inf"} 5 123`,
)
// Multiple non-empty vmrange buckets // Multiple non-empty vmrange buckets
f( f(
`foo{vmrange="4.084e+02...4.642e+02"} 2 123 `foo{vmrange="4.084e+02...4.642e+02"} 2 123

View File

@ -39,6 +39,7 @@ created by v1.90.0 or newer versions. The solution is to upgrade to v1.90.0 or n
* BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): fix snapshot not being deleted in case of error during backup. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2055). * BUGFIX: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): fix snapshot not being deleted in case of error during backup. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2055).
* BUGFIX: allow using dashes and dots in environment variables names referred in config files via `%{ENV-VAR.SYNTAX}`. See [these docs](https://docs.victoriametrics.com/#environment-variables) and [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3999). * BUGFIX: allow using dashes and dots in environment variables names referred in config files via `%{ENV-VAR.SYNTAX}`. See [these docs](https://docs.victoriametrics.com/#environment-variables) and [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3999).
* BUGFIX: return back query performance scalability on hosts with big number of CPU cores. The scalability has been reduced in [v1.86.0](https://docs.victoriametrics.com/CHANGELOG.html#v1860). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3966). * BUGFIX: return back query performance scalability on hosts with big number of CPU cores. The scalability has been reduced in [v1.86.0](https://docs.victoriametrics.com/CHANGELOG.html#v1860). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3966).
* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly convert [VictoriaMetrics historgram buckets](https://valyala.medium.com/improving-histogram-usability-for-prometheus-and-grafana-bc7e5df0e350) to Prometheus histogram buckets when VictoriaMetrics histogram contain zero buckets. Previously these buckets were ignored, and this could lead to missing Prometheus histogram buckets after the conversion. Thanks to @zklapow for [the fix](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4021).
## [v1.89.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.89.1) ## [v1.89.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.89.1)