mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AlertingNG: Fix the alerting stage for legacy alerts (#32025)
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
This commit is contained in:
@@ -32,6 +32,9 @@ type AlertProvider struct {
|
||||
stage notify.Stage
|
||||
}
|
||||
|
||||
// NewAlertProvider returns AlertProvider that also supports legacy alerts via PutPostableAlert.
|
||||
// The notify.Stage should be of the type notify.RoutingStage or something similar that takes
|
||||
// notification channel name from the context.
|
||||
func NewAlertProvider(s notify.Stage, m types.Marker, l log.Logger) (*AlertProvider, error) {
|
||||
alerts, err := mem.NewAlerts(context.Background(), m, 30*time.Minute, l)
|
||||
if err != nil {
|
||||
|
||||
@@ -39,14 +39,6 @@ type Alertmanager struct {
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
type WithReceiverStage struct {
|
||||
}
|
||||
|
||||
func (s *WithReceiverStage) Exec(ctx context.Context, l gokit_log.Logger, alerts ...*types.Alert) (context.Context, []*types.Alert, error) {
|
||||
//TODO: Alerts with a receiver should be handled here.
|
||||
return ctx, nil, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
registry.RegisterService(&Alertmanager{})
|
||||
}
|
||||
@@ -66,11 +58,6 @@ func (am *Alertmanager) Run(ctx context.Context) error {
|
||||
am.marker = types.NewMarker(prometheus.DefaultRegisterer)
|
||||
|
||||
var err error
|
||||
am.alerts, err = NewAlertProvider(&WithReceiverStage{}, am.marker, gokit_log.NewNopLogger())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize alerting storage component")
|
||||
}
|
||||
|
||||
am.silences, err = silence.New(silence.Options{
|
||||
SnapshotFile: filepath.Join("dir", "silences"), //TODO: This is a setting
|
||||
Retention: time.Hour * 24, //TODO: This is also a setting
|
||||
@@ -98,6 +85,12 @@ func (am *Alertmanager) Run(ctx context.Context) error {
|
||||
stage := createReceiverStage(name, receivers[name], waitFunc, am.notificationLog)
|
||||
routingStage[name] = notify.MultiStage{silencingStage, stage}
|
||||
}
|
||||
|
||||
am.alerts, err = NewAlertProvider(routingStage, am.marker, gokit_log.NewNopLogger())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize alerting storage component")
|
||||
}
|
||||
|
||||
am.dispatcher = dispatch.NewDispatcher(am.alerts, BuildRoutingConfiguration(), routingStage, am.marker, timeoutFunc, gokit_log.NewNopLogger(), nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user