@@ -27,7 +27,7 @@ func Setup(ctx context.Context, logger log.Logger, conf *config.Config) (*Instan
2727 "check_name" : log .String (check .Name ),
2828 })
2929
30- client , err := provider .NewClient (checkLogger , cmp . Or (check .Alert , conf .Alert ))
30+ client , err := provider .NewClient (checkLogger , mergeAlertConfigs (check .Alert , conf .Alert ))
3131 if err != nil {
3232 return nil , fmt .Errorf ("setting up check[%d] provider: %w" , idx , err )
3333 }
@@ -67,7 +67,7 @@ func (xs *Instances) CheckIn(ctx context.Context, logger log.Logger, checkID str
6767 })
6868
6969 // Grab the provider client for the check
70- client , err := provider .NewClient (logger , cmp . Or (found .Alert , xs .conf .Alert ))
70+ client , err := provider .NewClient (logger , mergeAlertConfigs (found .Alert , xs .conf .Alert ))
7171 if err != nil {
7272 return nil , fmt .Errorf ("problem getting client for check-in: %w" , err )
7373 }
@@ -82,3 +82,23 @@ func (xs *Instances) CheckIn(ctx context.Context, logger log.Logger, checkID str
8282 NextExpectedCheckIn : checkInExpected ,
8383 }, nil
8484}
85+
86+ func mergeAlertConfigs (local , global config.Alert ) config.Alert {
87+ var out config.Alert
88+
89+ // PagerDuty config merging
90+ out .PagerDuty = cmp .Or (local .PagerDuty , global .PagerDuty )
91+
92+ if local .PagerDuty != nil && global .PagerDuty != nil {
93+ // Prefer the local config over the global config
94+ out .PagerDuty = & config.PagerDuty {
95+ ApiKey : cmp .Or (local .PagerDuty .ApiKey , global .PagerDuty .ApiKey ),
96+ EscalationPolicy : cmp .Or (local .PagerDuty .EscalationPolicy , global .PagerDuty .EscalationPolicy ),
97+ From : cmp .Or (local .PagerDuty .From , global .PagerDuty .From ),
98+ RoutingKey : cmp .Or (local .PagerDuty .RoutingKey , global .PagerDuty .RoutingKey ),
99+ Urgency : cmp .Or (local .PagerDuty .Urgency , global .PagerDuty .Urgency ),
100+ }
101+ }
102+
103+ return out
104+ }
0 commit comments