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

* Return error instead of default writing NaN
This commit is contained in:
William Wernert
2024-07-22 15:47:02 -04:00
committed by GitHub
parent f1b4964b24
commit 45f298120e
2 changed files with 6 additions and 8 deletions
@@ -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)
})
})
}
+4 -6
View File
@@ -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()