From d6a4daa26a861c8642dca467cc6afc450bbc6b2f Mon Sep 17 00:00:00 2001 From: Alex Salt Date: Tue, 21 May 2019 12:41:54 +0300 Subject: [PATCH] web api: handle alert with Infinity/NaN values (#5582) * web/api/v1: alert value as string in alert/rules endpoints Signed-off-by: Alexander Saltykov --- docs/querying/api.md | 4 ++-- web/api/v1/api.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/querying/api.md b/docs/querying/api.md index fba7e9ff0b..d01f15ab14 100644 --- a/docs/querying/api.md +++ b/docs/querying/api.md @@ -465,7 +465,7 @@ $ curl http://localhost:9090/api/v1/rules "severity": "page" }, "state": "firing", - "value": 1 + "value": "1e+00" } ], "annotations": { @@ -522,7 +522,7 @@ $ curl http://localhost:9090/api/v1/alerts "alertname": "my-alert" }, "state": "firing", - "value": 1 + "value": "1e+00" } ] }, diff --git a/web/api/v1/api.go b/web/api/v1/api.go index bfb4aec9fd..465594f549 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -694,7 +694,7 @@ type Alert struct { Annotations labels.Labels `json:"annotations"` State string `json:"state"` ActiveAt *time.Time `json:"activeAt,omitempty"` - Value float64 `json:"value"` + Value string `json:"value"` } func (api *API) alerts(r *http.Request) apiFuncResult { @@ -721,7 +721,7 @@ func rulesAlertsToAPIAlerts(rulesAlerts []*rules.Alert) []*Alert { Annotations: ruleAlert.Annotations, State: ruleAlert.State.String(), ActiveAt: &ruleAlert.ActiveAt, - Value: ruleAlert.Value, + Value: strconv.FormatFloat(ruleAlert.Value, 'e', -1, 64), } }