diff --git a/apis/vshn/v1/common_types.go b/apis/vshn/v1/common_types.go index 24c5072f01..0a61f3d0e7 100644 --- a/apis/vshn/v1/common_types.go +++ b/apis/vshn/v1/common_types.go @@ -182,6 +182,15 @@ type VSHNMonitoring struct { // Email necessary to send alerts via email Email string `json:"email,omitempty"` + + // +kubebuilder:validation:Enum=frequent;standard;minimal + // +kubebuilder:default=standard + + // AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + // "frequent" sends reminders every hour, "standard" (default) every 4 hours, + // "minimal" every 12 hours. This helps reduce email spam while ensuring + // you stay informed about unresolved alerts. + AlertFrequency string `json:"alertFrequency,omitempty"` } // InitialMaintenanceStatus tracks the status of the initial maintenance job. diff --git a/crds/vshn.appcat.vshn.io_vshnforgejoes.yaml b/crds/vshn.appcat.vshn.io_vshnforgejoes.yaml index a8944e9e27..c5a92a8eea 100644 --- a/crds/vshn.appcat.vshn.io_vshnforgejoes.yaml +++ b/crds/vshn.appcat.vshn.io_vshnforgejoes.yaml @@ -105,6 +105,18 @@ spec: monitoring: description: Monitoring contains settings to control the monitoring of a service. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_vshnkeycloaks.yaml b/crds/vshn.appcat.vshn.io_vshnkeycloaks.yaml index fdf41cd997..f65a3dda5e 100644 --- a/crds/vshn.appcat.vshn.io_vshnkeycloaks.yaml +++ b/crds/vshn.appcat.vshn.io_vshnkeycloaks.yaml @@ -108,6 +108,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the @@ -4820,6 +4832,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_vshnmariadbs.yaml b/crds/vshn.appcat.vshn.io_vshnmariadbs.yaml index aab40a5f0a..b5732d1df4 100644 --- a/crds/vshn.appcat.vshn.io_vshnmariadbs.yaml +++ b/crds/vshn.appcat.vshn.io_vshnmariadbs.yaml @@ -114,6 +114,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_vshnminios.yaml b/crds/vshn.appcat.vshn.io_vshnminios.yaml index a7d77c3981..809d8d2f1b 100644 --- a/crds/vshn.appcat.vshn.io_vshnminios.yaml +++ b/crds/vshn.appcat.vshn.io_vshnminios.yaml @@ -106,6 +106,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_vshnnextclouds.yaml b/crds/vshn.appcat.vshn.io_vshnnextclouds.yaml index e29e6f1e9c..b88c5e3776 100644 --- a/crds/vshn.appcat.vshn.io_vshnnextclouds.yaml +++ b/crds/vshn.appcat.vshn.io_vshnnextclouds.yaml @@ -115,6 +115,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the @@ -4730,6 +4742,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_vshnpostgresqls.yaml b/crds/vshn.appcat.vshn.io_vshnpostgresqls.yaml index b18c6e1b91..462a048748 100644 --- a/crds/vshn.appcat.vshn.io_vshnpostgresqls.yaml +++ b/crds/vshn.appcat.vshn.io_vshnpostgresqls.yaml @@ -167,6 +167,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_vshnredis.yaml b/crds/vshn.appcat.vshn.io_vshnredis.yaml index 328b2fa5bd..10e42823f4 100644 --- a/crds/vshn.appcat.vshn.io_vshnredis.yaml +++ b/crds/vshn.appcat.vshn.io_vshnredis.yaml @@ -108,6 +108,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_xvshnforgejoes.yaml b/crds/vshn.appcat.vshn.io_xvshnforgejoes.yaml index 1710a9066f..c787b3b7b3 100644 --- a/crds/vshn.appcat.vshn.io_xvshnforgejoes.yaml +++ b/crds/vshn.appcat.vshn.io_xvshnforgejoes.yaml @@ -151,6 +151,18 @@ spec: description: Monitoring contains settings to control the monitoring of a service. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_xvshnkeycloaks.yaml b/crds/vshn.appcat.vshn.io_xvshnkeycloaks.yaml index 8c1b087099..4bcd636f84 100644 --- a/crds/vshn.appcat.vshn.io_xvshnkeycloaks.yaml +++ b/crds/vshn.appcat.vshn.io_xvshnkeycloaks.yaml @@ -161,6 +161,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the @@ -5571,6 +5583,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_xvshnmariadbs.yaml b/crds/vshn.appcat.vshn.io_xvshnmariadbs.yaml index 6610b5eb58..afa4ae8894 100644 --- a/crds/vshn.appcat.vshn.io_xvshnmariadbs.yaml +++ b/crds/vshn.appcat.vshn.io_xvshnmariadbs.yaml @@ -167,6 +167,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_xvshnminios.yaml b/crds/vshn.appcat.vshn.io_xvshnminios.yaml index 4e0b98cd01..71f0fc1441 100644 --- a/crds/vshn.appcat.vshn.io_xvshnminios.yaml +++ b/crds/vshn.appcat.vshn.io_xvshnminios.yaml @@ -160,6 +160,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_xvshnnextclouds.yaml b/crds/vshn.appcat.vshn.io_xvshnnextclouds.yaml index ca9c5701b1..286e41490a 100644 --- a/crds/vshn.appcat.vshn.io_xvshnnextclouds.yaml +++ b/crds/vshn.appcat.vshn.io_xvshnnextclouds.yaml @@ -159,6 +159,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the @@ -5465,6 +5477,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_xvshnpostgresqls.yaml b/crds/vshn.appcat.vshn.io_xvshnpostgresqls.yaml index 38e35ab843..2bed4cd4d3 100644 --- a/crds/vshn.appcat.vshn.io_xvshnpostgresqls.yaml +++ b/crds/vshn.appcat.vshn.io_xvshnpostgresqls.yaml @@ -170,6 +170,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/crds/vshn.appcat.vshn.io_xvshnredis.yaml b/crds/vshn.appcat.vshn.io_xvshnredis.yaml index fc2bba5961..5a204b2b50 100644 --- a/crds/vshn.appcat.vshn.io_xvshnredis.yaml +++ b/crds/vshn.appcat.vshn.io_xvshnredis.yaml @@ -162,6 +162,18 @@ spec: monitoring: description: Monitoring contains settings to control monitoring. properties: + alertFrequency: + default: standard + description: |- + AlertFrequency controls how often repeat alert emails are sent for ongoing issues. + "frequent" sends reminders every hour, "standard" (default) every 4 hours, + "minimal" every 12 hours. This helps reduce email spam while ensuring + you stay informed about unresolved alerts. + enum: + - frequent + - standard + - minimal + type: string alertmanagerConfigRef: description: |- AlertmanagerConfigRef contains the name of the AlertmanagerConfig that should be copied over to the diff --git a/pkg/comp-functions/functions/common/mailgun_alerting.go b/pkg/comp-functions/functions/common/mailgun_alerting.go index 2b9a824c87..606f370ea5 100644 --- a/pkg/comp-functions/functions/common/mailgun_alerting.go +++ b/pkg/comp-functions/functions/common/mailgun_alerting.go @@ -31,7 +31,9 @@ func MailgunAlerting[T client.Object](ctx context.Context, obj T, svc *runtime.S return runtime.NewWarningResult(fmt.Sprintf("Type %s doesn't implement Alerter interface", reflect.TypeOf(obj).String())) } - email := alertConfig.GetVSHNMonitoring().Email + monitoring := alertConfig.GetVSHNMonitoring() + email := monitoring.Email + alertFrequency := monitoring.AlertFrequency instanceNamespace := alertConfig.GetInstanceNamespace() name := obj.GetName() @@ -42,8 +44,8 @@ func MailgunAlerting[T client.Object](ctx context.Context, obj T, svc *runtime.S return runtime.NewWarningResult("Email Alerting is not enabled") } - log.Info("Deploying AlertmanagerConfig for mail alerting...") - err = deployAlertmanagerConfig(ctx, name, email, instanceNamespace, svc) + log.Info("Deploying AlertmanagerConfig for mail alerting...", "alertFrequency", alertFrequency) + err = deployAlertmanagerConfig(ctx, name, email, alertFrequency, instanceNamespace, svc) if err != nil { return runtime.NewFatalResult(fmt.Errorf("Can't deploy AlertmanagerConfig "+name+"-alertmanagerconfig-mailgun for mail alerting: %w", err)) } @@ -53,11 +55,50 @@ func MailgunAlerting[T client.Object](ctx context.Context, obj T, svc *runtime.S return nil } -func deployAlertmanagerConfig(ctx context.Context, name, email, instanceNamespace string, svc *runtime.ServiceRuntime) error { +// getAlertIntervals returns the appropriate alert timing intervals. +// Priority: per-instance AlertFrequency preset > component ConfigMap values > hardcoded defaults. +// +// AlertFrequency presets: +// - "frequent": 10s/5m/1h (legacy behavior, max ~24 emails/day) +// - "standard": 30s/10m/4h (default, max ~6 emails/day) +// - "minimal": 1m/30m/12h (low spam, max ~2 emails/day) +func getAlertIntervals(alertFrequency string, config *v1.ConfigMap) (groupWait, groupInterval, repeatInterval string) { + // If per-instance AlertFrequency preset is specified, use it + switch alertFrequency { + case "frequent": + return "10s", "5m", "1h" + case "minimal": + return "1m", "30m", "12h" + case "standard": + return "30s", "10m", "4h" + } + + // Otherwise, use component ConfigMap values with hardcoded fallbacks + groupWait = config.Data["emailAlertingGroupWait"] + if groupWait == "" { + groupWait = "30s" + } + + groupInterval = config.Data["emailAlertingGroupInterval"] + if groupInterval == "" { + groupInterval = "10m" + } + + repeatInterval = config.Data["emailAlertingRepeatInterval"] + if repeatInterval == "" { + repeatInterval = "4h" + } + + return groupWait, groupInterval, repeatInterval +} + +func deployAlertmanagerConfig(ctx context.Context, name, email, alertFrequency, instanceNamespace string, svc *runtime.ServiceRuntime) error { var alertManagerConfigName = name + "-alertmanagerconfig-mailgun" var alertManagerConfigSecretName = name + "-alertmanagerconfig-mailgun-secret" receiverName := "mailgun" + groupWait, groupInterval, repeatInterval := getAlertIntervals(alertFrequency, &svc.Config) + ac := &alertmanagerv1alpha1.AlertmanagerConfig{ ObjectMeta: metav1.ObjectMeta{ Name: alertManagerConfigName, @@ -92,9 +133,9 @@ func deployAlertmanagerConfig(ctx context.Context, name, email, instanceNamespac GroupBy: []string{ "alertname", }, - GroupWait: "10s", - GroupInterval: "5m", - RepeatInterval: "1h", + GroupWait: groupWait, + GroupInterval: groupInterval, + RepeatInterval: repeatInterval, Receiver: receiverName, }, },