Chore: Remove bus from the alerting service (#44496)
* propagate notificationservice down to the notifiers * replace dispatch in result handler * remove dispatch from the rule reader * remove dispatch from eval context * remove dispatch from alerting usage * remove dispatch from alerting usage * remove dispatch from notifier * attempt to fix tests in alerting * hello linter, my old friend; also disable some tests for now * use mocks to fix the tests * resolving wire providers * make linter happy * remove yet another bus.dispatch * fix tests using store mock
This commit is contained in:
@@ -5,10 +5,10 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/services/notifications"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
@@ -37,14 +37,14 @@ const (
|
||||
)
|
||||
|
||||
// NewLINENotifier is the constructor for the LINE notifier
|
||||
func NewLINENotifier(model *models.AlertNotification, fn alerting.GetDecryptedValueFn) (alerting.Notifier, error) {
|
||||
func NewLINENotifier(model *models.AlertNotification, fn alerting.GetDecryptedValueFn, ns notifications.Service) (alerting.Notifier, error) {
|
||||
token := fn(context.Background(), model.SecureSettings, "token", model.Settings.Get("token").MustString(), setting.SecretKey)
|
||||
if token == "" {
|
||||
return nil, alerting.ValidationError{Reason: "Could not find token in settings"}
|
||||
}
|
||||
|
||||
return &LineNotifier{
|
||||
NotifierBase: NewNotifierBase(model),
|
||||
NotifierBase: NewNotifierBase(model, ns),
|
||||
Token: token,
|
||||
log: log.New("alerting.notifier.line"),
|
||||
}, nil
|
||||
@@ -92,7 +92,7 @@ func (ln *LineNotifier) createAlert(evalContext *alerting.EvalContext) error {
|
||||
Body: form.Encode(),
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(evalContext.Ctx, cmd); err != nil {
|
||||
if err := ln.NotificationService.SendWebhookSync(evalContext.Ctx, cmd); err != nil {
|
||||
ln.log.Error("Failed to send notification to LINE", "error", err, "body", body)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user