Alerting: Handle marshaling Inf values (#36947)

* SSE: change EvalMatch json value encoding to string
* update MarshalJSON on null.Float to handle inf as null
fixes #36424
This commit is contained in:
Kyle Brandt
2021-07-21 10:04:40 -04:00
committed by GitHub
parent f8118cceaf
commit b6a7156300
2 changed files with 20 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/expr/mathexp"
@@ -61,12 +62,29 @@ func (ccc *ConditionsCmd) NeedsVars() []string {
}
// EvalMatch represents the series violating the threshold.
// It goes into the metadata of data frames so it can be extracted.
type EvalMatch struct {
Value *float64 `json:"value"`
Metric string `json:"metric"`
Labels data.Labels `json:"labels"`
}
func (em EvalMatch) MarshalJSON() ([]byte, error) {
fs := ""
if em.Value != nil {
fs = strconv.FormatFloat(*em.Value, 'f', -1, 64)
}
return json.Marshal(struct {
Value string `json:"value"`
Metric string `json:"metric"`
Labels data.Labels `json:"labels"`
}{
fs,
em.Metric,
em.Labels,
})
}
// Execute runs the command and returns the results or an error if the command
// failed to execute.
func (ccc *ConditionsCmd) Execute(ctx context.Context, vars mathexp.Vars) (mathexp.Results, error) {