Skip to content

Commit df1dc0d

Browse files
committed
Changes receiver and inhibition rules arrays to slices of value items
Signed-off-by: Rohan Gupta <[email protected]>
1 parent 0ba6441 commit df1dc0d

File tree

7 files changed

+53
-17
lines changed

7 files changed

+53
-17
lines changed

cmd/alertmanager/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const defaultClusterAddr = "0.0.0.0:9094"
131131

132132
// buildReceiverIntegrations builds a list of integration notifiers off of a
133133
// receiver config.
134-
func buildReceiverIntegrations(nc *config.Receiver, tmpl *template.Template, logger log.Logger) ([]notify.Integration, error) {
134+
func buildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logger log.Logger) ([]notify.Integration, error) {
135135
var (
136136
errs types.MultiError
137137
integrations []notify.Integration

cmd/alertmanager/main_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ func (s sendResolved) SendResolved() bool { return bool(s) }
3131

3232
func TestBuildReceiverIntegrations(t *testing.T) {
3333
for _, tc := range []struct {
34-
receiver *config.Receiver
34+
receiver config.Receiver
3535
err bool
3636
exp []notify.Integration
3737
}{
3838
{
39-
receiver: &config.Receiver{
39+
receiver: config.Receiver{
4040
Name: "foo",
4141
WebhookConfigs: []*config.WebhookConfig{
4242
{
@@ -56,7 +56,7 @@ func TestBuildReceiverIntegrations(t *testing.T) {
5656
},
5757
},
5858
{
59-
receiver: &config.Receiver{
59+
receiver: config.Receiver{
6060
Name: "foo",
6161
WebhookConfigs: []*config.WebhookConfig{
6262
{

config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,11 @@ func (ti *TimeInterval) UnmarshalYAML(unmarshal func(interface{}) error) error {
295295

296296
// Config is the top-level configuration for Alertmanager's config files.
297297
type Config struct {
298-
Global *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
299-
Route *Route `yaml:"route,omitempty" json:"route,omitempty"`
300-
InhibitRules []*InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"`
301-
Receivers []*Receiver `yaml:"receivers,omitempty" json:"receivers,omitempty"`
302-
Templates []string `yaml:"templates" json:"templates"`
298+
Global *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
299+
Route *Route `yaml:"route,omitempty" json:"route,omitempty"`
300+
InhibitRules []InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"`
301+
Receivers []Receiver `yaml:"receivers,omitempty" json:"receivers,omitempty"`
302+
Templates []string `yaml:"templates" json:"templates"`
303303
// Deprecated. Remove before v1.0 release.
304304
MuteTimeIntervals []MuteTimeInterval `yaml:"mute_time_intervals,omitempty" json:"mute_time_intervals,omitempty"`
305305
TimeIntervals []TimeInterval `yaml:"time_intervals,omitempty" json:"time_intervals,omitempty"`

config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ func TestEmptyFieldsAndRegex(t *testing.T) {
895895
},
896896
},
897897
},
898-
Receivers: []*Receiver{
898+
Receivers: []Receiver{
899899
{
900900
Name: "team-X-mails",
901901
EmailConfigs: []*EmailConfig{

inhibit/inhibit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type Inhibitor struct {
4444
}
4545

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

168168
// NewInhibitRule returns a new InhibitRule based on a configuration definition.
169-
func NewInhibitRule(cr *config.InhibitRule) *InhibitRule {
169+
func NewInhibitRule(cr config.InhibitRule) *InhibitRule {
170170
var (
171171
sourcem labels.Matchers
172172
targetm labels.Matchers

inhibit/inhibit_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestInhibitRuleMatches(t *testing.T) {
153153
}
154154

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

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

372372
now := time.Now()
373-
inhibitRule := func() *config.InhibitRule {
374-
return &config.InhibitRule{
373+
inhibitRule := func() config.InhibitRule {
374+
return config.InhibitRule{
375375
SourceMatch: map[string]string{"s": "1"},
376376
TargetMatch: map[string]string{"t": "1"},
377377
Equal: model.LabelNames{"e"},
@@ -452,7 +452,7 @@ func TestInhibit(t *testing.T) {
452452
} {
453453
ap := newFakeAlerts(tc.alerts)
454454
mk := types.NewMarker(prometheus.NewRegistry())
455-
inhibitor := NewInhibitor(ap, []*config.InhibitRule{inhibitRule()}, mk, nopLogger)
455+
inhibitor := NewInhibitor(ap, []config.InhibitRule{inhibitRule()}, mk, nopLogger)
456456

457457
go func() {
458458
for ap.finished != nil {

test/with_api_v2/acceptance/inhibit_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,39 @@ inhibit_rules:
154154

155155
t.Log(co.Check())
156156
}
157+
158+
func TestEmptyInhibitionRule(t *testing.T) {
159+
t.Parallel()
160+
161+
// This integration test checks that when we have empty inhibition rules,
162+
// there is no panic caused by null-pointer references.
163+
164+
conf := `
165+
route:
166+
receiver: "default"
167+
group_by: []
168+
group_wait: 1s
169+
group_interval: 1s
170+
repeat_interval: 1s
171+
172+
receivers:
173+
- name: "default"
174+
webhook_configs:
175+
- url: 'http://%s'
176+
177+
inhibit_rules:
178+
-
179+
`
180+
181+
at := NewAcceptanceTest(t, &AcceptanceOpts{
182+
Tolerance: 150 * time.Millisecond,
183+
})
184+
185+
co := at.Collector("webhook")
186+
wh := NewWebhook(t, co)
187+
188+
at.AlertmanagerCluster(fmt.Sprintf(conf, wh.Address()), 1)
189+
at.Run()
190+
191+
t.Log(co.Check())
192+
}

0 commit comments

Comments
 (0)