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:
parent
85caf29316
commit
0c026b4387
10
api/api.go
10
api/api.go
|
@ -496,6 +496,8 @@ func (api *API) insertAlerts(w http.ResponseWriter, r *http.Request, alerts ...*
|
|||
validationErrs = &types.MultiError{}
|
||||
)
|
||||
for _, a := range alerts {
|
||||
removeEmptyLabels(a.Labels)
|
||||
|
||||
if err := a.Validate(); err != nil {
|
||||
validationErrs.Add(err)
|
||||
numInvalidAlerts.Inc()
|
||||
|
@ -522,6 +524,14 @@ func (api *API) insertAlerts(w http.ResponseWriter, r *http.Request, alerts ...*
|
|||
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) {
|
||||
var sil types.Silence
|
||||
if err := api.receive(r, &sil); err != nil {
|
||||
|
|
Loading…
Reference in New Issue