MCPcopy Index your code
hub / github.com/cortexproject/cortex / SetRulesConfig

Method SetRulesConfig

pkg/configs/db/postgres/postgres.go:207–228  ·  view source on GitHub ↗

SetRulesConfig sets the current alertmanager config for a user.

(ctx context.Context, userID string, oldConfig, newConfig userconfig.RulesConfig)

Source from the content-addressed store, hash-verified

205
206// SetRulesConfig sets the current alertmanager config for a user.
207func (d DB) SetRulesConfig(ctx context.Context, userID string, oldConfig, newConfig userconfig.RulesConfig) (bool, error) {
208 updated := false
209 err := d.Transaction(func(tx DB) error {
210 current, err := d.GetConfig(ctx, userID)
211 if err != nil && err != sql.ErrNoRows {
212 return err
213 }
214 // The supplied oldConfig must match the current config. If no config
215 // exists, then oldConfig must be nil. Otherwise, it must exactly
216 // equal the existing config.
217 if !((err == sql.ErrNoRows && oldConfig.Files == nil) || oldConfig.Equal(current.Config.RulesConfig)) { //nolint:staticcheck
218 return nil
219 }
220 new := userconfig.Config{
221 AlertmanagerConfig: current.Config.AlertmanagerConfig,
222 RulesConfig: newConfig,
223 }
224 updated = true
225 return d.SetConfig(ctx, userID, new)
226 })
227 return updated, err
228}
229
230// findRulesConfigs helps GetAllRulesConfigs and GetRulesConfigs retrieve the
231// set of all active rules configurations across all our users.

Callers

nothing calls this directly

Implementers 4

timedpkg/configs/db/timed.go
tracedpkg/configs/db/traced.go
DBpkg/configs/db/postgres/postgres.go
DBpkg/configs/db/memory/memory.go

Calls 4

TransactionMethod · 0.95
GetConfigMethod · 0.95
SetConfigMethod · 0.95
EqualMethod · 0.65

Tested by

no test coverage detected