MCPcopy Create free account
hub / github.com/cortexproject/cortex / syncConfigs

Method syncConfigs

pkg/alertmanager/multitenant.go:851–886  ·  view source on GitHub ↗
(cfgs map[string]alertspb.AlertConfigDesc)

Source from the content-addressed store, hash-verified

849}
850
851func (am *MultitenantAlertmanager) syncConfigs(cfgs map[string]alertspb.AlertConfigDesc) {
852 level.Debug(am.logger).Log("msg", "adding configurations", "num_configs", len(cfgs))
853 for user, cfg := range cfgs {
854 err := am.setConfig(cfg)
855 if err != nil {
856 am.multitenantMetrics.lastReloadSuccessful.WithLabelValues(user).Set(float64(0))
857 level.Warn(am.logger).Log("msg", "error applying config", "err", err)
858 continue
859 }
860
861 am.multitenantMetrics.lastReloadSuccessful.WithLabelValues(user).Set(float64(1))
862 am.multitenantMetrics.lastReloadSuccessfulTimestamp.WithLabelValues(user).SetToCurrentTime()
863 }
864
865 userAlertmanagersToStop := map[string]*Alertmanager{}
866
867 am.alertmanagersMtx.Lock()
868 for userID, userAM := range am.alertmanagers {
869 if _, exists := cfgs[userID]; !exists {
870 userAlertmanagersToStop[userID] = userAM
871 delete(am.alertmanagers, userID)
872 delete(am.cfgs, userID)
873 am.multitenantMetrics.lastReloadSuccessful.DeleteLabelValues(userID)
874 am.multitenantMetrics.lastReloadSuccessfulTimestamp.DeleteLabelValues(userID)
875 am.alertmanagerMetrics.removeUserRegistry(userID)
876 }
877 }
878 am.alertmanagersMtx.Unlock()
879
880 // Now stop alertmanagers and wait until they are really stopped, without holding lock.
881 for userID, userAM := range userAlertmanagersToStop {
882 level.Info(am.logger).Log("msg", "deactivating per-tenant alertmanager", "user", userID)
883 userAM.StopAndWait()
884 level.Info(am.logger).Log("msg", "deactivated per-tenant alertmanager", "user", userID)
885 }
886}
887
888// setConfig applies the given configuration to the alertmanager for `userID`,
889// creating an alertmanager if it doesn't already exist.

Callers 1

loadAndSyncConfigsMethod · 0.95

Calls 5

setConfigMethod · 0.95
removeUserRegistryMethod · 0.80
StopAndWaitMethod · 0.80
SetMethod · 0.65
LogMethod · 0.45

Tested by

no test coverage detected