Browse Source

fix(notification): broken test notifications

ref #6159
bergquist 9 years ago
parent
commit
d726f49a8c

+ 1 - 1
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)
 	}

+ 6 - 18
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),

+ 1 - 1
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())

+ 1 - 1
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)

+ 1 - 1
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)
 	}
 

+ 1 - 1
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)
 	}