From d792c63ea4ee81bfad90fecbd75616ffd7df03d6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:31:17 +0000 Subject: [PATCH] fix(deps): update github.com/grafana/alerting digest to 4446935 --- go.mod | 2 +- go.sum | 4 +- .../alerting/notify/grafana_alertmanager.go | 20 ++++++-- .../alerting/receivers/slack/config.go | 5 +- .../grafana/alerting/receivers/slack/slack.go | 2 +- .../alerting/receivers/slack/testing.go | 3 +- .../alerting/templates/default_template.go | 1 + .../alerting/templates/template_data.go | 48 ++++++++++++------- vendor/modules.txt | 2 +- 9 files changed, 60 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index f1f96bf0a02..136e97e753d 100644 --- a/go.mod +++ b/go.mod @@ -66,7 +66,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-20250113170557-b4ab2ba363a8 + github.com/grafana/alerting v0.0.0-20250128163937-4446935bbcce github.com/grafana/regexp v0.0.0-20240607082908-2cb410fa05da github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/hashicorp/vault/api v1.15.0 diff --git a/go.sum b/go.sum index da5f6bf1688..b879e84a381 100644 --- a/go.sum +++ b/go.sum @@ -1269,8 +1269,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-20250113170557-b4ab2ba363a8 h1:mdI6P22PgFD7bQ0Yf4h8cfHSldak4nxogvlsTHZyZmc= -github.com/grafana/alerting v0.0.0-20250113170557-b4ab2ba363a8/go.mod h1:QsnoKX/iYZxA4Cv+H+wC7uxutBD8qi8ZW5UJvD2TYmU= +github.com/grafana/alerting v0.0.0-20250128163937-4446935bbcce h1:lilqLsOGzo+0SuyXjaN5XRVJbnkJRB0bXMoIlYHTIPE= +github.com/grafana/alerting v0.0.0-20250128163937-4446935bbcce/go.mod h1:QsnoKX/iYZxA4Cv+H+wC7uxutBD8qi8ZW5UJvD2TYmU= github.com/grafana/dskit v0.0.0-20250122122458-53db97b18080 h1:VrEVJtQtvq7fqWKAIHOtAEYa+kTrPImXB5/vM+QZOf0= github.com/grafana/dskit v0.0.0-20250122122458-53db97b18080/go.mod h1:SPLNCARd4xdjCkue0O6hvuoveuS1dGJjDnfxYe405YQ= github.com/grafana/e2e v0.1.2-0.20240118170847-db90b84177fc h1:BW+LjKJDz0So5LI8UZfW5neWeKpSkWqhmGjQFzcFfLM= diff --git a/vendor/github.com/grafana/alerting/notify/grafana_alertmanager.go b/vendor/github.com/grafana/alerting/notify/grafana_alertmanager.go index 693dbff52c4..fcbd00f4ab5 100644 --- a/vendor/github.com/grafana/alerting/notify/grafana_alertmanager.go +++ b/vendor/github.com/grafana/alerting/notify/grafana_alertmanager.go @@ -18,8 +18,6 @@ import ( "github.com/go-openapi/strfmt" "golang.org/x/sync/errgroup" - "github.com/grafana/alerting/cluster" - "github.com/grafana/alerting/notify/nfstatus" amv2 "github.com/prometheus/alertmanager/api/v2/models" "github.com/prometheus/alertmanager/config" "github.com/prometheus/alertmanager/dispatch" @@ -37,6 +35,9 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/model" + "github.com/grafana/alerting/cluster" + "github.com/grafana/alerting/notify/nfstatus" + "github.com/grafana/alerting/models" "github.com/grafana/alerting/templates" ) @@ -663,13 +664,24 @@ func (am *GrafanaAlertmanager) ApplyConfig(cfg Configuration) (err error) { // Finally, build the integrations map using the receiver configuration and templates. apiReceivers := cfg.Receivers() + nameToReceiver := make(map[string]*APIReceiver, len(apiReceivers)) + for _, receiver := range apiReceivers { + if existing, ok := nameToReceiver[receiver.Name]; ok { + itypes := make([]string, 0, len(existing.GrafanaIntegrations.Integrations)) + for _, i := range existing.GrafanaIntegrations.Integrations { + itypes = append(itypes, i.Type) + } + level.Warn(am.logger).Log("msg", "receiver with same name is defined multiple times. Only the last one will be used", "receiver_name", receiver.Name, "overwritten_integrations", itypes) + } + nameToReceiver[receiver.Name] = receiver + } integrationsMap := make(map[string][]*Integration, len(apiReceivers)) - for _, apiReceiver := range apiReceivers { + for name, apiReceiver := range nameToReceiver { integrations, err := cfg.BuildReceiverIntegrationsFunc()(apiReceiver, tmpl) if err != nil { return err } - integrationsMap[apiReceiver.Name] = integrations + integrationsMap[name] = integrations } // Now, let's put together our notification pipeline diff --git a/vendor/github.com/grafana/alerting/receivers/slack/config.go b/vendor/github.com/grafana/alerting/receivers/slack/config.go index edd82b4131b..de32eff9ee2 100644 --- a/vendor/github.com/grafana/alerting/receivers/slack/config.go +++ b/vendor/github.com/grafana/alerting/receivers/slack/config.go @@ -24,6 +24,7 @@ type Config struct { MentionChannel string `json:"mentionChannel,omitempty" yaml:"mentionChannel,omitempty"` MentionUsers receivers.CommaSeparatedStrings `json:"mentionUsers,omitempty" yaml:"mentionUsers,omitempty"` MentionGroups receivers.CommaSeparatedStrings `json:"mentionGroups,omitempty" yaml:"mentionGroups,omitempty"` + Color string `json:"color,omitempty" yaml:"color,omitempty"` } func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Config, error) { @@ -67,6 +68,8 @@ func NewConfig(jsonData json.RawMessage, decryptFn receivers.DecryptFunc) (Confi if settings.Title == "" { settings.Title = templates.DefaultMessageTitleEmbed } - + if settings.Color == "" { + settings.Color = templates.DefaultMessageColor + } return settings, nil } diff --git a/vendor/github.com/grafana/alerting/receivers/slack/slack.go b/vendor/github.com/grafana/alerting/receivers/slack/slack.go index cd65cb2e35c..e4839f1e930 100644 --- a/vendor/github.com/grafana/alerting/receivers/slack/slack.go +++ b/vendor/github.com/grafana/alerting/receivers/slack/slack.go @@ -258,7 +258,7 @@ func (sn *Notifier) createSlackMessage(ctx context.Context, alerts []*types.Aler // https://api.slack.com/messaging/composing/layouts#when-to-use-attachments Attachments: []attachment{ { - Color: receivers.GetAlertStatusColor(types.Alerts(alerts...).Status()), + Color: tmpl(sn.settings.Color), Title: title, Fallback: title, Footer: "Grafana v" + sn.appVersion, diff --git a/vendor/github.com/grafana/alerting/receivers/slack/testing.go b/vendor/github.com/grafana/alerting/receivers/slack/testing.go index 0d7f13964c5..c448fe17673 100644 --- a/vendor/github.com/grafana/alerting/receivers/slack/testing.go +++ b/vendor/github.com/grafana/alerting/receivers/slack/testing.go @@ -13,7 +13,8 @@ const FullValidConfigForTesting = `{ "icon_url": "http://localhost/icon_url", "mentionChannel": "channel", "mentionUsers": "test-mentionUsers", - "mentionGroups": "test-mentionGroups" + "mentionGroups": "test-mentionGroups", + "color": "test-color" }` // FullValidSecretsForTesting is a string representation of JSON object that contains all fields that can be overridden from secrets diff --git a/vendor/github.com/grafana/alerting/templates/default_template.go b/vendor/github.com/grafana/alerting/templates/default_template.go index 601a11d8dc7..ec6665c418f 100644 --- a/vendor/github.com/grafana/alerting/templates/default_template.go +++ b/vendor/github.com/grafana/alerting/templates/default_template.go @@ -9,6 +9,7 @@ import ( const ( DefaultMessageTitleEmbed = `{{ template "default.title" . }}` DefaultMessageEmbed = `{{ template "default.message" . }}` + DefaultMessageColor = `{{ if eq .Status "firing" }}#D63232{{ else }}#36a64f{{ end }}` ) var DefaultTemplateString = ` diff --git a/vendor/github.com/grafana/alerting/templates/template_data.go b/vendor/github.com/grafana/alerting/templates/template_data.go index f9b452624ec..21f8957971b 100644 --- a/vendor/github.com/grafana/alerting/templates/template_data.go +++ b/vendor/github.com/grafana/alerting/templates/template_data.go @@ -8,7 +8,6 @@ import ( "net/url" "path" "slices" - "sort" "strings" tmpltext "text/template" "time" @@ -226,28 +225,45 @@ func extendAlert(alert template.Alert, externalURL string, logger log.Logger) *E extended.ValueString = alert.Annotations[models.ValueStringAnnotation] } - matchers := make([]string, 0) - for key, value := range alert.Labels { - if !(strings.HasPrefix(key, "__") && strings.HasSuffix(key, "__")) { - matchers = append(matchers, key+"="+value) - } - } - sort.Strings(matchers) - u.Path = path.Join(externalPath, "/alerting/silence/new") + extended.SilenceURL = generateSilenceURL(alert, *u, externalPath) + + return extended +} + +// generateSilenceURL generates a URL to silence the given alert in Grafana. +func generateSilenceURL(alert template.Alert, baseURL url.URL, externalPath string) string { + baseURL.Path = path.Join(externalPath, "/alerting/silence/new") query := make(url.Values) query.Add("alertmanager", "grafana") - for _, matcher := range matchers { - query.Add("matcher", matcher) + + ruleUID := alert.Labels[models.RuleUIDLabel] + if ruleUID != "" { + query.Add("matcher", models.RuleUIDLabel+"="+ruleUID) } - u.RawQuery = query.Encode() + for _, pair := range alert.Labels.SortedPairs() { + if strings.HasPrefix(pair.Name, "__") && strings.HasSuffix(pair.Name, "__") { + continue + } + + // If the alert has a rule uid available, it can more succinctly and accurately replace alertname + folder labels. + // In addition, using rule uid is more compatible with minimal permission RBAC users as they require the rule uid to silence. + if ruleUID != "" && (pair.Name == models.FolderTitleLabel || pair.Name == model.AlertNameLabel) { + continue + } + + query.Add("matcher", pair.Name+"="+pair.Value) + } + + baseURL.RawQuery = query.Encode() + + orgID := alert.Annotations[models.OrgIDAnnotation] if len(orgID) > 0 { - extended.SilenceURL = setOrgIDQueryParam(u, orgID) - } else { - extended.SilenceURL = u.String() + _ = setOrgIDQueryParam(&baseURL, orgID) } - return extended + + return baseURL.String() } func setOrgIDQueryParam(url *url.URL, orgID string) string { diff --git a/vendor/modules.txt b/vendor/modules.txt index a5363da96ae..853e1125e1c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -610,7 +610,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-20250113170557-b4ab2ba363a8 +# github.com/grafana/alerting v0.0.0-20250128163937-4446935bbcce ## explicit; go 1.22 github.com/grafana/alerting/cluster github.com/grafana/alerting/definition