From df15618d58d89abb6a2e0b9a70c2fb8011a007f7 Mon Sep 17 00:00:00 2001 From: Tito Lins Date: Fri, 20 Sep 2024 02:25:32 +0200 Subject: [PATCH 1/7] use tlsConfig to send webhooks --- pkg/alertmanager/sender.go | 40 +++++++++++-------- .../grafana/alerting/receivers/webhook.go | 6 ++- .../alerting/receivers/webhook/config.go | 16 +++++++- .../alerting/receivers/webhook/webhook.go | 9 +++++ 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/pkg/alertmanager/sender.go b/pkg/alertmanager/sender.go index 1a3fa42a472..a6c81d165e9 100644 --- a/pkg/alertmanager/sender.go +++ b/pkg/alertmanager/sender.go @@ -29,27 +29,11 @@ var ( ) type Sender struct { - c *http.Client log log.Logger } func NewSender(log log.Logger) *Sender { - netTransport := &http.Transport{ - TLSClientConfig: &tls.Config{ - Renegotiation: tls.RenegotiateFreelyAsClient, - }, - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 5 * time.Second, - } - c := &http.Client{ - Timeout: time.Second * 30, - Transport: netTransport, - } return &Sender{ - c: c, log: log, } } @@ -86,7 +70,7 @@ func (s *Sender) SendWebhook(ctx context.Context, cmd *alertingReceivers.SendWeb request.Header.Set(k, v) } - resp, err := s.c.Do(request) + resp, err := tlsClient(cmd.TLSConfig).Do(request) if err != nil { return err } @@ -117,3 +101,25 @@ func (s *Sender) SendWebhook(ctx context.Context, cmd *alertingReceivers.SendWeb level.Debug(s.log).Log("msg", "Webhook failed", "url", cmd.URL, "statuscode", resp.Status, "body", string(body)) return fmt.Errorf("webhook response status %v", resp.Status) } + +func tlsClient(tlsConfig *tls.Config) *http.Client { + nc := func(tlsConfig *tls.Config) *http.Client { + return &http.Client{ + Timeout: time.Second * 30, + Transport: &http.Transport{ + TLSClientConfig: tlsConfig, + Proxy: http.ProxyFromEnvironment, + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + }).Dial, + TLSHandshakeTimeout: 5 * time.Second, + }, + } + } + + if tlsConfig == nil { + return nc(&tls.Config{Renegotiation: tls.RenegotiateFreelyAsClient}) + } + + return nc(tlsConfig) +} diff --git a/vendor/github.com/grafana/alerting/receivers/webhook.go b/vendor/github.com/grafana/alerting/receivers/webhook.go index a28f8e85992..9287232dad2 100644 --- a/vendor/github.com/grafana/alerting/receivers/webhook.go +++ b/vendor/github.com/grafana/alerting/receivers/webhook.go @@ -1,6 +1,9 @@ package receivers -import "context" +import ( + "context" + "crypto/tls" +) type SendWebhookSettings struct { URL string @@ -11,6 +14,7 @@ type SendWebhookSettings struct { HTTPHeader map[string]string ContentType string Validation func(body []byte, statusCode int) error + TLSConfig *tls.Config } type WebhookSender interface { diff --git a/vendor/github.com/grafana/alerting/receivers/webhook/config.go b/vendor/github.com/grafana/alerting/receivers/webhook/config.go index de045153444..11bf96ea6f4 100644 --- a/vendor/github.com/grafana/alerting/receivers/webhook/config.go +++ b/vendor/github.com/grafana/alerting/receivers/webhook/config.go @@ -22,8 +22,9 @@ type Config struct { User string Password string - Title string - Message string + Title string + Message string + TLSConfig *receivers.TLSConfig } func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Config, error) { @@ -38,6 +39,7 @@ func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Confi Password string `json:"password,omitempty" yaml:"password,omitempty"` Title string `json:"title,omitempty" yaml:"title,omitempty"` Message string `json:"message,omitempty" yaml:"message,omitempty"` + TLSConfig *receivers.TLSConfig `json:"tlsConfig,omitempty" yaml:"tlsConfig,omitempty"` }{} err := json.Unmarshal(jsonData, &rawSettings) @@ -77,5 +79,15 @@ func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Confi if settings.Message == "" { settings.Message = templates.DefaultMessageEmbed } + + if tlsConfig := rawSettings.TLSConfig; tlsConfig != nil { + settings.TLSConfig = &receivers.TLSConfig{ + InsecureSkipVerify: tlsConfig.InsecureSkipVerify, + CACertificate: decryptFn("tlsConfig.caCertificate", tlsConfig.CACertificate), + ClientCertificate: decryptFn("tlsConfig.clientCertificate", tlsConfig.ClientCertificate), + ClientKey: decryptFn("tlsConfig.clientKey", tlsConfig.ClientKey), + } + } + return settings, err } diff --git a/vendor/github.com/grafana/alerting/receivers/webhook/webhook.go b/vendor/github.com/grafana/alerting/receivers/webhook/webhook.go index b1b954f27ab..7a21d5ccb6b 100644 --- a/vendor/github.com/grafana/alerting/receivers/webhook/webhook.go +++ b/vendor/github.com/grafana/alerting/receivers/webhook/webhook.go @@ -2,6 +2,7 @@ package webhook import ( "context" + "crypto/tls" "encoding/json" "fmt" @@ -111,6 +112,13 @@ func (wn *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error return false, tmplErr } + var tlsConfig *tls.Config + if wn.settings.TLSConfig != nil { + if tlsConfig, err = wn.settings.TLSConfig.ToCryptoTLSConfig(); err != nil { + return false, err + } + } + cmd := &receivers.SendWebhookSettings{ URL: parsedURL, User: wn.settings.User, @@ -118,6 +126,7 @@ func (wn *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error Body: string(body), HTTPMethod: wn.settings.HTTPMethod, HTTPHeader: headers, + TLSConfig: tlsConfig, } if err := wn.ns.SendWebhook(ctx, cmd); err != nil { From d3f07e7e2f32a3fbbc206254ad6a50e4733d367d Mon Sep 17 00:00:00 2001 From: Tito Lins Date: Tue, 15 Oct 2024 16:04:53 +0200 Subject: [PATCH 2/7] update alerting --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d101d3cfcd6..33b623faa22 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/google/go-github/v57 v57.0.0 github.com/google/uuid v1.6.0 github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc - github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b + github.com/grafana/alerting v0.0.0-20241015120117-e29973e8e19e github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/hashicorp/vault/api v1.15.0 From 50cb9762e8a4bd59774ab8fd05345d18edc2d304 Mon Sep 17 00:00:00 2001 From: Tito Lins Date: Tue, 15 Oct 2024 16:05:19 +0200 Subject: [PATCH 3/7] update alerting --- .../alerting/definition/alertmanager.go | 20 +++++++++++++++++++ .../notify/grafana_alertmanager_metrics.go | 5 +++-- .../grafana/alerting/notify/receivers.go | 2 +- .../grafana/alerting/notify/testing.go | 3 ++- .../alerting/receivers/email_sender.go | 2 +- .../alerting/receivers/googlechat/config.go | 4 +++- .../alerting/receivers/googlechat/testing.go | 5 +++++ .../alerting/receivers/pushover/pushover.go | 2 +- .../grafana/alerting/receivers/slack/slack.go | 4 ++-- .../alerting/receivers/victorops/victorops.go | 2 +- .../alerting/receivers/webhook/testing.go | 13 ++++++++++-- vendor/modules.txt | 4 ++-- 12 files changed, 52 insertions(+), 14 deletions(-) diff --git a/vendor/github.com/grafana/alerting/definition/alertmanager.go b/vendor/github.com/grafana/alerting/definition/alertmanager.go index 7a1efa3d0dd..8631711fe76 100644 --- a/vendor/github.com/grafana/alerting/definition/alertmanager.go +++ b/vendor/github.com/grafana/alerting/definition/alertmanager.go @@ -1,6 +1,7 @@ package definition import ( + "encoding/base64" "encoding/json" "fmt" "reflect" @@ -606,3 +607,22 @@ func (r *PostableApiReceiver) GetName() string { type PostableGrafanaReceivers struct { GrafanaManagedReceivers []*PostableGrafanaReceiver `yaml:"grafana_managed_receiver_configs,omitempty" json:"grafana_managed_receiver_configs,omitempty"` } + +// DecryptSecureSettings returns a map containing the decoded and decrypted secure settings. +func (pgr *PostableGrafanaReceiver) DecryptSecureSettings(decryptFn func(payload []byte) ([]byte, error)) (map[string]string, error) { + decrypted := make(map[string]string, len(pgr.SecureSettings)) + for k, v := range pgr.SecureSettings { + decoded, err := base64.StdEncoding.DecodeString(v) + if err != nil { + return nil, fmt.Errorf("failed to decode value for key '%s': %w", k, err) + } + + b, err := decryptFn(decoded) + if err != nil { + return nil, fmt.Errorf("failed to decrypt value for key '%s': %w", k, err) + } + + decrypted[k] = string(b) + } + return decrypted, nil +} diff --git a/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go b/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go index 8c1bf6acc6f..73b970d8e82 100644 --- a/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go +++ b/vendor/github.com/grafana/alerting/notify/grafana_alertmanager_metrics.go @@ -1,6 +1,7 @@ package notify import ( + "github.com/go-kit/log" "github.com/prometheus/alertmanager/api/metrics" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" @@ -20,10 +21,10 @@ type GrafanaAlertmanagerMetrics struct { } // NewGrafanaAlertmanagerMetrics creates a set of metrics for the Alertmanager. -func NewGrafanaAlertmanagerMetrics(r prometheus.Registerer) *GrafanaAlertmanagerMetrics { +func NewGrafanaAlertmanagerMetrics(r prometheus.Registerer, l log.Logger) *GrafanaAlertmanagerMetrics { return &GrafanaAlertmanagerMetrics{ Registerer: r, - Alerts: metrics.NewAlerts(r), + Alerts: metrics.NewAlerts(r, l), configuredReceivers: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: subsystem, diff --git a/vendor/github.com/grafana/alerting/notify/receivers.go b/vendor/github.com/grafana/alerting/notify/receivers.go index 9fdf162c699..09ac3715298 100644 --- a/vendor/github.com/grafana/alerting/notify/receivers.go +++ b/vendor/github.com/grafana/alerting/notify/receivers.go @@ -283,7 +283,7 @@ func parseNotifier(ctx context.Context, result *GrafanaReceiverConfig, receiver } result.EmailConfigs = append(result.EmailConfigs, newNotifierConfig(receiver, cfg)) case "googlechat": - cfg, err := googlechat.NewConfig(receiver.Settings) + cfg, err := googlechat.NewConfig(receiver.Settings, decryptFn) if err != nil { return err } diff --git a/vendor/github.com/grafana/alerting/notify/testing.go b/vendor/github.com/grafana/alerting/notify/testing.go index a200afb7045..d4ccdf7f86c 100644 --- a/vendor/github.com/grafana/alerting/notify/testing.go +++ b/vendor/github.com/grafana/alerting/notify/testing.go @@ -136,7 +136,8 @@ var AllKnownConfigsForTesting = map[string]NotifierConfigTest{ Config: email.FullValidConfigForTesting, }, "googlechat": {NotifierType: "googlechat", - Config: googlechat.FullValidConfigForTesting, + Config: googlechat.FullValidConfigForTesting, + Secrets: googlechat.FullValidSecretsForTesting, }, "kafka": {NotifierType: "kafka", Config: kafka.FullValidConfigForTesting, diff --git a/vendor/github.com/grafana/alerting/receivers/email_sender.go b/vendor/github.com/grafana/alerting/receivers/email_sender.go index a8ecdce28ed..f029e17c0ba 100644 --- a/vendor/github.com/grafana/alerting/receivers/email_sender.go +++ b/vendor/github.com/grafana/alerting/receivers/email_sender.go @@ -43,7 +43,7 @@ type defaultEmailSender struct { // NewEmailSenderFactory takes a configuration and returns a new EmailSender factory function. func NewEmailSenderFactory(cfg EmailSenderConfig) func(Metadata) (EmailSender, error) { - return func(n Metadata) (EmailSender, error) { + return func(_ Metadata) (EmailSender, error) { tmpl, err := template.New("templates"). Funcs(template.FuncMap{ "Subject": subjectTemplateFunc, diff --git a/vendor/github.com/grafana/alerting/receivers/googlechat/config.go b/vendor/github.com/grafana/alerting/receivers/googlechat/config.go index 993a577e7c0..a23ca8d537e 100644 --- a/vendor/github.com/grafana/alerting/receivers/googlechat/config.go +++ b/vendor/github.com/grafana/alerting/receivers/googlechat/config.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + "github.com/grafana/alerting/receivers" "github.com/grafana/alerting/templates" ) @@ -14,13 +15,14 @@ type Config struct { Message string `json:"message,omitempty" yaml:"message,omitempty"` } -func NewConfig(jsonData json.RawMessage) (Config, error) { +func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Config, error) { var settings Config err := json.Unmarshal(jsonData, &settings) if err != nil { return Config{}, fmt.Errorf("failed to unmarshal settings: %w", err) } + settings.URL = decryptFn("url", settings.URL) if settings.URL == "" { return Config{}, errors.New("could not find url property in settings") } diff --git a/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go b/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go index b82663f3d2c..2a078b95caa 100644 --- a/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go +++ b/vendor/github.com/grafana/alerting/receivers/googlechat/testing.go @@ -8,3 +8,8 @@ const FullValidConfigForTesting = `{ "avatar_url" : "http://avatar", "use_discord_username": true }` + +// FullValidSecretsForTesting is a string representation of JSON object that contains all fields that can be overridden from secrets. +const FullValidSecretsForTesting = `{ + "url": "http://localhost/url-secret" +}` diff --git a/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go b/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go index 140963c82ec..6876676fef9 100644 --- a/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go +++ b/vendor/github.com/grafana/alerting/receivers/pushover/pushover.go @@ -215,7 +215,7 @@ func (pn *Notifier) genPushoverBody(ctx context.Context, as ...*types.Alert) (ma func (pn *Notifier) writeImageParts(ctx context.Context, w *multipart.Writer, as ...*types.Alert) { // Pushover supports at most one image attachment with a maximum size of pushoverMaxFileSize. // If the image is larger than pushoverMaxFileSize then return an error. - err := images.WithStoredImages(ctx, pn.log, pn.images, func(index int, image images.Image) error { + err := images.WithStoredImages(ctx, pn.log, pn.images, func(_ int, image images.Image) error { f, err := os.Open(image.Path) if err != nil { return fmt.Errorf("failed to open the image: %w", err) diff --git a/vendor/github.com/grafana/alerting/receivers/slack/slack.go b/vendor/github.com/grafana/alerting/receivers/slack/slack.go index b89e4cd88e6..a90278e31d9 100644 --- a/vendor/github.com/grafana/alerting/receivers/slack/slack.go +++ b/vendor/github.com/grafana/alerting/receivers/slack/slack.go @@ -176,7 +176,7 @@ func (sn *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, e // sendSlackRequest sends a request to the Slack API. // Stubbable by tests. -var sendSlackRequest = func(ctx context.Context, req *http.Request, logger logging.Logger) (string, error) { +var sendSlackRequest = func(_ context.Context, req *http.Request, logger logging.Logger) (string, error) { resp, err := slackClient.Do(req) if err != nil { return "", fmt.Errorf("failed to send request: %w", err) @@ -344,7 +344,7 @@ func (sn *Notifier) createSlackMessage(ctx context.Context, alerts []*types.Aler if isIncomingWebhook(sn.settings) { // Incoming webhooks cannot upload files, instead share images via their URL - _ = images.WithStoredImages(ctx, sn.log, sn.images, func(index int, image images.Image) error { + _ = images.WithStoredImages(ctx, sn.log, sn.images, func(_ int, image images.Image) error { if image.URL != "" { req.Attachments[0].ImageURL = image.URL return images.ErrImagesDone diff --git a/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go b/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go index 5455118e474..206ee6af762 100644 --- a/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go +++ b/vendor/github.com/grafana/alerting/receivers/victorops/victorops.go @@ -87,7 +87,7 @@ func (vn *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error } _ = images.WithStoredImages(ctx, vn.log, vn.images, - func(index int, image images.Image) error { + func(_ int, image images.Image) error { if image.URL != "" { bodyJSON["image_url"] = image.URL return images.ErrImagesDone diff --git a/vendor/github.com/grafana/alerting/receivers/webhook/testing.go b/vendor/github.com/grafana/alerting/receivers/webhook/testing.go index e73877f4e6a..336d0d68496 100644 --- a/vendor/github.com/grafana/alerting/receivers/webhook/testing.go +++ b/vendor/github.com/grafana/alerting/receivers/webhook/testing.go @@ -10,11 +10,20 @@ const FullValidConfigForTesting = `{ "username": "test-user", "password": "test-pass", "title": "test-title", - "message": "test-message" + "message": "test-message", + "tlsConfig": { + "insecureSkipVerify": false, + "clientCertificate": "test-client-certificate", + "clientKey": "test-client-key", + "caCertificate": "test-ca-certificate" + } }` // FullValidSecretsForTesting is a string representation of JSON object that contains all fields that can be overridden from secrets const FullValidSecretsForTesting = `{ "username": "test-secret-user", - "password": "test-secret-pass" + "password": "test-secret-pass", + "clientCertificate": "test-client-certificate", + "clientKey": "test-client-key", + "caCertificate": "test-ca-certificate" }` diff --git a/vendor/modules.txt b/vendor/modules.txt index 0253a44f5f7..91e87999992 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -584,8 +584,8 @@ github.com/gosimple/slug # github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc ## explicit; go 1.13 github.com/grafana-tools/sdk -# github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b -## explicit; go 1.21 +# github.com/grafana/alerting v0.0.0-20241015120117-e29973e8e19e +## explicit; go 1.22 github.com/grafana/alerting/cluster github.com/grafana/alerting/definition github.com/grafana/alerting/images From 44b6c13f57dd0aed7b408dba974ec5aef22a6638 Mon Sep 17 00:00:00 2001 From: Tito Lins Date: Thu, 17 Oct 2024 11:48:06 +0200 Subject: [PATCH 4/7] use NewTLSClient from alerting --- go.mod | 2 +- pkg/alertmanager/sender.go | 31 ++----------------- .../grafana/alerting/receivers/util.go | 23 ++++++++++++++ vendor/modules.txt | 2 +- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/go.mod b/go.mod index 33b623faa22..b6ab0404568 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/google/go-github/v57 v57.0.0 github.com/google/uuid v1.6.0 github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc - github.com/grafana/alerting v0.0.0-20241015120117-e29973e8e19e + github.com/grafana/alerting v0.0.0-20241017094609-2849f688c8eb github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/hashicorp/vault/api v1.15.0 diff --git a/pkg/alertmanager/sender.go b/pkg/alertmanager/sender.go index a6c81d165e9..10982228caf 100644 --- a/pkg/alertmanager/sender.go +++ b/pkg/alertmanager/sender.go @@ -9,12 +9,9 @@ package alertmanager import ( "bytes" "context" - "crypto/tls" "fmt" "io" - "net" "net/http" - "time" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -24,9 +21,7 @@ import ( "github.com/grafana/mimir/pkg/util/version" ) -var ( - ErrInvalidMethod = errors.New("webhook only supports HTTP methods PUT or POST") -) +var ErrInvalidMethod = errors.New("webhook only supports HTTP methods PUT or POST") type Sender struct { log log.Logger @@ -70,7 +65,7 @@ func (s *Sender) SendWebhook(ctx context.Context, cmd *alertingReceivers.SendWeb request.Header.Set(k, v) } - resp, err := tlsClient(cmd.TLSConfig).Do(request) + resp, err := alertingReceivers.NewTLSClient(cmd.TLSConfig).Do(request) if err != nil { return err } @@ -101,25 +96,3 @@ func (s *Sender) SendWebhook(ctx context.Context, cmd *alertingReceivers.SendWeb level.Debug(s.log).Log("msg", "Webhook failed", "url", cmd.URL, "statuscode", resp.Status, "body", string(body)) return fmt.Errorf("webhook response status %v", resp.Status) } - -func tlsClient(tlsConfig *tls.Config) *http.Client { - nc := func(tlsConfig *tls.Config) *http.Client { - return &http.Client{ - Timeout: time.Second * 30, - Transport: &http.Transport{ - TLSClientConfig: tlsConfig, - Proxy: http.ProxyFromEnvironment, - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 5 * time.Second, - }, - } - } - - if tlsConfig == nil { - return nc(&tls.Config{Renegotiation: tls.RenegotiateFreelyAsClient}) - } - - return nc(tlsConfig) -} diff --git a/vendor/github.com/grafana/alerting/receivers/util.go b/vendor/github.com/grafana/alerting/receivers/util.go index cc04aa1fca3..efdcccacc0c 100644 --- a/vendor/github.com/grafana/alerting/receivers/util.go +++ b/vendor/github.com/grafana/alerting/receivers/util.go @@ -76,6 +76,29 @@ func (cfg *TLSConfig) ToCryptoTLSConfig() (*tls.Config, error) { return tlsCfg, nil } +// NewTLSClient creates a new HTTP client with the provided TLS configuration or with default settings. +func NewTLSClient(tlsConfig *tls.Config) *http.Client { + nc := func(tlsConfig *tls.Config) *http.Client { + return &http.Client{ + Timeout: time.Second * 30, + Transport: &http.Transport{ + TLSClientConfig: tlsConfig, + Proxy: http.ProxyFromEnvironment, + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + }).Dial, + TLSHandshakeTimeout: 5 * time.Second, + }, + } + } + + if tlsConfig == nil { + return nc(&tls.Config{Renegotiation: tls.RenegotiateFreelyAsClient}) + } + + return nc(tlsConfig) +} + // SendHTTPRequest sends an HTTP request. // Stubbable by tests. // diff --git a/vendor/modules.txt b/vendor/modules.txt index 91e87999992..49b7f13b504 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -584,7 +584,7 @@ github.com/gosimple/slug # github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc ## explicit; go 1.13 github.com/grafana-tools/sdk -# github.com/grafana/alerting v0.0.0-20241015120117-e29973e8e19e +# github.com/grafana/alerting v0.0.0-20241017094609-2849f688c8eb ## explicit; go 1.22 github.com/grafana/alerting/cluster github.com/grafana/alerting/definition From 91c67e89d765644877e0b45762bf732d7e12bcfe Mon Sep 17 00:00:00 2001 From: Tito Lins Date: Thu, 17 Oct 2024 14:06:34 +0200 Subject: [PATCH 5/7] update prometheus-alertmanager --- go.mod | 2 +- go.sum | 4 ++-- .../alertmanager/api/metrics/metrics.go | 16 +++++++++++++--- .../prometheus/alertmanager/api/v2/api.go | 2 +- vendor/modules.txt | 4 ++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index b6ab0404568..6464f416f2b 100644 --- a/go.mod +++ b/go.mod @@ -309,7 +309,7 @@ replace github.com/opentracing-contrib/go-stdlib => github.com/grafana/opentraci replace github.com/opentracing-contrib/go-grpc => github.com/charleskorn/go-grpc v0.0.0-20231024023642-e9298576254f // Replacing prometheus/alertmanager with our fork. -replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240924175849-b8b7c2c74eb6 +replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240930132144-b5e64e81e8d3 // Replacing with a fork commit based on v1.17.1 having cherry-picked the following PRs: // - https://github.com/grafana/franz-go/pull/1 diff --git a/go.sum b/go.sum index e240d7abe6d..4f97d35bb98 100644 --- a/go.sum +++ b/go.sum @@ -531,8 +531,8 @@ github.com/grafana/mimir-prometheus v0.0.0-20241018090525-641277312a18 h1:Ks/tOv github.com/grafana/mimir-prometheus v0.0.0-20241018090525-641277312a18/go.mod h1:AvqWbZV+ePQxe3xQT4IX1iP1/evmMJKI7sNxzx20S6Y= github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 h1:em1oddjXL8c1tL0iFdtVtPloq2hRPen2MJQKoAWpxu0= github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU= -github.com/grafana/prometheus-alertmanager v0.25.1-0.20240924175849-b8b7c2c74eb6 h1:nT8QXdJo6wHMBcF0xEoXxEWkoUZOyzV/jyi/u9l7YEk= -github.com/grafana/prometheus-alertmanager v0.25.1-0.20240924175849-b8b7c2c74eb6/go.mod h1:YeND+6FDA7OuFgDzYODN8kfPhXLCehcpxe4T9mdnpCY= +github.com/grafana/prometheus-alertmanager v0.25.1-0.20240930132144-b5e64e81e8d3 h1:6D2gGAwyQBElSrp3E+9lSr7k8gLuP3Aiy20rweLWeBw= +github.com/grafana/prometheus-alertmanager v0.25.1-0.20240930132144-b5e64e81e8d3/go.mod h1:YeND+6FDA7OuFgDzYODN8kfPhXLCehcpxe4T9mdnpCY= github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg= github.com/grafana/pyroscope-go/godeltaprof v0.1.8/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU= github.com/grafana/regexp v0.0.0-20240531075221-3685f1377d7b h1:oMAq12GxTpwo9jxbnG/M4F/HdpwbibTaVoxNA0NZprY= diff --git a/vendor/github.com/prometheus/alertmanager/api/metrics/metrics.go b/vendor/github.com/prometheus/alertmanager/api/metrics/metrics.go index ea45acc2ee1..2a91911c3d7 100644 --- a/vendor/github.com/prometheus/alertmanager/api/metrics/metrics.go +++ b/vendor/github.com/prometheus/alertmanager/api/metrics/metrics.go @@ -13,7 +13,12 @@ package metrics -import "github.com/prometheus/client_golang/prometheus" +import ( + "github.com/go-kit/log" + "github.com/go-kit/log/level" + + "github.com/prometheus/client_golang/prometheus" +) // Alerts stores metrics for alerts. type Alerts struct { @@ -24,7 +29,7 @@ type Alerts struct { // NewAlerts returns an *Alerts struct for the given API version. // Since v1 was deprecated in 0.28, v2 is now hardcoded. -func NewAlerts(r prometheus.Registerer) *Alerts { +func NewAlerts(r prometheus.Registerer, l log.Logger) *Alerts { numReceivedAlerts := prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "alertmanager_alerts_received_total", Help: "The total number of received alerts.", @@ -36,7 +41,12 @@ func NewAlerts(r prometheus.Registerer) *Alerts { ConstLabels: prometheus.Labels{"version": "v2"}, }) if r != nil { - r.MustRegister(numReceivedAlerts, numInvalidAlerts) + for _, c := range []prometheus.Collector{numReceivedAlerts, numInvalidAlerts} { + r.Unregister(c) + if err := r.Register(c); err != nil { + level.Error(l).Log("msg", "Failed to register collector", "err", err) + } + } } return &Alerts{ firing: numReceivedAlerts.WithLabelValues("firing"), diff --git a/vendor/github.com/prometheus/alertmanager/api/v2/api.go b/vendor/github.com/prometheus/alertmanager/api/v2/api.go index 80babb460b3..4372309e5cf 100644 --- a/vendor/github.com/prometheus/alertmanager/api/v2/api.go +++ b/vendor/github.com/prometheus/alertmanager/api/v2/api.go @@ -100,7 +100,7 @@ func NewAPI( peer: peer, silences: silences, logger: l, - m: metrics.NewAlerts(r), + m: metrics.NewAlerts(r, l), uptime: time.Now(), } diff --git a/vendor/modules.txt b/vendor/modules.txt index 49b7f13b504..536eb8fd8cc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -922,7 +922,7 @@ github.com/pmezard/go-difflib/difflib # github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c ## explicit; go 1.14 github.com/power-devops/perfstat -# github.com/prometheus/alertmanager v0.27.0 => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240924175849-b8b7c2c74eb6 +# github.com/prometheus/alertmanager v0.27.0 => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240930132144-b5e64e81e8d3 ## explicit; go 1.22 github.com/prometheus/alertmanager/api github.com/prometheus/alertmanager/api/metrics @@ -1683,5 +1683,5 @@ sigs.k8s.io/yaml/goyaml.v3 # github.com/munnerz/goautoneg => github.com/grafana/goautoneg v0.0.0-20240607115440-f335c04c58ce # github.com/opentracing-contrib/go-stdlib => github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 # github.com/opentracing-contrib/go-grpc => github.com/charleskorn/go-grpc v0.0.0-20231024023642-e9298576254f -# github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240924175849-b8b7c2c74eb6 +# github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240930132144-b5e64e81e8d3 # github.com/twmb/franz-go => github.com/grafana/franz-go v0.0.0-20241009100846-782ba1442937 From 32e24bf81021f5cb2575fc911ec0adc1e154939d Mon Sep 17 00:00:00 2001 From: Tito Lins Date: Mon, 21 Oct 2024 14:54:26 +0200 Subject: [PATCH 6/7] update alerting --- go.mod | 2 +- vendor/modules.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 6464f416f2b..e18cb945c4d 100644 --- a/go.mod +++ b/go.mod @@ -65,7 +65,7 @@ require ( github.com/google/go-github/v57 v57.0.0 github.com/google/uuid v1.6.0 github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc - github.com/grafana/alerting v0.0.0-20241017094609-2849f688c8eb + github.com/grafana/alerting v0.0.0-20241021123319-be61d61f71e7 github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/hashicorp/vault/api v1.15.0 diff --git a/vendor/modules.txt b/vendor/modules.txt index 536eb8fd8cc..2631efd8969 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -584,7 +584,7 @@ github.com/gosimple/slug # github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc ## explicit; go 1.13 github.com/grafana-tools/sdk -# github.com/grafana/alerting v0.0.0-20241017094609-2849f688c8eb +# github.com/grafana/alerting v0.0.0-20241021123319-be61d61f71e7 ## explicit; go 1.22 github.com/grafana/alerting/cluster github.com/grafana/alerting/definition From 98b2a8f73d735c4377f3ad6cb438a745cf6eb99b Mon Sep 17 00:00:00 2001 From: Tito Lins Date: Tue, 22 Oct 2024 12:20:19 +0200 Subject: [PATCH 7/7] update alerting --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 4f97d35bb98..1fa3e973b6a 100644 --- a/go.sum +++ b/go.sum @@ -513,8 +513,8 @@ github.com/gosimple/slug v1.1.1 h1:fRu/digW+NMwBIP+RmviTK97Ho/bEj/C9swrCspN3D4= github.com/gosimple/slug v1.1.1/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0= github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc h1:PXZQA2WCxe85Tnn+WEvr8fDpfwibmEPgfgFEaC87G24= github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc/go.mod h1:AHHlOEv1+GGQ3ktHMlhuTUwo3zljV3QJbC0+8o2kn+4= -github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b h1:UO4mv94pG1kzKCgBKh20TXdACBCAK2vYjV3Q2MlcpEQ= -github.com/grafana/alerting v0.0.0-20240926144415-27f4e81b4b6b/go.mod h1:GMLi6d09Xqo96fCVUjNk//rcjP5NKEdjOzfWIffD5r4= +github.com/grafana/alerting v0.0.0-20241021123319-be61d61f71e7 h1:lsM/QscEX+ZDIJm48ynQscH+msETyGYV6ug8L4f2DtM= +github.com/grafana/alerting v0.0.0-20241021123319-be61d61f71e7/go.mod h1:QsnoKX/iYZxA4Cv+H+wC7uxutBD8qi8ZW5UJvD2TYmU= github.com/grafana/dskit v0.0.0-20241021153333-9018c0eb8c52 h1:5+WiCb4UyRAVECk4m8nBrQlZkFCL/7+Vq7Q++EydIeI= github.com/grafana/dskit v0.0.0-20241021153333-9018c0eb8c52/go.mod h1:SPLNCARd4xdjCkue0O6hvuoveuS1dGJjDnfxYe405YQ= github.com/grafana/e2e v0.1.2-0.20240118170847-db90b84177fc h1:BW+LjKJDz0So5LI8UZfW5neWeKpSkWqhmGjQFzcFfLM=