diff --git a/Documentation/api-reference/api.md b/Documentation/api-reference/api.md index 2927f4972..e4b6c1521 100644 --- a/Documentation/api-reference/api.md +++ b/Documentation/api-reference/api.md @@ -10269,7 +10269,7 @@ DNSConfig.

Duration (string alias)

-(Appears on:AlertmanagerEndpoints, AlertmanagerGlobalConfig, CommonPrometheusFields, Endpoint, MetadataConfig, PodMetricsEndpoint, ProbeSpec, PrometheusSpec, PrometheusTracingConfig, QuerySpec, QueueConfig, RemoteReadSpec, RemoteWriteSpec, RetainConfig, Rule, RuleGroup, TSDBSpec, ThanosRulerSpec, ThanosSpec, AzureSDConfig, ConsulSDConfig, DNSSDConfig, DigitalOceanSDConfig, DockerSDConfig, DockerSwarmSDConfig, EC2SDConfig, EurekaSDConfig, FileSDConfig, GCESDConfig, HTTPSDConfig, HetznerSDConfig, IonosSDConfig, KumaSDConfig, LightSailSDConfig, LinodeSDConfig, NomadSDConfig, OVHCloudSDConfig, OpenStackSDConfig, PuppetDBSDConfig, PushoverConfig, ScalewaySDConfig, ScrapeConfigSpec, WebhookConfig, PushoverConfig, WebhookConfig) +(Appears on:AlertmanagerEndpoints, AlertmanagerGlobalConfig, CommonPrometheusFields, Endpoint, MetadataConfig, PodMetricsEndpoint, ProbeSpec, PrometheusSpec, PrometheusTracingConfig, QuerySpec, QueueConfig, RemoteReadSpec, RemoteWriteSpec, RetainConfig, Rule, RuleGroup, TSDBSpec, ThanosRulerSpec, ThanosSpec, AzureSDConfig, ConsulSDConfig, DNSSDConfig, DigitalOceanSDConfig, DockerSDConfig, DockerSwarmSDConfig, EC2SDConfig, EurekaSDConfig, FileSDConfig, GCESDConfig, HTTPSDConfig, HetznerSDConfig, IonosSDConfig, KumaSDConfig, LightSailSDConfig, LinodeSDConfig, NomadSDConfig, OVHCloudSDConfig, OpenStackSDConfig, PagerDutyConfig, PuppetDBSDConfig, PushoverConfig, ScalewaySDConfig, ScrapeConfigSpec, WebhookConfig, PagerDutyConfig, PushoverConfig, WebhookConfig)

Duration is a valid time duration that can be parsed by Prometheus model.ParseDuration() function. @@ -30256,6 +30256,21 @@ string

source defines the unique location of the affected system.

+ + +timeout
+ + +Duration + + + + +(Optional) +

Timeout is the maximum time allowed to invoke the pagerduty +It requires Alertmanager >= v0.30.0.

+ +

PagerDutyImageConfig @@ -37828,6 +37843,21 @@ string

source defines the unique location of the affected system.

+ + +timeout
+ + +Duration + + + + +(Optional) +

Timeout is the maximum time allowed to invoke the pagerduty +It requires Alertmanager >= v0.30.0.

+ +

PagerDutyImageConfig diff --git a/bundle.yaml b/bundle.yaml index ff15dde17..88cf2128e 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -4557,6 +4557,12 @@ spec: description: source defines the unique location of the affected system. type: string + timeout: + description: |- + Timeout is the maximum time allowed to invoke the pagerduty + It requires Alertmanager >= v0.30.0. + pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ + type: string url: description: url defines the URL to send requests to. type: string diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml index 9ab1a401a..4579824f6 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_alertmanagerconfigs.yaml @@ -4556,6 +4556,12 @@ spec: description: source defines the unique location of the affected system. type: string + timeout: + description: |- + Timeout is the maximum time allowed to invoke the pagerduty + It requires Alertmanager >= v0.30.0. + pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ + type: string url: description: url defines the URL to send requests to. type: string @@ -16543,6 +16549,12 @@ spec: description: source defines the unique location of the affected system. type: string + timeout: + description: |- + Timeout is the maximum time allowed to invoke the pagerduty + It requires Alertmanager >= v0.30.0. + pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ + type: string url: description: url defines the URL to send requests to. type: string diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml index d297bc185..abeb7d4f8 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagerconfigs.yaml @@ -4557,6 +4557,12 @@ spec: description: source defines the unique location of the affected system. type: string + timeout: + description: |- + Timeout is the maximum time allowed to invoke the pagerduty + It requires Alertmanager >= v0.30.0. + pattern: ^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$ + type: string url: description: url defines the URL to send requests to. type: string diff --git a/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json b/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json index 8b4b29121..9b4479d73 100644 --- a/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json +++ b/jsonnet/prometheus-operator/alertmanagerconfigs-crd.json @@ -4173,6 +4173,11 @@ "description": "source defines the unique location of the affected system.", "type": "string" }, + "timeout": { + "description": "Timeout is the maximum time allowed to invoke the pagerduty\nIt requires Alertmanager >= v0.30.0.", + "pattern": "^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$", + "type": "string" + }, "url": { "description": "url defines the URL to send requests to.", "type": "string" diff --git a/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet b/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet index 96b99f9ce..8c6ad7d2d 100644 --- a/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet +++ b/jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet @@ -4011,6 +4011,11 @@ description: 'source defines the unique location of the affected system.', type: 'string', }, + timeout: { + description: 'Timeout is the maximum time allowed to invoke the pagerduty\nIt requires Alertmanager >= v0.30.0.', + pattern: '^(0|(([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?)$', + type: 'string', + }, url: { description: 'url defines the URL to send requests to.', type: 'string', diff --git a/pkg/alertmanager/amcfg.go b/pkg/alertmanager/amcfg.go index e1a91a980..56c1319d6 100644 --- a/pkg/alertmanager/amcfg.go +++ b/pkg/alertmanager/amcfg.go @@ -1053,6 +1053,16 @@ func (cb *ConfigBuilder) convertPagerdutyConfig(ctx context.Context, in monitori out.Source = *in.Source } + if in.Timeout != nil { + if *in.Timeout != "" { + timeout, err := model.ParseDuration(string(*in.Timeout)) + if err != nil { + return nil, err + } + out.Timeout = &timeout + } + } + return out, nil } @@ -2411,6 +2421,7 @@ func (ops *opsgenieResponder) sanitize(amVersion semver.Version) error { func (pdc *pagerdutyConfig) sanitize(amVersion semver.Version, logger *slog.Logger) error { lessThanV0_25 := amVersion.LT(semver.MustParse("0.25.0")) + lessThanV0_30 := amVersion.LT(semver.MustParse("0.30.0")) if pdc.Source != "" && lessThanV0_25 { msg := "'source' supported in Alertmanager >= 0.25.0 only - dropping field from provided config" @@ -2442,6 +2453,12 @@ func (pdc *pagerdutyConfig) sanitize(amVersion semver.Version, logger *slog.Logg pdc.RoutingKeyFile = "" } + if pdc.Timeout != nil && lessThanV0_30 { + msg := "'timeout' supported in Alertmanager >= 0.30.0 only - dropping field from provided config" + logger.Warn(msg, "current_version", amVersion.String()) + pdc.Timeout = nil + } + return pdc.HTTPConfig.sanitize(amVersion, logger) } diff --git a/pkg/alertmanager/amcfg_test.go b/pkg/alertmanager/amcfg_test.go index 5e303d3e1..31aab632b 100644 --- a/pkg/alertmanager/amcfg_test.go +++ b/pkg/alertmanager/amcfg_test.go @@ -3909,6 +3909,9 @@ func TestSanitizeConfig(t *testing.T) { versionSMTPTLSConfigAllowed := semver.Version{Major: 0, Minor: 28} versionSMTPTLSConfigNotAllowed := semver.Version{Major: 0, Minor: 27} + versionTimeoutConfigAllowed := semver.Version{Major: 0, Minor: 30} + versionTimeoutConfigNotAllowed := semver.Version{Major: 0, Minor: 29} + for _, tc := range []struct { name string againstVersion semver.Version @@ -4569,6 +4572,39 @@ func TestSanitizeConfig(t *testing.T) { }, golden: "summary_add_in_supported_versions_for_MSTeams_config.golden", }, + { + name: "Test timeout is dropped in pagerduty config for unsupported versions", + againstVersion: versionTimeoutConfigNotAllowed, + + in: &alertmanagerConfig{ + Receivers: []*receiver{ + { + PagerdutyConfigs: []*pagerdutyConfig{ + { + Timeout: ptr.To(model.Duration(time.Minute)), + }, + }, + }, + }, + }, + golden: "test_pagerduty_timeout_is_dropped_in_pagerduty_config_for_unsupported_versions.golden", + }, + { + name: "Test timeout is added in pagerduty config for supported versions", + againstVersion: versionTimeoutConfigAllowed, + in: &alertmanagerConfig{ + Receivers: []*receiver{ + { + PagerdutyConfigs: []*pagerdutyConfig{ + { + Timeout: ptr.To(model.Duration(time.Minute)), + }, + }, + }, + }, + }, + golden: "test_pagerduty_timeout_is_added_in_pagerduty_config_for_supported_versions.golden", + }, } { t.Run(tc.name, func(t *testing.T) { err := tc.in.sanitize(tc.againstVersion, logger) diff --git a/pkg/alertmanager/testdata/test_pagerduty_timeout_is_added_in_pagerduty_config_for_supported_versions.golden b/pkg/alertmanager/testdata/test_pagerduty_timeout_is_added_in_pagerduty_config_for_supported_versions.golden new file mode 100644 index 000000000..c008410a5 --- /dev/null +++ b/pkg/alertmanager/testdata/test_pagerduty_timeout_is_added_in_pagerduty_config_for_supported_versions.golden @@ -0,0 +1,5 @@ +receivers: +- name: "" + pagerduty_configs: + - timeout: 1m +templates: [] diff --git a/pkg/alertmanager/testdata/test_pagerduty_timeout_is_dropped_in_pagerduty_config_for_unsupported_versions.golden b/pkg/alertmanager/testdata/test_pagerduty_timeout_is_dropped_in_pagerduty_config_for_unsupported_versions.golden new file mode 100644 index 000000000..448ec7eb9 --- /dev/null +++ b/pkg/alertmanager/testdata/test_pagerduty_timeout_is_dropped_in_pagerduty_config_for_unsupported_versions.golden @@ -0,0 +1,5 @@ +receivers: +- name: "" + pagerduty_configs: + - {} +templates: [] diff --git a/pkg/alertmanager/types.go b/pkg/alertmanager/types.go index ea425cd1e..e4f0010a0 100644 --- a/pkg/alertmanager/types.go +++ b/pkg/alertmanager/types.go @@ -149,6 +149,7 @@ type pagerdutyConfig struct { Component string `yaml:"component,omitempty" json:"component,omitempty"` Group string `yaml:"group,omitempty" json:"group,omitempty"` Source string `yaml:"source,omitempty" json:"source,omitempty"` + Timeout *model.Duration `yaml:"timeout,omitempty" json:"timeout,omitempty"` } type opsgenieConfig struct { diff --git a/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go b/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go index 72201c359..7124c9878 100644 --- a/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go +++ b/pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go @@ -286,6 +286,10 @@ type PagerDutyConfig struct { // source defines the unique location of the affected system. // +optional Source *string `json:"source,omitempty"` + // Timeout is the maximum time allowed to invoke the pagerduty + // It requires Alertmanager >= v0.30.0. + // +optional + Timeout *monitoringv1.Duration `json:"timeout,omitempty"` } // PagerDutyImageConfig attaches images to an incident diff --git a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go index 37cdabf14..942478b9e 100644 --- a/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go @@ -1885,6 +1885,11 @@ func (in *PagerDutyConfig) DeepCopyInto(out *PagerDutyConfig) { *out = new(string) **out = **in } + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(monitoringv1.Duration) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PagerDutyConfig. diff --git a/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go b/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go index 296ec133f..2fe17a0d2 100644 --- a/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go +++ b/pkg/apis/monitoring/v1beta1/alertmanager_config_types.go @@ -283,6 +283,10 @@ type PagerDutyConfig struct { // source defines the unique location of the affected system. // +optional Source *string `json:"source,omitempty"` + // Timeout is the maximum time allowed to invoke the pagerduty + // It requires Alertmanager >= v0.30.0. + // +optional + Timeout *monitoringv1.Duration `json:"timeout,omitempty"` } // PagerDutyImageConfig attaches images to an incident diff --git a/pkg/apis/monitoring/v1beta1/conversion_from.go b/pkg/apis/monitoring/v1beta1/conversion_from.go index 8d2241b16..f4c667d68 100644 --- a/pkg/apis/monitoring/v1beta1/conversion_from.go +++ b/pkg/apis/monitoring/v1beta1/conversion_from.go @@ -258,6 +258,7 @@ func convertPagerDutyConfigFrom(in v1alpha1.PagerDutyConfig) PagerDutyConfig { PagerDutyLinkConfigs: convertPagerDutyLinkConfigsFrom(in.PagerDutyLinkConfigs), HTTPConfig: convertHTTPConfigFrom(in.HTTPConfig), Source: in.Source, + Timeout: in.Timeout, } } diff --git a/pkg/apis/monitoring/v1beta1/conversion_to.go b/pkg/apis/monitoring/v1beta1/conversion_to.go index 2a9d2afe4..01b21ffc0 100644 --- a/pkg/apis/monitoring/v1beta1/conversion_to.go +++ b/pkg/apis/monitoring/v1beta1/conversion_to.go @@ -254,6 +254,7 @@ func convertPagerDutyConfigTo(in PagerDutyConfig) v1alpha1.PagerDutyConfig { PagerDutyLinkConfigs: convertPagerDutyLinkConfigsTo(in.PagerDutyLinkConfigs), HTTPConfig: convertHTTPConfigTo(in.HTTPConfig), Source: in.Source, + Timeout: in.Timeout, } } diff --git a/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go index 6fe42ba57..eda8bd5be 100644 --- a/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go @@ -524,6 +524,11 @@ func (in *PagerDutyConfig) DeepCopyInto(out *PagerDutyConfig) { *out = new(string) **out = **in } + if in.Timeout != nil { + in, out := &in.Timeout, &out.Timeout + *out = new(monitoringv1.Duration) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PagerDutyConfig. diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/pagerdutyconfig.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/pagerdutyconfig.go index b33e6802d..36b729a5d 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/pagerdutyconfig.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/pagerdutyconfig.go @@ -17,6 +17,7 @@ package v1alpha1 import ( + monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" v1 "k8s.io/api/core/v1" ) @@ -39,6 +40,7 @@ type PagerDutyConfigApplyConfiguration struct { PagerDutyLinkConfigs []PagerDutyLinkConfigApplyConfiguration `json:"pagerDutyLinkConfigs,omitempty"` HTTPConfig *HTTPConfigApplyConfiguration `json:"httpConfig,omitempty"` Source *string `json:"source,omitempty"` + Timeout *monitoringv1.Duration `json:"timeout,omitempty"` } // PagerDutyConfigApplyConfiguration constructs a declarative configuration of the PagerDutyConfig type for use with @@ -189,3 +191,11 @@ func (b *PagerDutyConfigApplyConfiguration) WithSource(value string) *PagerDutyC b.Source = &value return b } + +// WithTimeout sets the Timeout field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Timeout field is set to the value of the last call. +func (b *PagerDutyConfigApplyConfiguration) WithTimeout(value monitoringv1.Duration) *PagerDutyConfigApplyConfiguration { + b.Timeout = &value + return b +} diff --git a/pkg/client/applyconfiguration/monitoring/v1beta1/pagerdutyconfig.go b/pkg/client/applyconfiguration/monitoring/v1beta1/pagerdutyconfig.go index 653e53ebb..f4c8fe070 100644 --- a/pkg/client/applyconfiguration/monitoring/v1beta1/pagerdutyconfig.go +++ b/pkg/client/applyconfiguration/monitoring/v1beta1/pagerdutyconfig.go @@ -16,6 +16,10 @@ package v1beta1 +import ( + v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" +) + // PagerDutyConfigApplyConfiguration represents a declarative configuration of the PagerDutyConfig type for use // with apply. type PagerDutyConfigApplyConfiguration struct { @@ -35,6 +39,7 @@ type PagerDutyConfigApplyConfiguration struct { PagerDutyLinkConfigs []PagerDutyLinkConfigApplyConfiguration `json:"pagerDutyLinkConfigs,omitempty"` HTTPConfig *HTTPConfigApplyConfiguration `json:"httpConfig,omitempty"` Source *string `json:"source,omitempty"` + Timeout *v1.Duration `json:"timeout,omitempty"` } // PagerDutyConfigApplyConfiguration constructs a declarative configuration of the PagerDutyConfig type for use with @@ -185,3 +190,11 @@ func (b *PagerDutyConfigApplyConfiguration) WithSource(value string) *PagerDutyC b.Source = &value return b } + +// WithTimeout sets the Timeout field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Timeout field is set to the value of the last call. +func (b *PagerDutyConfigApplyConfiguration) WithTimeout(value v1.Duration) *PagerDutyConfigApplyConfiguration { + b.Timeout = &value + return b +}