|
|
|
@ -121,6 +121,8 @@ type AlertingRule struct {
|
|
|
|
|
annotations labels.Labels |
|
|
|
|
// External labels from the global config.
|
|
|
|
|
externalLabels map[string]string |
|
|
|
|
// The external URL from the --web.external-url flag.
|
|
|
|
|
externalURL string |
|
|
|
|
// true if old state has been restored. We start persisting samples for ALERT_FOR_STATE
|
|
|
|
|
// only after the restoration.
|
|
|
|
|
restored bool |
|
|
|
@ -144,7 +146,7 @@ type AlertingRule struct {
|
|
|
|
|
// NewAlertingRule constructs a new AlertingRule.
|
|
|
|
|
func NewAlertingRule( |
|
|
|
|
name string, vec parser.Expr, hold time.Duration, |
|
|
|
|
labels, annotations, externalLabels labels.Labels, |
|
|
|
|
labels, annotations, externalLabels labels.Labels, externalURL string, |
|
|
|
|
restored bool, logger log.Logger, |
|
|
|
|
) *AlertingRule { |
|
|
|
|
el := make(map[string]string, len(externalLabels)) |
|
|
|
@ -159,6 +161,7 @@ func NewAlertingRule(
|
|
|
|
|
labels: labels, |
|
|
|
|
annotations: annotations, |
|
|
|
|
externalLabels: el, |
|
|
|
|
externalURL: externalURL, |
|
|
|
|
health: HealthUnknown, |
|
|
|
|
active: map[uint64]*Alert{}, |
|
|
|
|
logger: logger, |
|
|
|
@ -318,12 +321,13 @@ func (r *AlertingRule) Eval(ctx context.Context, ts time.Time, query QueryFunc,
|
|
|
|
|
l[lbl.Name] = lbl.Value |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tmplData := template.AlertTemplateData(l, r.externalLabels, smpl.V) |
|
|
|
|
tmplData := template.AlertTemplateData(l, r.externalLabels, r.externalURL, smpl.V) |
|
|
|
|
// Inject some convenience variables that are easier to remember for users
|
|
|
|
|
// who are not used to Go's templating system.
|
|
|
|
|
defs := []string{ |
|
|
|
|
"{{$labels := .Labels}}", |
|
|
|
|
"{{$externalLabels := .ExternalLabels}}", |
|
|
|
|
"{{$externalURL := .ExternalURL}}", |
|
|
|
|
"{{$value := .Value}}", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|