@ -18,6 +18,7 @@ import (
gokit_log "github.com/go-kit/kit/log"
amv2 "github.com/prometheus/alertmanager/api/v2/models"
"github.com/prometheus/alertmanager/cluster"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/dispatch"
"github.com/prometheus/alertmanager/inhibit"
"github.com/prometheus/alertmanager/nflog"
@ -26,6 +27,7 @@ import (
"github.com/prometheus/alertmanager/provider/mem"
"github.com/prometheus/alertmanager/silence"
"github.com/prometheus/alertmanager/template"
"github.com/prometheus/alertmanager/timeinterval"
"github.com/prometheus/alertmanager/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
@ -110,6 +112,10 @@ type Alertmanager struct {
silencer * silence . Silencer
silences * silence . Silences
// muteTimes is a map where the key is the name of the mute_time_interval
// and the value represents all configured time_interval(s)
muteTimes map [ string ] [ ] timeinterval . TimeInterval
stageMetrics * notify . Metrics
dispatcherMetrics * dispatch . DispatcherMetrics
@ -329,6 +335,14 @@ func (am *Alertmanager) templateFromPaths(paths ...string) (*template.Template,
return tmpl , nil
}
func ( am * Alertmanager ) buildMuteTimesMap ( muteTimeIntervals [ ] config . MuteTimeInterval ) map [ string ] [ ] timeinterval . TimeInterval {
muteTimes := make ( map [ string ] [ ] timeinterval . TimeInterval , len ( muteTimeIntervals ) )
for _ , ti := range muteTimeIntervals {
muteTimes [ ti . Name ] = ti . TimeIntervals
}
return muteTimes
}
// applyConfig applies a new configuration by re-initializing all components using the configuration provided.
// It is not safe to call concurrently.
func ( am * Alertmanager ) applyConfig ( cfg * apimodels . PostableUserConfig , rawConfig [ ] byte ) ( err error ) {
@ -375,6 +389,7 @@ func (am *Alertmanager) applyConfig(cfg *apimodels.PostableUserConfig, rawConfig
if err != nil {
return fmt . Errorf ( "failed to build integration map: %w" , err )
}
// Now, let's put together our notification pipeline
routingStage := make ( notify . RoutingStage , len ( integrationsMap ) )
@ -386,14 +401,16 @@ func (am *Alertmanager) applyConfig(cfg *apimodels.PostableUserConfig, rawConfig
}
am . inhibitor = inhibit . NewInhibitor ( am . alerts , cfg . AlertmanagerConfig . InhibitRules , am . marker , am . gokitLogger )
am . muteTimes = am . buildMuteTimesMap ( cfg . AlertmanagerConfig . MuteTimeIntervals )
am . silencer = silence . NewSilencer ( am . silences , am . marker , am . gokitLogger )
meshStage := notify . NewGossipSettleStage ( am . peer )
inhibitionStage := notify . NewMuteStage ( am . inhibitor )
timeMuteStage := notify . NewTimeMuteStage ( am . muteTimes )
silencingStage := notify . NewMuteStage ( am . silencer )
for name := range integrationsMap {
stage := am . createReceiverStage ( name , integrationsMap [ name ] , am . waitFunc , am . notificationLog )
routingStage [ name ] = notify . MultiStage { meshStage , silencingStage , inhibitionStage , stage }
routingStage [ name ] = notify . MultiStage { meshStage , silencingStage , timeMuteStage , inhibitionStage , stage }
}
am . route = dispatch . NewRoute ( cfg . AlertmanagerConfig . Route . AsAMRoute ( ) , nil )