Skip to content

Commit

Permalink
Update prometheus/alertmanager to version v0.25.1-0.20230203120921-79…
Browse files Browse the repository at this point in the history
…23bc5f8ec6 (#5276)

Signed-off-by: Krishna Teja Puttagunta <[email protected]>
Signed-off-by: Krishna Teja Puttagunta <[email protected]>
  • Loading branch information
krishnateja325 authored Jun 1, 2023
1 parent f62815f commit fba65a1
Show file tree
Hide file tree
Showing 52 changed files with 2,582 additions and 480 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## master / unreleased
* [CHANGE] Updating prometheus/alertmanager from v0.25.0 to v0.25.1-0.20230505130626-263ca5c9438e. This includes the below changes. #5276
- Validating new fields on the Webhook AM config, PushOver AM Config and Telegram AM Config.
- filtering 5xx Errors in numTotalFailedNotifications metric.
- Delete silence respond with 404 when silence is not found.
- mark webhook URL as a secret.
* [CHANGE] Ruler: Added user label to `cortex_ruler_write_requests_total`, `cortex_ruler_write_requests_failed_total`, `cortex_ruler_queries_total`, and `cortex_ruler_queries_failed_total` metrics. #5312
* [CHANGE] Alertmanager: Validating new fields on the PagerDuty AM config. #5290
* [CHANGE] Ingester: Creating label `native-histogram-sample` on the `cortex_discarded_samples_total` to keep track of discarded native histogram samples. #5289
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ require (
github.com/opentracing-contrib/go-stdlib v1.0.0
github.com/opentracing/opentracing-go v1.2.0
github.com/pkg/errors v0.9.1
github.com/prometheus/alertmanager v0.25.0
github.com/prometheus/alertmanager v0.25.1-0.20230505130626-263ca5c9438e
github.com/prometheus/client_golang v1.15.1
github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.42.0
Expand Down Expand Up @@ -104,7 +104,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.1 // indirect
github.com/aws/smithy-go v1.11.1 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/benbjohnson/clock v1.3.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
Expand All @@ -131,7 +131,7 @@ require (
github.com/go-openapi/runtime v0.25.0 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/gogo/googleapis v1.4.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -149,6 +149,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/jessevdk/go-flags v1.5.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
Expand Down Expand Up @@ -179,7 +180,7 @@ require (
github.com/prometheus/exporter-toolkit v0.10.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/redis/rueidis v1.0.2-go1.18 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/rs/cors v1.9.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/sercand/kuberesolver v2.4.0+incompatible // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,8 @@ github.com/aws/smithy-go v1.11.1/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnw
github.com/baidubce/bce-sdk-go v0.9.111 h1:yGgtPpZYUZW4uoVorQ4xnuEgVeddACydlcJKW87MDV4=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.3 h1:g+rSsSaAzhHJYcIQE78hJ3AhyjjtQvleKDjlhdBnIhc=
github.com/benbjohnson/clock v1.3.3/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down Expand Up @@ -1025,8 +1025,8 @@ github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI=
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU=
Expand Down Expand Up @@ -1266,6 +1266,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.6.0 h1:uL2shRDx7RTrOrTCUZEGP/wJUFiUI8QT6E7z5o8jga4=
github.com/hashicorp/golang-lru v0.6.0/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.2 h1:Dwmkdr5Nc/oBiXgJS3CDHNhJtIHkuZ3DZF5twqnfBdU=
github.com/hashicorp/golang-lru/v2 v2.0.2/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
Expand Down Expand Up @@ -1675,8 +1677,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
github.com/prometheus/alertmanager v0.25.0 h1:vbXKUR6PYRiZPRIKfmXaG+dmCKG52RtPL4Btl8hQGvg=
github.com/prometheus/alertmanager v0.25.0/go.mod h1:MEZ3rFVHqKZsw7IcNS/m4AWZeXThmJhumpiWR4eHU/w=
github.com/prometheus/alertmanager v0.25.1-0.20230505130626-263ca5c9438e h1:bW60vV2VM/YKsXA6dmb3z5XB9+gh/lQBDiZDVrsDhhA=
github.com/prometheus/alertmanager v0.25.1-0.20230505130626-263ca5c9438e/go.mod h1:QtbJShIif+fPgjXVPy3mEJaNebBHSU5NkoFtzsUS1c0=
github.com/prometheus/client_golang v0.0.0-20180209125602-c332b6f63c06/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
Expand Down Expand Up @@ -1753,8 +1755,8 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U=
github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE=
github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
Expand Down
32 changes: 17 additions & 15 deletions pkg/alertmanager/alertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,26 @@ func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
am.state = &NilPeer{}
}

am.wg.Add(1)
var err error
am.nflog, err = nflog.New(
nflog.WithRetention(cfg.Retention),
nflog.WithSnapshot(filepath.Join(cfg.TenantDataDir, notificationLogSnapshot)),
nflog.WithMaintenance(maintenancePeriod, am.stop, am.wg.Done, nil),
nflog.WithMetrics(am.registry),
nflog.WithLogger(log.With(am.logger, "component", "nflog")),
)

notificationFile := filepath.Join(cfg.TenantDataDir, notificationLogSnapshot)
am.nflog, err = nflog.New(nflog.Options{
SnapshotFile: notificationFile,
Retention: cfg.Retention,
Logger: log.With(am.logger, "component", "nflog"),
Metrics: am.registry,
})

if err != nil {
return nil, fmt.Errorf("failed to create notification log: %v", err)
}

c := am.state.AddState("nfl:"+cfg.UserID, am.nflog, am.registry)
am.nflog.SetBroadcast(c.Broadcast)

am.wg.Add(1)
go func() {
am.nflog.Maintenance(maintenancePeriod, notificationFile, am.stop, nil)
am.wg.Done()
}()
am.marker = types.NewMarker(am.registry)

silencesFile := filepath.Join(cfg.TenantDataDir, silencesSnapshot)
Expand All @@ -218,10 +222,8 @@ func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
if err != nil {
return nil, fmt.Errorf("failed to create silences: %v", err)
}

c = am.state.AddState("sil:"+cfg.UserID, am.silences, am.registry)
am.silences.SetBroadcast(c.Broadcast)

// State replication needs to be started after the state keys are defined.
if service, ok := am.state.(services.Service); ok {
if err := service.StartAsync(context.Background()); err != nil {
Expand Down Expand Up @@ -320,7 +322,7 @@ func (am *Alertmanager) ApplyConfig(userID string, conf *config.Config, rawCfg s
templateFiles[i] = templateFilepath
}

tmpl, err := template.FromGlobs(templateFiles...)
tmpl, err := template.FromGlobs(templateFiles)
if err != nil {
return err
}
Expand Down Expand Up @@ -461,7 +463,7 @@ func (am *Alertmanager) getFullState() (*clusterpb.FullState, error) {

// buildIntegrationsMap builds a map of name to the list of integration notifiers off of a
// list of receiver config.
func buildIntegrationsMap(nc []*config.Receiver, tmpl *template.Template, firewallDialer *util_net.FirewallDialer, logger log.Logger, notifierWrapper func(string, notify.Notifier) notify.Notifier) (map[string][]notify.Integration, error) {
func buildIntegrationsMap(nc []config.Receiver, tmpl *template.Template, firewallDialer *util_net.FirewallDialer, logger log.Logger, notifierWrapper func(string, notify.Notifier) notify.Notifier) (map[string][]notify.Integration, error) {
integrationsMap := make(map[string][]notify.Integration, len(nc))
for _, rcv := range nc {
integrations, err := buildReceiverIntegrations(rcv, tmpl, firewallDialer, logger, notifierWrapper)
Expand All @@ -476,7 +478,7 @@ func buildIntegrationsMap(nc []*config.Receiver, tmpl *template.Template, firewa
// buildReceiverIntegrations builds a list of integration notifiers off of a
// receiver config.
// Taken from https://github.com/prometheus/alertmanager/blob/94d875f1227b29abece661db1a68c001122d1da5/cmd/alertmanager/main.go#L112-L159.
func buildReceiverIntegrations(nc *config.Receiver, tmpl *template.Template, firewallDialer *util_net.FirewallDialer, logger log.Logger, wrapper func(string, notify.Notifier) notify.Notifier) ([]notify.Integration, error) {
func buildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, firewallDialer *util_net.FirewallDialer, logger log.Logger, wrapper func(string, notify.Notifier) notify.Notifier) ([]notify.Integration, error) {
var (
errs types.MultiError
integrations []notify.Integration
Expand Down
51 changes: 50 additions & 1 deletion pkg/alertmanager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var (
errOpsGenieAPIKeyFileNotAllowed = errors.New("setting OpsGenie api_key_file is not allowed")
errPagerDutyRoutingKeyFileNotAllowed = errors.New("setting PagerDuty routing_key_file is not allowed")
errPagerDutyServiceKeyFileNotAllowed = errors.New("setting PagerDuty service_key_file is not allowed")
errWebhookURLFileNotAllowed = errors.New("setting Webhook url_file is not allowed")
errPushOverUserKeyFileNotAllowed = errors.New("setting PushOver user_key_file is not allowed")
errPushOverTokenFileNotAllowed = errors.New("setting PushOver token_file is not allowed")
errTelegramBotTokenFileNotAllowed = errors.New("setting Telegram bot_token_file is not allowed")
)

// UserConfig is used to communicate a users alertmanager configs
Expand Down Expand Up @@ -249,7 +253,7 @@ func validateUserConfig(logger log.Logger, cfg alertspb.AlertConfigDesc, limits
templateFiles[i] = filepath.Join(userTempDir, t)
}

_, err = template.FromGlobs(templateFiles...)
_, err = template.FromGlobs(templateFiles)
if err != nil {
return err
}
Expand Down Expand Up @@ -363,6 +367,19 @@ func validateAlertmanagerConfig(cfg interface{}) error {
if err := validatePagerdutyConfig(v.Interface().(config.PagerdutyConfig)); err != nil {
return err
}

case reflect.TypeOf(config.WebhookConfig{}):
if err := validateWebhookConfig(v.Interface().(config.WebhookConfig)); err != nil {
return err
}
case reflect.TypeOf(config.PushoverConfig{}):
if err := validatePushOverConfig(v.Interface().(config.PushoverConfig)); err != nil {
return err
}
case reflect.TypeOf(config.TelegramConfig{}):
if err := validateTelegramConfig(v.Interface().(config.TelegramConfig)); err != nil {
return err
}
}

// If the input config is a struct, recursively iterate on all fields.
Expand Down Expand Up @@ -488,3 +505,35 @@ func validatePagerdutyConfig(cfg config.PagerdutyConfig) error {

return nil
}

// validateWebhookConfig validates the Webhook config and returns an error if it contains
// settings not allowed by Cortex.
func validateWebhookConfig(cfg config.WebhookConfig) error {
if cfg.URLFile != "" {
return errWebhookURLFileNotAllowed
}
return nil
}

// validatePushOverConfig validates the Pushover Config and returns an error if it contains
// settings not allowed by Cortex.
func validatePushOverConfig(cfg config.PushoverConfig) error {
if cfg.UserKeyFile != "" {
return errPushOverUserKeyFileNotAllowed
}

if cfg.TokenFile != "" {
return errPushOverTokenFileNotAllowed
}

return nil
}

// validateTelegramConfig validates the Telegram Config and returns an error if it contains
// settings not allowed by Cortex.
func validateTelegramConfig(cfg config.TelegramConfig) error {
if cfg.BotTokenFile != "" {
return errTelegramBotTokenFileNotAllowed
}
return nil
}
60 changes: 59 additions & 1 deletion pkg/alertmanager/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,64 @@ alertmanager_config: |
`,
err: errors.Wrap(errPagerDutyServiceKeyFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if Webhook url_file is set",
cfg: `
alertmanager_config: |
receivers:
- name: default-receiver
webhook_configs:
- url_file: /urlFile
route:
receiver: 'default-receiver'
`,
err: errors.Wrap(errWebhookURLFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if PushOver user_key_file is set",
cfg: `
alertmanager_config: |
receivers:
- name: default-receiver
pushover_configs:
- user_key_file: /secrets
token: 'token'
route:
receiver: 'default-receiver'
`,
err: errors.Wrap(errPushOverUserKeyFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if PushOver token_file is set",
cfg: `
alertmanager_config: |
receivers:
- name: default-receiver
pushover_configs:
- token_file: /secrets
user_key: 'pushover user'
route:
receiver: 'default-receiver'
`,
err: errors.Wrap(errPushOverTokenFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if Telegram bot_token_file is set",
cfg: `
alertmanager_config: |
receivers:
- name: default-receiver
telegram_configs:
- chat_id: 5
bot_token_file: /secrets
route:
receiver: 'default-receiver'
`,
err: errors.Wrap(errTelegramBotTokenFileNotAllowed, "error validating Alertmanager config"),
},
}

limits := &mockAlertManagerLimits{}
Expand Down Expand Up @@ -810,7 +868,7 @@ func TestValidateAlertmanagerConfig(t *testing.T) {
},
"struct containing *HTTPClientConfig as nested child within a slice": {
input: config.Config{
Receivers: []*config.Receiver{{
Receivers: []config.Receiver{{
Name: "test",
WebhookConfigs: []*config.WebhookConfig{{
HTTPConfig: &commoncfg.HTTPClientConfig{
Expand Down
2 changes: 1 addition & 1 deletion pkg/alertmanager/multitenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ func (am *MultitenantAlertmanager) setConfig(cfg alertspb.AlertConfigDesc) error
return err
}

userAmConfig.Receivers[i].WebhookConfigs[j].URL = &amconfig.URL{URL: u}
userAmConfig.Receivers[i].WebhookConfigs[j].URL = &amconfig.SecretURL{URL: u}
}
}
}
Expand Down
Loading

0 comments on commit fba65a1

Please sign in to comment.