Alerting: Return error when writing recorded metrics instead of default writing NaN (#90743)

* Return error instead of default writing NaN
pull/90799/head
William Wernert 10 months ago committed by GitHub
parent f1b4964b24
commit 45f298120e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      pkg/services/ngalert/schedule/recording_rule_test.go
  2. 10
      pkg/services/ngalert/writer/prom.go

@ -482,8 +482,8 @@ func TestRecordingRule_Integration(t *testing.T) {
t.Run("status shows evaluation", func(t *testing.T) {
status := process.(*recordingRule).Status()
// TODO: OK expected for nil result but having a point. Probably should change.
require.Equal(t, "ok", status.Health)
//TODO: assert "error" to fix test, update to "nodata" in the future
require.Equal(t, "error", status.Health)
})
})
}

@ -3,7 +3,6 @@ package writer
import (
"context"
"fmt"
"math"
"net/http"
"net/url"
"strings"
@ -63,15 +62,14 @@ func PointsFromFrames(name string, t time.Time, frames data.Frames, extraLabels
points := make([]Point, 0, len(col.Refs))
for _, ref := range col.Refs {
// Use a default value of NaN if the value is empty or nil.
f := math.NaN()
if fp, empty, _ := ref.NullableFloat64Value(); !empty && fp != nil {
f = *fp
fp, empty, _ := ref.NullableFloat64Value()
if empty || fp == nil {
return nil, fmt.Errorf("unable to read float64 value")
}
metric := Metric{
T: t,
V: f,
V: *fp,
}
labels := ref.GetLabels().Copy()

Loading…
Cancel
Save