diff --git a/pkg/services/alerting/conditions/query.go b/pkg/services/alerting/conditions/query.go index af550a1ad18..a9a99ba919e 100644 --- a/pkg/services/alerting/conditions/query.go +++ b/pkg/services/alerting/conditions/query.go @@ -82,7 +82,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange * req := c.getRequestForAlertRule(getDsInfo.Result, timeRange) result := make(tsdb.TimeSeriesSlice, 0) - resp, err := c.HandleRequest(context.Context, req) + resp, err := c.HandleRequest(context.Ctx, req) if err != nil { return nil, fmt.Errorf("tsdb.HandleRequest() error %v", err) } diff --git a/pkg/services/alerting/eval_context.go b/pkg/services/alerting/eval_context.go index 4903069b887..d9aaec28b0a 100644 --- a/pkg/services/alerting/eval_context.go +++ b/pkg/services/alerting/eval_context.go @@ -28,23 +28,7 @@ type EvalContext struct { NoDataFound bool RetryCount int - Context context.Context -} - -func (evalContext *EvalContext) Deadline() (deadline time.Time, ok bool) { - return evalContext.Deadline() -} - -func (evalContext *EvalContext) Done() <-chan struct{} { - return evalContext.Context.Done() -} - -func (evalContext *EvalContext) Err() error { - return evalContext.Context.Err() -} - -func (evalContext *EvalContext) Value(key interface{}) interface{} { - return evalContext.Context.Value(key) + Ctx context.Context } type StateDescription struct { @@ -103,6 +87,10 @@ func (c *EvalContext) GetDashboardSlug() (string, error) { } func (c *EvalContext) GetRuleUrl() (string, error) { + if c.IsTestRun { + return setting.AppUrl, nil + } + if slug, err := c.GetDashboardSlug(); err != nil { return "", err } else { @@ -113,7 +101,7 @@ func (c *EvalContext) GetRuleUrl() (string, error) { func NewEvalContext(alertCtx context.Context, rule *Rule) *EvalContext { return &EvalContext{ - Context: alertCtx, + Ctx: alertCtx, StartTime: time.Now(), Rule: rule, Logs: make([]*ResultLogEntry, 0), diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index c44ea777595..db84b20e041 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -57,7 +57,7 @@ func (n *RootNotifier) Notify(context *EvalContext) error { } func (n *RootNotifier) sendNotifications(context *EvalContext, notifiers []Notifier) error { - g, _ := errgroup.WithContext(context.Context) + g, _ := errgroup.WithContext(context.Ctx) for _, notifier := range notifiers { n.log.Info("Sending notification", "firing", context.Firing, "type", notifier.GetType()) diff --git a/pkg/services/alerting/notifiers/email.go b/pkg/services/alerting/notifiers/email.go index dfb12e9cb7b..d51383a7ddc 100644 --- a/pkg/services/alerting/notifiers/email.go +++ b/pkg/services/alerting/notifiers/email.go @@ -63,7 +63,7 @@ func (this *EmailNotifier) Notify(evalContext *alerting.EvalContext) error { }, } - err = bus.DispatchCtx(evalContext, cmd) + err = bus.DispatchCtx(evalContext.Ctx, cmd) if err != nil { this.log.Error("Failed to send alert notification email", "error", err) diff --git a/pkg/services/alerting/notifiers/slack.go b/pkg/services/alerting/notifiers/slack.go index ff71ae5d8c8..b0f36631626 100644 --- a/pkg/services/alerting/notifiers/slack.go +++ b/pkg/services/alerting/notifiers/slack.go @@ -90,7 +90,7 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error { data, _ := json.Marshal(&body) cmd := &m.SendWebhookSync{Url: this.Url, Body: string(data)} - if err := bus.DispatchCtx(evalContext, cmd); err != nil { + if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { this.log.Error("Failed to send slack notification", "error", err, "webhook", this.Name) } diff --git a/pkg/services/alerting/notifiers/webhook.go b/pkg/services/alerting/notifiers/webhook.go index 223ea2a5d54..09134702549 100644 --- a/pkg/services/alerting/notifiers/webhook.go +++ b/pkg/services/alerting/notifiers/webhook.go @@ -65,7 +65,7 @@ func (this *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error { Body: string(body), } - if err := bus.DispatchCtx(evalContext, cmd); err != nil { + if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil { this.log.Error("Failed to send webhook", "error", err, "webhook", this.Name) }