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