AlertingNG: Fix the alerting stage for legacy alerts (#32025)

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
This commit is contained in:
Ganesh Vernekar
2021-03-17 22:08:33 +05:30
committed by GitHub
parent 866912d62c
commit 974ccf8091
2 changed files with 9 additions and 13 deletions

View File

@@ -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 {

View File

@@ -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)
}