Skip to content

Commit

Permalink
support multiple same type of enrichments in a pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
83bytes committed Jun 30, 2024
1 parent e595614 commit f982c5b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion alert/processAlert.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ProcessAlert(a types.Alert) {
logr.Info("processing enrichment : ", v.EnrichmentName)

if f, ok := (*enrichmentMap)[v.EnrichmentName]; ok {
resMap[v.EnrichmentName], err = f(a, v)
resMap[v.StepName], err = f(a, v)
if err != nil {
fmt.Println(err)
}
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func ValidateAndLoad(b []byte) (*types.AlertManagerConfig, error) {
for _, v := range amConfig.AlertPipelines {
for _, e := range v.Enrichments {
if len(e.StepName) <= 0 {
return amConfig, fmt.Errorf("unable to load config, please check format")
return &types.AlertManagerConfig{}, fmt.Errorf("unable to load config, please check format")
}
}

for _, v := range v.Actions {
if len(v.StepName) <= 0 {
return amConfig, fmt.Errorf("unable to load config, please check format")
return &types.AlertManagerConfig{}, fmt.Errorf("unable to load config, please check format")
}
}
//
Expand Down
9 changes: 4 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,24 @@ func TestValidateAndLoad(t *testing.T) {
b: []byte(`randomKey: randonValue
randomKey2: randomValue2`),
},
want: types.AlertManagerConfig{},
want: types.AlertManagerConfig{}, // doesnt matter here
wantErr: true,
},
{
name: "noStepInConfig",
args: args{
b: []byte(badAlertConfigNoStepName),
},
want: types.DefaultAlertManagerConfig(),
wantErr: false,
want: types.AlertManagerConfig{}, // doesnt matter here
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ValidateAndLoad(tt.args.b)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateAndLoad() error = %v, wantErr %v", err, tt.wantErr)
return
t.Fatalf("ValidateAndLoad() error = %v, wantErr %v", err, tt.wantErr)
}

// dereference the pointer for got to make deepequal happy
Expand Down

0 comments on commit f982c5b

Please sign in to comment.