Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ttl obj to alertmanagercfgs resource #6515

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c94dc12
add ttl obj into alertmanagerConfig rsc
afzal442 Apr 14, 2024
25e0aaa
add generated CR
afzal442 Apr 15, 2024
2747edb
rmvs extra commented stmt
afzal442 Apr 16, 2024
77a2282
fixes a linting issue
afzal442 Apr 16, 2024
036ba68
add ttl supported version test case
afzal442 Apr 17, 2024
8244c95
Merge branch 'main' into add-ttl-alertmanagercfgs
afzal442 Apr 25, 2024
31e1e9c
fixes lint issues
afzal442 Apr 25, 2024
84e6e26
minor fixes
afzal442 May 9, 2024
84a8df4
Merge remote-tracking branch 'upstream/main' into add-ttl-alertmanage…
afzal442 May 9, 2024
8b3dc39
reformats the pkg call
afzal442 May 9, 2024
58ec600
Adds pushover config over alert manager
afzal442 May 15, 2024
b195b02
Merge branch 'main' into add-ttl-alertmanagercfgs
afzal442 May 16, 2024
b91e0b8
Merge branch 'prometheus-operator:main' into add-ttl-alertmanagercfgs
afzal442 May 17, 2024
2588071
Adds prom model pkg to client
afzal442 May 17, 2024
d044d93
Updated ttl type to v1.Duration custom type
afzal442 May 31, 2024
6018fff
Reverted the ttl obj for alertmanager struct
afzal442 Jun 4, 2024
540bac6
minor fixes
afzal442 Jun 9, 2024
9269e2e
updates the go modules
afzal442 Jun 9, 2024
0117428
updates the docs
afzal442 Jun 9, 2024
1cb8592
rmvs conflict with docs
afzal442 Jun 9, 2024
5d144c7
Reverts the go mod changes
afzal442 Jun 11, 2024
bcdfd9f
updated api
afzal442 Jun 11, 2024
cbf9057
Merge remote-tracking branch 'upstream/main' into add-ttl-alertmanage…
afzal442 Jun 11, 2024
23f6f08
Fixes minor space issue
afzal442 Jun 11, 2024
9de0b67
Minor chronological issue fixed
afzal442 Jun 11, 2024
6bfeb10
refactored the type to string
afzal442 Jun 13, 2024
43fea21
Updated the type string to custom type
afzal442 Jun 19, 2024
8901002
Added TTL check in convertPushoverconfig
afzal442 Jun 19, 2024
338172f
Merge remote-tracking branch 'upstream/main' into add-ttl-alertmanage…
afzal442 Jun 19, 2024
db0680b
Updated TTL in/output
afzal442 Jun 19, 2024
a6d203c
Update pkg/alertmanager/amcfg.go
simonpasquier Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion Documentation/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions bundle.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions jsonnet/prometheus-operator/alertmanagerconfigs-crd.json
Original file line number Diff line number Diff line change
Expand Up @@ -5921,6 +5921,11 @@
}
},
"type": "object"
},
"ttl": {
"description": "The time to live definition for the alert notification",
"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"
}
},
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5831,6 +5831,11 @@
},
type: 'array',
},
ttl: {
description: 'The time to live definition for the alert notification',
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',
},
},
type: 'object',
},
Expand Down
8 changes: 8 additions & 0 deletions pkg/alertmanager/amcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,14 @@ func (c *alertmanagerConfig) sanitize(amVersion semver.Version, logger log.Logge
}
}

if c.TTL != nil && amVersion.LT(semver.MustParse("0.27.0")) {
level.Warn(logger).Log(
"msg", "'ttl' supported in Alertmanager >= 0.27.0 only - dropping field from provided config",
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
"current_version", amVersion.String(),
)
c.TTL = nil
}

return c.Route.sanitize(amVersion, logger)
}

Expand Down
23 changes: 23 additions & 0 deletions pkg/alertmanager/amcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,9 @@ func TestSanitizeConfig(t *testing.T) {
versionMSTeamsSummaryAllowed := semver.Version{Major: 0, Minor: 27}
versionMSTeamsSummaryNotAllowed := semver.Version{Major: 0, Minor: 26}

versionTTLAllowed := semver.Version{Major: 0, Minor: 27}
versionTTLNotAllowed := semver.Version{Major: 0, Minor: 26}

for _, tc := range []struct {
name string
againstVersion semver.Version
Expand Down Expand Up @@ -2264,6 +2267,26 @@ func TestSanitizeConfig(t *testing.T) {
},
},
},
{
name: "Test TTL configuration is allowed for supported versions",
againstVersion: versionTTLAllowed,
in: &alertmanagerConfig{
TTL: ptr.To(monitoringingv1.Duration("1h")),
},
expect: alertmanagerConfig{
TTL: ptr.To(monitoringingv1.Duration("1h")),
},
},
{
name: "Test TTL configuration is dropped for unsupported versions",
againstVersion: versionTTLNotAllowed,
in: &alertmanagerConfig{
TTL: ptr.To(monitoringingv1.Duration("30s")),
},
expect: alertmanagerConfig{
TTL: nil,
},
},
{
name: "Test inhibit rules error with unsupported syntax",
againstVersion: matcherV2SyntaxNotAllowed,
Expand Down
3 changes: 3 additions & 0 deletions pkg/alertmanager/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

"github.com/prometheus/alertmanager/config"
"github.com/prometheus/common/model"

v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
)

// Customization of Config type from alertmanager repo:
Expand All @@ -29,6 +31,7 @@ import (
// https://github.com/prometheus/alertmanager/issues/1985
type alertmanagerConfig struct {
Global *globalConfig `yaml:"global,omitempty" json:"global,omitempty"`
TTL *v1.Duration `yaml:"ttl,omitempty" json:"ttl,omitempty"`
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
Route *route `yaml:"route,omitempty" json:"route,omitempty"`
InhibitRules []*inhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"`
Receivers []*receiver `yaml:"receivers,omitempty" json:"receivers,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/monitoring/v1alpha1/alertmanager_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type AlertmanagerConfigList struct {
// By definition, the Alertmanager configuration only applies to alerts for which
// the `namespace` label is equal to the namespace of the AlertmanagerConfig resource.
type AlertmanagerConfigSpec struct {
// The time to live definition for the alert notification
// +optional
TTL *monitoringv1.Duration `json:"ttl,omitempty"`
afzal442 marked this conversation as resolved.
Show resolved Hide resolved
// The Alertmanager route definition for alerts matching the resource's
// namespace. If present, it will be added to the generated Alertmanager
// configuration as a first-level route.
Expand Down
Loading
Loading