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 <alexander-s@yandex-team.ru>
This commit is contained in:
Alex Salt 2019-05-21 12:41:54 +03:00 committed by Brian Brazil
parent 0652b518da
commit d6a4daa26a
2 changed files with 4 additions and 4 deletions

View File

@ -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"
}
]
},

View File

@ -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),
}
}