Skip to content

Commit

Permalink
not allow to configure AM experimental features
Browse files Browse the repository at this point in the history
Signed-off-by: alanprot <alanprot@gmail.com>
  • Loading branch information
alanprot committed Apr 2, 2024
1 parent 844d501 commit f5328df
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 125 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* [FEATURE] Ruler: Add `ruler.concurrent-evals-enabled` flag to enable concurrent evaluation within a single rule group for independent rules. Maximum concurrency can be configured via `ruler.max-concurrent-evals`. #5766
* [FEATURE] Distributor Queryable: Experimental: Add config `zone_results_quorum_metadata`. When querying ingesters using metadata APIs such as label names and values, only results from quorum number of zones will be included and merged. #5779
* [FEATURE] Storage Cache Clients: Add config `set_async_circuit_breaker_config` to utilize the circuit breaker pattern for dynamically thresholding asynchronous set operations. Implemented in both memcached and redis cache clients. #5789
* [FEATURE] Alert Manager: Add support for the new AM `alertmanager.enable-feature` experimental flag. #5841
* [ENHANCEMENT] Store Gateway: Added `-store-gateway.enabled-tenants` and `-store-gateway.disabled-tenants` to explicitly enable or disable store-gateway for specific tenants. #5638
* [ENHANCEMENT] Compactor: Add new compactor metric `cortex_compactor_start_duration_seconds`. #5683
* [ENHANCEMENT] Upgraded Docker base images to `alpine:3.18`. #5684
Expand Down
5 changes: 0 additions & 5 deletions docs/configuration/config-file-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,6 @@ The `alertmanager_config` configures the Cortex alertmanager.
# CLI flag: -alertmanager.max-recv-msg-size
[max_recv_msg_size: <int> | default = 16777216]
# Comma separated list of prometheus alertManager features to enable. Valid
# options: receiver-name-in-metrics, classic-mode, utf8-strict-mode
# CLI flag: -alertmanager.enable-feature
[enable_feature: <string> | default = ""]
# Shard tenants across multiple alertmanager instances.
# CLI flag: -alertmanager.sharding-enabled
[sharding_enabled: <boolean> | default = false]
Expand Down
30 changes: 0 additions & 30 deletions integration/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,6 @@ func TestAlertmanagerSharding(t *testing.T) {
assert.Equal(t, comment(3), ids[id3].Comment)
assert.Equal(t, s3, ids[id3].Status.State)
}

// Endpoint: GET /v1/silences
{
for _, c := range clients {
list, err := c.GetSilencesV1(context.Background())
require.NoError(t, err)
assertSilences(list, types.SilenceStateActive, types.SilenceStateActive, types.SilenceStateActive)
}
}

// Endpoint: GET /v2/silences
{
for _, c := range clients {
Expand All @@ -379,26 +369,6 @@ func TestAlertmanagerSharding(t *testing.T) {
}
}

// Endpoint: GET /v1/silence/{id}
{
for _, c := range clients {
sil1, err := c.GetSilenceV1(context.Background(), id1)
require.NoError(t, err)
assert.Equal(t, comment(1), sil1.Comment)
assert.Equal(t, types.SilenceStateActive, sil1.Status.State)

sil2, err := c.GetSilenceV1(context.Background(), id2)
require.NoError(t, err)
assert.Equal(t, comment(2), sil2.Comment)
assert.Equal(t, types.SilenceStateActive, sil2.Status.State)

sil3, err := c.GetSilenceV1(context.Background(), id3)
require.NoError(t, err)
assert.Equal(t, comment(3), sil3.Comment)
assert.Equal(t, types.SilenceStateActive, sil3.Status.State)
}
}

// Endpoint: GET /v2/silence/{id}
{
for _, c := range clients {
Expand Down
76 changes: 0 additions & 76 deletions integration/e2ecortex/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,44 +871,6 @@ func (c *Client) CreateSilence(ctx context.Context, silence types.Silence) (stri
return decoded.Data.SilenceID, nil
}

func (c *Client) GetSilencesV1(ctx context.Context) ([]types.Silence, error) {
u := c.alertmanagerClient.URL("api/prom/api/v1/silences", nil)

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return nil, fmt.Errorf("error creating request: %v", err)
}

resp, body, err := c.alertmanagerClient.Do(ctx, req)
if err != nil {
return nil, err
}

if resp.StatusCode == http.StatusNotFound {
return nil, ErrNotFound
}

if resp.StatusCode/100 != 2 {
return nil, fmt.Errorf("getting silences failed with status %d and error %v", resp.StatusCode, string(body))
}

type response struct {
Status string `json:"status"`
Data []types.Silence `json:"data"`
}

decoded := &response{}
if err := json.Unmarshal(body, decoded); err != nil {
return nil, err
}

if decoded.Status != "success" {
return nil, fmt.Errorf("unexpected response status '%s'", decoded.Status)
}

return decoded.Data, nil
}

func (c *Client) GetSilencesV2(ctx context.Context) ([]types.Silence, error) {
u := c.alertmanagerClient.URL("api/prom/api/v2/silences", nil)

Expand Down Expand Up @@ -938,44 +900,6 @@ func (c *Client) GetSilencesV2(ctx context.Context) ([]types.Silence, error) {
return decoded, nil
}

func (c *Client) GetSilenceV1(ctx context.Context, id string) (types.Silence, error) {
u := c.alertmanagerClient.URL(fmt.Sprintf("api/prom/api/v1/silence/%s", url.PathEscape(id)), nil)

req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return types.Silence{}, fmt.Errorf("error creating request: %v", err)
}

resp, body, err := c.alertmanagerClient.Do(ctx, req)
if err != nil {
return types.Silence{}, err
}

if resp.StatusCode == http.StatusNotFound {
return types.Silence{}, ErrNotFound
}

if resp.StatusCode/100 != 2 {
return types.Silence{}, fmt.Errorf("getting silence failed with status %d and error %v", resp.StatusCode, string(body))
}

type response struct {
Status string `json:"status"`
Data types.Silence `json:"data"`
}

decoded := &response{}
if err := json.Unmarshal(body, decoded); err != nil {
return types.Silence{}, err
}

if decoded.Status != "success" {
return types.Silence{}, fmt.Errorf("unexpected response status '%s'", decoded.Status)
}

return decoded.Data, nil
}

func (c *Client) GetSilenceV2(ctx context.Context, id string) (types.Silence, error) {
u := c.alertmanagerClient.URL(fmt.Sprintf("api/prom/api/v2/silence/%s", url.PathEscape(id)), nil)

Expand Down
5 changes: 2 additions & 3 deletions pkg/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ type Config struct {
PersisterConfig PersisterConfig
APIConcurrency int
GCInterval time.Duration

FeatureFlags string
}

// An Alertmanager manages the alerts for one user.
Expand Down Expand Up @@ -247,7 +245,8 @@ func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
}
}

featureConfig, err := featurecontrol.NewFlags(am.logger, cfg.FeatureFlags)
// Lets not enable any AM experimental feature for now.
featureConfig, err := featurecontrol.NewFlags(am.logger, "")
if err != nil {
level.Error(am.logger).Log("msg", "error parsing the feature flag list", "err", err)
return nil, errors.Wrap(err, "error parsing the feature flag list")
Expand Down
14 changes: 5 additions & 9 deletions pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/prometheus/alertmanager/cluster"
"github.com/prometheus/alertmanager/cluster/clusterpb"
amconfig "github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/featurecontrol"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
tsdb_errors "github.com/prometheus/prometheus/tsdb/errors"
Expand Down Expand Up @@ -65,12 +64,11 @@ var (

// MultitenantAlertmanagerConfig is the configuration for a multitenant Alertmanager.
type MultitenantAlertmanagerConfig struct {
DataDir string `yaml:"data_dir"`
Retention time.Duration `yaml:"retention"`
ExternalURL flagext.URLValue `yaml:"external_url"`
PollInterval time.Duration `yaml:"poll_interval"`
MaxRecvMsgSize int64 `yaml:"max_recv_msg_size"`
EnableFeature flagext.StringSliceCSV `yaml:"enable_feature"`
DataDir string `yaml:"data_dir"`
Retention time.Duration `yaml:"retention"`
ExternalURL flagext.URLValue `yaml:"external_url"`
PollInterval time.Duration `yaml:"poll_interval"`
MaxRecvMsgSize int64 `yaml:"max_recv_msg_size"`

// Enable sharding for the Alertmanager
ShardingEnabled bool `yaml:"sharding_enabled"`
Expand Down Expand Up @@ -127,7 +125,6 @@ func (cfg *MultitenantAlertmanagerConfig) RegisterFlags(f *flag.FlagSet) {
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.")
f.Var(&cfg.EnableFeature, "alertmanager.enable-feature", fmt.Sprintf("Comma separated list of prometheus alertManager features to enable. Valid options: %s", strings.Join(featurecontrol.AllowedFlags, ", ")))

cfg.AlertmanagerClient.RegisterFlagsWithPrefix("alertmanager.alertmanager-client", f)
cfg.Persister.RegisterFlagsWithPrefix("alertmanager", f)
Expand Down Expand Up @@ -981,7 +978,6 @@ func (am *MultitenantAlertmanager) newAlertmanager(userID string, amConfig *amco
Limits: am.limits,
APIConcurrency: am.cfg.APIConcurrency,
GCInterval: am.cfg.GCInterval,
FeatureFlags: am.cfg.EnableFeature.String(),
}, 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 @@ -979,7 +979,7 @@ receivers:
defer services.StopAndAwaitTerminated(ctx, am) //nolint:errcheck

// Request when no user configuration is present.
req := httptest.NewRequest("GET", externalURL.String()+"/api/v1/status", nil)
req := httptest.NewRequest("GET", externalURL.String()+"/api/v2/status", nil)
w := httptest.NewRecorder()

am.ServeHTTP(w, req.WithContext(user.InjectOrgID(req.Context(), "user1")))
Expand Down

0 comments on commit f5328df

Please sign in to comment.