Remove empty alert labels on ingest

The same behavior exists in prometheus. This is a
bit superfluous, but in the event people are using
old versions of prometheus or a different metric
gathering system, it's still valid to check.
This commit is contained in:
Stuart Nelson 2018-03-20 12:06:34 +01:00
parent 85caf29316
commit 0c026b4387
1 changed files with 10 additions and 0 deletions

View File

@ -496,6 +496,8 @@ func (api *API) insertAlerts(w http.ResponseWriter, r *http.Request, alerts ...*
validationErrs = &types.MultiError{} validationErrs = &types.MultiError{}
) )
for _, a := range alerts { for _, a := range alerts {
removeEmptyLabels(a.Labels)
if err := a.Validate(); err != nil { if err := a.Validate(); err != nil {
validationErrs.Add(err) validationErrs.Add(err)
numInvalidAlerts.Inc() numInvalidAlerts.Inc()
@ -522,6 +524,14 @@ func (api *API) insertAlerts(w http.ResponseWriter, r *http.Request, alerts ...*
api.respond(w, nil) api.respond(w, nil)
} }
func removeEmptyLabels(ls model.LabelSet) {
for k, v := range ls {
if string(v) == "" {
delete(ls, k)
}
}
}
func (api *API) setSilence(w http.ResponseWriter, r *http.Request) { func (api *API) setSilence(w http.ResponseWriter, r *http.Request) {
var sil types.Silence var sil types.Silence
if err := api.receive(r, &sil); err != nil { if err := api.receive(r, &sil); err != nil {