mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
app/vmselect/prometheus: update adjustLastPoints function
- Do not overwrite last points by the previous NaNs, since this may result in empty time series. - Overwrite the last 2 points instead of 3. This should be enough in most cases.
This commit is contained in:
parent
e06866005d
commit
9a4b2b8315
@ -489,7 +489,7 @@ func QueryRangeHandler(w http.ResponseWriter, r *http.Request) error {
|
|||||||
return fmt.Errorf("cannot execute %q: %s", query, err)
|
return fmt.Errorf("cannot execute %q: %s", query, err)
|
||||||
}
|
}
|
||||||
if ct-end < latencyOffset {
|
if ct-end < latencyOffset {
|
||||||
adjustLastPoints(result)
|
result = adjustLastPoints(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@ -502,17 +502,17 @@ var queryRangeDuration = metrics.NewSummary(`vm_request_duration_seconds{path="/
|
|||||||
|
|
||||||
// adjustLastPoints substitutes the last point values with the previous
|
// adjustLastPoints substitutes the last point values with the previous
|
||||||
// point values, since the last points may contain garbage.
|
// point values, since the last points may contain garbage.
|
||||||
func adjustLastPoints(tss []netstorage.Result) {
|
func adjustLastPoints(tss []netstorage.Result) []netstorage.Result {
|
||||||
if len(tss) == 0 {
|
if len(tss) == 0 {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for the last non-NaN value across all the timeseries.
|
// Search for the last non-NaN value across all the timeseries.
|
||||||
lastNonNaNIdx := -1
|
lastNonNaNIdx := -1
|
||||||
for i := range tss {
|
for i := range tss {
|
||||||
r := &tss[i]
|
values := tss[i].Values
|
||||||
j := len(r.Values) - 1
|
j := len(values) - 1
|
||||||
for j >= 0 && math.IsNaN(r.Values[j]) {
|
for j >= 0 && math.IsNaN(values[j]) {
|
||||||
j--
|
j--
|
||||||
}
|
}
|
||||||
if j > lastNonNaNIdx {
|
if j > lastNonNaNIdx {
|
||||||
@ -521,21 +521,22 @@ func adjustLastPoints(tss []netstorage.Result) {
|
|||||||
}
|
}
|
||||||
if lastNonNaNIdx == -1 {
|
if lastNonNaNIdx == -1 {
|
||||||
// All timeseries contain only NaNs.
|
// All timeseries contain only NaNs.
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Substitute last three values starting from lastNonNaNIdx
|
// Substitute the last two values starting from lastNonNaNIdx
|
||||||
// with the previous values for each timeseries.
|
// with the previous values for each timeseries.
|
||||||
for i := range tss {
|
for i := range tss {
|
||||||
r := &tss[i]
|
values := tss[i].Values
|
||||||
for j := 0; j < 3; j++ {
|
for j := 0; j < 2; j++ {
|
||||||
idx := lastNonNaNIdx + j
|
idx := lastNonNaNIdx + j
|
||||||
if idx <= 0 || idx >= len(r.Values) {
|
if idx <= 0 || idx >= len(values) || math.IsNaN(values[idx-1]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r.Values[idx] = r.Values[idx-1]
|
values[idx] = values[idx-1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tss
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTime(r *http.Request, argKey string, defaultValue int64) (int64, error) {
|
func getTime(r *http.Request, argKey string, defaultValue int64) (int64, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user