Alerting: unwrap AMConfigV1 in PostableAPIConfigToNotificationsConfiguration (#125864)

Pass PostableApiAlertingConfig and []TemplateGroup directly instead of
the *AMConfigV1 wrapper, so callers control template selection.
This commit is contained in:
Yuri Tseretyan
2026-06-03 17:45:56 -04:00
committed by GitHub
parent dd9549b8ae
commit e0f34feefe
3 changed files with 12 additions and 8 deletions
@@ -154,7 +154,7 @@ func (moa *MultiOrgAlertmanager) PrepareConfig(
prepared.AlertmanagerConfig = preparedConfig
return PostableAPIConfigToNotificationsConfiguration(prepared, moa.limits)
return PostableAPIConfigToNotificationsConfiguration(prepared.AlertmanagerConfig, prepared.SortedTemplates(true), moa.limits)
}
func (moa *MultiOrgAlertmanager) SaveAndApplyDefaultConfig(ctx context.Context, orgId int64) error {
+10 -6
View File
@@ -57,16 +57,20 @@ func IntegrationToIntegrationConfig(i models.Integration) (alertingModels.Integr
}, nil
}
func PostableAPIConfigToNotificationsConfiguration(c *v1.AMConfigV1, limits alertingNotify.DynamicLimits) (alertingNotify.NotificationsConfiguration, error) {
receivers, err := ModelToAPIReceivers(c.AlertmanagerConfig.Receivers)
func PostableAPIConfigToNotificationsConfiguration(
cfg v1.PostableApiAlertingConfig,
tmpls []v1.TemplateGroup,
limits alertingNotify.DynamicLimits,
) (alertingNotify.NotificationsConfiguration, error) {
receivers, err := ModelToAPIReceivers(cfg.Receivers)
if err != nil {
return alertingNotify.NotificationsConfiguration{}, err
}
return alertingNotify.NotificationsConfiguration{
RoutingTree: RouteToAPI(c.AlertmanagerConfig.Route),
InhibitRules: c.AlertmanagerConfig.InhibitRules,
TimeIntervals: ModelToTimeIntervals(c.AlertmanagerConfig.TimeIntervals, c.AlertmanagerConfig.MuteTimeIntervals),
Templates: ModelToTemplateDefinitions(c.SortedTemplates(true)),
RoutingTree: RouteToAPI(cfg.Route),
InhibitRules: cfg.InhibitRules,
TimeIntervals: ModelToTimeIntervals(cfg.TimeIntervals, cfg.MuteTimeIntervals),
Templates: ModelToTemplateDefinitions(tmpls),
Receivers: receivers,
Limits: limits,
}, nil
+1 -1
View File
@@ -247,7 +247,7 @@ func NewAlertmanager(
return fmt.Errorf("unable to add autogenerated routes: %w", err)
}
nc, err := notifier.PostableAPIConfigToNotificationsConfiguration(parsed, alertingNotify.DynamicLimits{})
nc, err := notifier.PostableAPIConfigToNotificationsConfiguration(parsed.AlertmanagerConfig, parsed.SortedTemplates(true), alertingNotify.DynamicLimits{})
if err != nil {
return fmt.Errorf("unable to convert default configuration: %w", err)
}