Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable logging of migration data when UTF-8 Strict Mode is enabled #9076

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/alertmanager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (am *MultitenantAlertmanager) SetUserConfig(w http.ResponseWriter, r *http.
}

cfgDesc := alertspb.ToProto(cfg.AlertmanagerConfig, cfg.TemplateFiles, userID)
if err := validateUserConfig(logger, cfgDesc, am.limits, userID); err != nil {
if err := validateUserConfig(logger, cfgDesc, am.limits, userID, am.cfg.UTF8StrictMode); err != nil {
level.Warn(logger).Log("msg", errValidatingConfig, "err", err.Error())
http.Error(w, fmt.Sprintf("%s: %s", errValidatingConfig, err.Error()), http.StatusBadRequest)
return
Expand Down Expand Up @@ -185,8 +185,10 @@ func (am *MultitenantAlertmanager) DeleteUserConfig(w http.ResponseWriter, r *ht
}

// Partially copied from: https://github.com/prometheus/alertmanager/blob/8e861c646bf67599a1704fc843c6a94d519ce312/cli/check_config.go#L65-L96
func validateUserConfig(logger log.Logger, cfg alertspb.AlertConfigDesc, limits Limits, user string) error {
validateMatchersInConfigDesc(logger, "api", cfg)
func validateUserConfig(logger log.Logger, cfg alertspb.AlertConfigDesc, limits Limits, user string, utf8StrictMode bool) error {
if !utf8StrictMode {
validateMatchersInConfigDesc(logger, "api", cfg)
}

// We don't have a valid use case for empty configurations. If a tenant does not have a
// configuration set and issue a request to the Alertmanager, we'll a) upload an empty
Expand Down
1 change: 1 addition & 0 deletions pkg/alertmanager/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ alertmanager_config: |

limits := &mockAlertManagerLimits{}
am := &MultitenantAlertmanager{
cfg: &MultitenantAlertmanagerConfig{},
store: prepareInMemoryAlertStore(),
logger: test.NewTestingLogger(t),
limits: limits,
Expand Down
14 changes: 8 additions & 6 deletions pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,12 +806,14 @@ type amConfig struct {
// setConfig applies the given configuration to the alertmanager for `userID`,
// creating an alertmanager if it doesn't already exist.
func (am *MultitenantAlertmanager) setConfig(cfg amConfig) error {
// Instead of using "config" as the origin, as in Prometheus Alertmanager, we use "tenant".
// The reason for this that the config.Load function uses the origin "config",
// which is correct, but Mimir uses config.Load to validate both API requests and tenant
// configurations. This means metrics from API requests are confused with metrics from
// tenant configurations. To avoid this confusion, we use a different origin.
validateMatchersInConfigDesc(am.logger, "tenant", cfg.AlertConfigDesc)
if !am.cfg.UTF8StrictMode {
// Instead of using "config" as the origin, as in Prometheus Alertmanager, we use "tenant".
// The reason for this that the config.Load function uses the origin "config",
// which is correct, but Mimir uses config.Load to validate both API requests and tenant
// configurations. This means metrics from API requests are confused with metrics from
// tenant configurations. To avoid this confusion, we use a different origin.
validateMatchersInConfigDesc(am.logger, "tenant", cfg.AlertConfigDesc)
}

level.Debug(am.logger).Log("msg", "setting config", "user", cfg.User)

Expand Down
Loading