in alertmanager/client/client.go [194:239]
func (c *client) ModifyTenantRoute(tenantID string, route *config.Route) error {
c.Lock()
defer c.Unlock()
conf, err := c.readConfigFile()
if err != nil {
return err
}
// ensure base route is valid base route for this tenant
baseRoute := c.getBaseRouteForTenant(tenantID, conf)
if route.Receiver != baseRoute.Receiver {
return fmt.Errorf("route base receiver is incorrect (should be \"%s\"). "+
"The base node should match nothing, then add routes as children of the base node", baseRoute.Receiver)
}
if route.Match == nil {
route.Match = map[string]string{}
}
if c.conf.Tenancy.RestrictorLabel != "" {
route.Match[c.conf.Tenancy.RestrictorLabel] = tenantID
}
for _, childRoute := range route.Routes {
if childRoute == nil {
continue
}
secureRoute(tenantID, childRoute)
}
tenantRouteIdx := conf.GetRouteIdx(config.MakeBaseRouteName(tenantID))
if tenantRouteIdx < 0 {
err := conf.InitializeNetworkBaseRoute(route, c.conf.Tenancy.RestrictorLabel, tenantID)
if err != nil {
return err
}
} else {
conf.Route.Routes[tenantRouteIdx] = route
}
err = conf.Validate()
if err != nil {
return err
}
return c.writeConfigFile(conf)
}