fix: fix vmalert template label not complete bug (#435)

Co-authored-by: xiaobeibei <xiaobeibei@bigo.sg>
This commit is contained in:
肖贝贝 2020-04-26 18:30:10 +08:00 committed by GitHub
parent d7c1ff8b0c
commit eeadfccdc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,15 +171,31 @@ func (r *Rule) newAlert(m datasource.Metric) (*notifier.Alert, error) {
Start: time.Now(),
// TODO: support End time
}
// 1. use data labels
for _, l := range m.Labels {
a.Labels[l.Name] = l.Value
}
// 2. template rule labels with data labels
rLabels, err := a.ExecTemplate(r.Labels)
if err != nil {
return a, err
}
// 3. merge data labels and rule labels
// metric labels may be overridden by
// rule labels
for k, v := range r.Labels {
for k, v := range rLabels {
a.Labels[k] = v
}
var err error
// 4. template merged labels
a.Labels, err = a.ExecTemplate(a.Labels)
if err != nil {
return a, err
}
a.Annotations, err = a.ExecTemplate(r.Annotations)
return a, err
}