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

Changes receiver and inhibition rules arrays to slices of value items instead of pointer items #3209

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cmd/alertmanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const defaultClusterAddr = "0.0.0.0:9094"

// buildReceiverIntegrations builds a list of integration notifiers off of a
// receiver config.
func buildReceiverIntegrations(nc *config.Receiver, tmpl *template.Template, logger log.Logger) ([]notify.Integration, error) {
func buildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logger log.Logger) ([]notify.Integration, error) {
var (
errs types.MultiError
integrations []notify.Integration
Expand Down
6 changes: 3 additions & 3 deletions cmd/alertmanager/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func (s sendResolved) SendResolved() bool { return bool(s) }

func TestBuildReceiverIntegrations(t *testing.T) {
for _, tc := range []struct {
receiver *config.Receiver
receiver config.Receiver
err bool
exp []notify.Integration
}{
{
receiver: &config.Receiver{
receiver: config.Receiver{
Name: "foo",
WebhookConfigs: []*config.WebhookConfig{
{
Expand All @@ -56,7 +56,7 @@ func TestBuildReceiverIntegrations(t *testing.T) {
},
},
{
receiver: &config.Receiver{
receiver: config.Receiver{
Name: "foo",
WebhookConfigs: []*config.WebhookConfig{
{
Expand Down
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ func (ti *TimeInterval) UnmarshalYAML(unmarshal func(interface{}) error) error {

// Config is the top-level configuration for Alertmanager's config files.
type Config struct {
Global *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
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"`
Templates []string `yaml:"templates" json:"templates"`
Global *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
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"`
Templates []string `yaml:"templates" json:"templates"`
// Deprecated. Remove before v1.0 release.
MuteTimeIntervals []MuteTimeInterval `yaml:"mute_time_intervals,omitempty" json:"mute_time_intervals,omitempty"`
TimeIntervals []TimeInterval `yaml:"time_intervals,omitempty" json:"time_intervals,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ func TestEmptyFieldsAndRegex(t *testing.T) {
},
},
},
Receivers: []*Receiver{
Receivers: []Receiver{
{
Name: "team-X-mails",
EmailConfigs: []*EmailConfig{
Expand Down
4 changes: 2 additions & 2 deletions inhibit/inhibit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Inhibitor struct {
}

// NewInhibitor returns a new Inhibitor.
func NewInhibitor(ap provider.Alerts, rs []*config.InhibitRule, mk types.Marker, logger log.Logger) *Inhibitor {
func NewInhibitor(ap provider.Alerts, rs []config.InhibitRule, mk types.Marker, logger log.Logger) *Inhibitor {
ih := &Inhibitor{
alerts: ap,
marker: mk,
Expand Down Expand Up @@ -166,7 +166,7 @@ type InhibitRule struct {
}

// NewInhibitRule returns a new InhibitRule based on a configuration definition.
func NewInhibitRule(cr *config.InhibitRule) *InhibitRule {
func NewInhibitRule(cr config.InhibitRule) *InhibitRule {
var (
sourcem labels.Matchers
targetm labels.Matchers
Expand Down
10 changes: 5 additions & 5 deletions inhibit/inhibit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestInhibitRuleMatches(t *testing.T) {
}

m := types.NewMarker(prometheus.NewRegistry())
ih := NewInhibitor(nil, []*config.InhibitRule{&rule1, &rule2}, m, nopLogger)
ih := NewInhibitor(nil, []config.InhibitRule{rule1, rule2}, m, nopLogger)
now := time.Now()
// Active alert that matches the source filter of rule1.
sourceAlert1 := &types.Alert{
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestInhibitRuleMatchers(t *testing.T) {
}

m := types.NewMarker(prometheus.NewRegistry())
ih := NewInhibitor(nil, []*config.InhibitRule{&rule1, &rule2}, m, nopLogger)
ih := NewInhibitor(nil, []config.InhibitRule{rule1, rule2}, m, nopLogger)
now := time.Now()
// Active alert that matches the source filter of rule1.
sourceAlert1 := &types.Alert{
Expand Down Expand Up @@ -370,8 +370,8 @@ func TestInhibit(t *testing.T) {
t.Parallel()

now := time.Now()
inhibitRule := func() *config.InhibitRule {
return &config.InhibitRule{
inhibitRule := func() config.InhibitRule {
return config.InhibitRule{
SourceMatch: map[string]string{"s": "1"},
TargetMatch: map[string]string{"t": "1"},
Equal: model.LabelNames{"e"},
Expand Down Expand Up @@ -452,7 +452,7 @@ func TestInhibit(t *testing.T) {
} {
ap := newFakeAlerts(tc.alerts)
mk := types.NewMarker(prometheus.NewRegistry())
inhibitor := NewInhibitor(ap, []*config.InhibitRule{inhibitRule()}, mk, nopLogger)
inhibitor := NewInhibitor(ap, []config.InhibitRule{inhibitRule()}, mk, nopLogger)

go func() {
for ap.finished != nil {
Expand Down
36 changes: 36 additions & 0 deletions test/with_api_v2/acceptance/inhibit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,39 @@ inhibit_rules:

t.Log(co.Check())
}

func TestEmptyInhibitionRule(t *testing.T) {
t.Parallel()

// This integration test checks that when we have empty inhibition rules,
// there is no panic caused by null-pointer references.

conf := `
route:
receiver: "default"
group_by: []
group_wait: 1s
group_interval: 1s
repeat_interval: 1s
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
inhibit_rules:
-
`

at := NewAcceptanceTest(t, &AcceptanceOpts{
Tolerance: 150 * time.Millisecond,
})

co := at.Collector("webhook")
wh := NewWebhook(t, co)

at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
at.Run()

t.Log(co.Check())
}