Skip to content

Commit d726f49

Browse files
committed
fix(notification): broken test notifications
ref grafana#6159
1 parent 5a201cf commit d726f49

File tree

6 files changed

+11
-23
lines changed

6 files changed

+11
-23
lines changed

pkg/services/alerting/conditions/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c *QueryCondition) executeQuery(context *alerting.EvalContext, timeRange *
8282
req := c.getRequestForAlertRule(getDsInfo.Result, timeRange)
8383
result := make(tsdb.TimeSeriesSlice, 0)
8484

85-
resp, err := c.HandleRequest(context.Context, req)
85+
resp, err := c.HandleRequest(context.Ctx, req)
8686
if err != nil {
8787
return nil, fmt.Errorf("tsdb.HandleRequest() error %v", err)
8888
}

pkg/services/alerting/eval_context.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,7 @@ type EvalContext struct {
2828
NoDataFound bool
2929
RetryCount int
3030

31-
Context context.Context
32-
}
33-
34-
func (evalContext *EvalContext) Deadline() (deadline time.Time, ok bool) {
35-
return evalContext.Deadline()
36-
}
37-
38-
func (evalContext *EvalContext) Done() <-chan struct{} {
39-
return evalContext.Context.Done()
40-
}
41-
42-
func (evalContext *EvalContext) Err() error {
43-
return evalContext.Context.Err()
44-
}
45-
46-
func (evalContext *EvalContext) Value(key interface{}) interface{} {
47-
return evalContext.Context.Value(key)
31+
Ctx context.Context
4832
}
4933

5034
type StateDescription struct {
@@ -103,6 +87,10 @@ func (c *EvalContext) GetDashboardSlug() (string, error) {
10387
}
10488

10589
func (c *EvalContext) GetRuleUrl() (string, error) {
90+
if c.IsTestRun {
91+
return setting.AppUrl, nil
92+
}
93+
10694
if slug, err := c.GetDashboardSlug(); err != nil {
10795
return "", err
10896
} else {
@@ -113,7 +101,7 @@ func (c *EvalContext) GetRuleUrl() (string, error) {
113101

114102
func NewEvalContext(alertCtx context.Context, rule *Rule) *EvalContext {
115103
return &EvalContext{
116-
Context: alertCtx,
104+
Ctx: alertCtx,
117105
StartTime: time.Now(),
118106
Rule: rule,
119107
Logs: make([]*ResultLogEntry, 0),

pkg/services/alerting/notifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (n *RootNotifier) Notify(context *EvalContext) error {
5757
}
5858

5959
func (n *RootNotifier) sendNotifications(context *EvalContext, notifiers []Notifier) error {
60-
g, _ := errgroup.WithContext(context.Context)
60+
g, _ := errgroup.WithContext(context.Ctx)
6161

6262
for _, notifier := range notifiers {
6363
n.log.Info("Sending notification", "firing", context.Firing, "type", notifier.GetType())

pkg/services/alerting/notifiers/email.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (this *EmailNotifier) Notify(evalContext *alerting.EvalContext) error {
6363
},
6464
}
6565

66-
err = bus.DispatchCtx(evalContext, cmd)
66+
err = bus.DispatchCtx(evalContext.Ctx, cmd)
6767

6868
if err != nil {
6969
this.log.Error("Failed to send alert notification email", "error", err)

pkg/services/alerting/notifiers/slack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (this *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
9090
data, _ := json.Marshal(&body)
9191
cmd := &m.SendWebhookSync{Url: this.Url, Body: string(data)}
9292

93-
if err := bus.DispatchCtx(evalContext, cmd); err != nil {
93+
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
9494
this.log.Error("Failed to send slack notification", "error", err, "webhook", this.Name)
9595
}
9696

pkg/services/alerting/notifiers/webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (this *WebhookNotifier) Notify(evalContext *alerting.EvalContext) error {
6565
Body: string(body),
6666
}
6767

68-
if err := bus.DispatchCtx(evalContext, cmd); err != nil {
68+
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
6969
this.log.Error("Failed to send webhook", "error", err, "webhook", this.Name)
7070
}
7171

0 commit comments

Comments
 (0)