1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
configCoordinator := config.NewCoordinator( *configFile, prometheus.DefaultRegisterer, configLogger, ) configCoordinator.Subscribe(func(conf *config.Config) error { tmpl, err = template.FromGlobs(conf.Templates) if err != nil { return fmt.Errorf("failed to parse templates: %w", err) } tmpl.ExternalURL = amURL
routes := dispatch.NewRoute(conf.Route, nil) activeReceivers := make(map[string]struct{}) routes.Walk(func(r *dispatch.Route) { activeReceivers[r.RouteOpts.Receiver] = struct{}{} })
receivers := make(map[string][]notify.Integration, len(activeReceivers)) var integrationsNum int for _, rcv := range conf.Receivers { if _, found := activeReceivers[rcv.Name]; !found { configLogger.Info("skipping creation of receiver not referenced by any route", "receiver", rcv.Name) continue } integrations, err := receiver.BuildReceiverIntegrations(rcv, tmpl, logger) if err != nil { return err } receivers[rcv.Name] = integrations integrationsNum += len(integrations) }
timeIntervals := make(map[string][]timeinterval.TimeInterval, len(conf.MuteTimeIntervals)+len(conf.TimeIntervals)) for _, ti := range conf.MuteTimeIntervals { timeIntervals[ti.Name] = ti.TimeIntervals }
for _, ti := range conf.TimeIntervals { timeIntervals[ti.Name] = ti.TimeIntervals }
intervener := timeinterval.NewIntervener(timeIntervals)
inhibitor.Stop() disp.Stop()
inhibitor = inhibit.NewInhibitor(alerts, conf.InhibitRules, marker, logger) silencer := silence.NewSilencer(silences, marker, logger)
var pipelinePeer notify.Peer if peer != nil { pipelinePeer = peer }
pipeline := pipelineBuilder.New( receivers, waitFunc, inhibitor, silencer, intervener, marker, notificationLog, pipelinePeer, )
configuredReceivers.Set(float64(len(activeReceivers))) configuredIntegrations.Set(float64(integrationsNum)) configuredInhibitionRules.Set(float64(len(conf.InhibitRules)))
api.Update(conf, func(labels model.LabelSet) { inhibitor.Mutes(labels) silencer.Mutes(labels) })
disp = dispatch.NewDispatcher(alerts, routes, pipeline, marker, timeoutFunc, nil, logger, dispMetrics) routes.Walk(func(r *dispatch.Route) { if r.RouteOpts.RepeatInterval > *retention { configLogger.Warn( "repeat_interval is greater than the data retention period. It can lead to notifications being repeated more often than expected.", "repeat_interval", r.RouteOpts.RepeatInterval, "retention", *retention, "route", r.Key(), ) }
if r.RouteOpts.RepeatInterval < r.RouteOpts.GroupInterval { configLogger.Warn( "repeat_interval is less than group_interval. Notifications will not repeat until the next group_interval.", "repeat_interval", r.RouteOpts.RepeatInterval, "group_interval", r.RouteOpts.GroupInterval, "route", r.Key(), ) } })
go disp.Run() go inhibitor.Run()
return nil })
if err := configCoordinator.Reload(); err != nil { return 1 }
|