Skip to content

Commit

Permalink
Making GCInterval Configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Teja Puttagunta <krishnateja325@gmail.com>
  • Loading branch information
krishnateja325 committed Sep 6, 2023
1 parent 7b9db50 commit bd5dfa2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## master / unreleased
* [FEATURE] Added the flag `-alertmanager.alerts-gc-interval` to configure alert manager alerts Garbage collection interval. #5550
* [FEATURE] Ruler: Add support for Limit field on RuleGroup. #5528
* [FEATURE] AlertManager: Add support for Webex, Discord and Telegram Receiver. #5493
* [FEATURE] Ingester: added `-admin-limit-message` to customize the message contained in limit errors.#5460
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ cluster:
# CLI flag: -alertmanager.api-concurrency
[api_concurrency: <int> | default = 0]
# Alertmanager alerts Garbage collection interval.
# CLI flag: -alertmanager.alerts-gc-interval
[gc_interval: <duration> | default = 30m]
alertmanager_client:
# Timeout for downstream alertmanagers.
# CLI flag: -alertmanager.alertmanager-client.remote-timeout
Expand Down
4 changes: 2 additions & 2 deletions pkg/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type Config struct {
Store alertstore.AlertStore
PersisterConfig PersisterConfig
APIConcurrency int
GCInterval time.Duration
}

// An Alertmanager manages the alerts for one user.
Expand Down Expand Up @@ -254,8 +255,7 @@ func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
if am.cfg.Limits != nil {
callback = newAlertsLimiter(am.cfg.UserID, am.cfg.Limits, reg)
}

am.alerts, err = mem.NewAlerts(context.Background(), am.marker, 30*time.Minute, callback, am.logger, am.registry)
am.alerts, err = mem.NewAlerts(context.Background(), am.marker, am.cfg.GCInterval, callback, am.logger, am.registry)
if err != nil {
return nil, fmt.Errorf("failed to create alerts: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/alertmanager/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func createAlertmanagerAndSendAlerts(t *testing.T, alertGroups, groupsLimit, exp
TenantDataDir: t.TempDir(),
ExternalURL: &url.URL{Path: "/am"},
ShardingEnabled: false,
GCInterval: 30 * time.Minute,
}, reg)
require.NoError(t, err)
defer am.StopAndWait()
Expand Down
8 changes: 5 additions & 3 deletions pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ type MultitenantAlertmanagerConfig struct {

Cluster ClusterConfig `yaml:"cluster"`

EnableAPI bool `yaml:"enable_api"`
APIConcurrency int `yaml:"api_concurrency"`
EnableAPI bool `yaml:"enable_api"`
APIConcurrency int `yaml:"api_concurrency"`
GCInterval time.Duration `yaml:"gc_interval"`

// For distributor.
AlertmanagerClient ClientConfig `yaml:"alertmanager_client"`
Expand Down Expand Up @@ -119,7 +120,7 @@ func (cfg *MultitenantAlertmanagerConfig) RegisterFlags(f *flag.FlagSet) {

f.BoolVar(&cfg.EnableAPI, "experimental.alertmanager.enable-api", false, "Enable the experimental alertmanager config api.")
f.IntVar(&cfg.APIConcurrency, "alertmanager.api-concurrency", 0, "Maximum number of concurrent GET API requests before returning an error.")

f.DurationVar(&cfg.GCInterval, "alertmanager.alerts-gc-interval", 30*time.Minute, "Alertmanager alerts Garbage collection interval.")
f.BoolVar(&cfg.ShardingEnabled, "alertmanager.sharding-enabled", false, "Shard tenants across multiple alertmanager instances.")
f.Var(&cfg.EnabledTenants, "alertmanager.enabled-tenants", "Comma separated list of tenants whose alerts this alertmanager can process. If specified, only these tenants will be handled by alertmanager, otherwise this alertmanager can process alerts from all tenants.")
f.Var(&cfg.DisabledTenants, "alertmanager.disabled-tenants", "Comma separated list of tenants whose alerts this alertmanager cannot process. If specified, a alertmanager that would normally pick the specified tenant(s) for processing will ignore them instead.")
Expand Down Expand Up @@ -969,6 +970,7 @@ func (am *MultitenantAlertmanager) newAlertmanager(userID string, amConfig *amco
PersisterConfig: am.cfg.Persister,
Limits: am.limits,
APIConcurrency: am.cfg.APIConcurrency,
GCInterval: am.cfg.GCInterval,
}, reg)
if err != nil {
return nil, fmt.Errorf("unable to start Alertmanager for user %v: %v", userID, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/alertmanager/multitenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func mockAlertmanagerConfig(t *testing.T) *MultitenantAlertmanagerConfig {
cfg.ShardingRing.InstanceAddr = "127.0.0.1"
cfg.PollInterval = time.Minute
cfg.ShardingRing.FinalSleep = 0

cfg.GCInterval = 30 * time.Minute
return cfg
}

Expand Down

0 comments on commit bd5dfa2

Please sign in to comment.