refactor(pagerduty): move configuration types into pagerduty package#5325
refactor(pagerduty): move configuration types into pagerduty package#5325TheMeier wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughPagerDuty configuration defaults and validation move into ChangesPagerDuty config relocation
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@notify/pagerduty/config.go`:
- Around line 86-112: PagerdutyConfig.UnmarshalYAML leaves HTTPConfig nil when
http_config is omitted, which later causes a panic in PagerdutyConfig.Build when
it dereferences c.HTTPConfig. Initialize HTTPConfig to a default value during
unmarshal, alongside the existing defaulting for Details and Source, so existing
receivers created through Receiver/config wiring work without requiring explicit
http_config.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 91706aac-d9b9-42c9-a295-33acb81dd808
📒 Files selected for processing (7)
config/config.goconfig/notifiers.goconfig/notifiers_test.gonotify/pagerduty/config.gonotify/pagerduty/config_test.gonotify/pagerduty/pagerduty.gonotify/pagerduty/pagerduty_test.go
💤 Files with no reviewable changes (2)
- config/notifiers_test.go
- config/notifiers.go
| func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(any) error) error { | ||
| *c = DefaultPagerdutyConfig | ||
| type plain PagerdutyConfig | ||
| if err := unmarshal((*plain)(c)); err != nil { | ||
| return err | ||
| } | ||
| if c.RoutingKey == "" && c.ServiceKey == "" && c.RoutingKeyFile == "" && c.ServiceKeyFile == "" { | ||
| return errors.New("missing service or routing key in PagerDuty config") | ||
| } | ||
| if len(c.RoutingKey) > 0 && len(c.RoutingKeyFile) > 0 { | ||
| return errors.New("at most one of routing_key & routing_key_file must be configured") | ||
| } | ||
| if len(c.ServiceKey) > 0 && len(c.ServiceKeyFile) > 0 { | ||
| return errors.New("at most one of service_key & service_key_file must be configured") | ||
| } | ||
| if c.Details == nil { | ||
| c.Details = make(map[string]any) | ||
| } | ||
| if c.Source == "" { | ||
| c.Source = c.Client | ||
| } | ||
| for k, v := range DefaultPagerdutyDetails { | ||
| if _, ok := c.Details[k]; !ok { | ||
| c.Details[k] = v | ||
| } | ||
| } | ||
| return nil |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win
Initialize HTTPConfig during YAML unmarshal.
PagerdutyConfig.HTTPConfig stays nil when http_config is omitted, but Line 57 in notify/pagerduty/pagerduty.go dereferences *c.HTTPConfig for every notifier build. With Line 960 in config/config.go now wiring this type into Receiver, an existing PagerDuty receiver without explicit http_config will panic at startup.
💡 Suggested fix
func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(any) error) error {
*c = DefaultPagerdutyConfig
type plain PagerdutyConfig
if err := unmarshal((*plain)(c)); err != nil {
return err
}
+ if c.HTTPConfig == nil {
+ c.HTTPConfig = &commoncfg.HTTPClientConfig{}
+ }
if c.RoutingKey == "" && c.ServiceKey == "" && c.RoutingKeyFile == "" && c.ServiceKeyFile == "" {
return errors.New("missing service or routing key in PagerDuty config")
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(any) error) error { | |
| *c = DefaultPagerdutyConfig | |
| type plain PagerdutyConfig | |
| if err := unmarshal((*plain)(c)); err != nil { | |
| return err | |
| } | |
| if c.RoutingKey == "" && c.ServiceKey == "" && c.RoutingKeyFile == "" && c.ServiceKeyFile == "" { | |
| return errors.New("missing service or routing key in PagerDuty config") | |
| } | |
| if len(c.RoutingKey) > 0 && len(c.RoutingKeyFile) > 0 { | |
| return errors.New("at most one of routing_key & routing_key_file must be configured") | |
| } | |
| if len(c.ServiceKey) > 0 && len(c.ServiceKeyFile) > 0 { | |
| return errors.New("at most one of service_key & service_key_file must be configured") | |
| } | |
| if c.Details == nil { | |
| c.Details = make(map[string]any) | |
| } | |
| if c.Source == "" { | |
| c.Source = c.Client | |
| } | |
| for k, v := range DefaultPagerdutyDetails { | |
| if _, ok := c.Details[k]; !ok { | |
| c.Details[k] = v | |
| } | |
| } | |
| return nil | |
| func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(any) error) error { | |
| *c = DefaultPagerdutyConfig | |
| type plain PagerdutyConfig | |
| if err := unmarshal((*plain)(c)); err != nil { | |
| return err | |
| } | |
| if c.HTTPConfig == nil { | |
| c.HTTPConfig = &commoncfg.HTTPClientConfig{} | |
| } | |
| if c.RoutingKey == "" && c.ServiceKey == "" && c.RoutingKeyFile == "" && c.ServiceKeyFile == "" { | |
| return errors.New("missing service or routing key in PagerDuty config") | |
| } | |
| if len(c.RoutingKey) > 0 && len(c.RoutingKeyFile) > 0 { | |
| return errors.New("at most one of routing_key & routing_key_file must be configured") | |
| } | |
| if len(c.ServiceKey) > 0 && len(c.ServiceKeyFile) > 0 { | |
| return errors.New("at most one of service_key & service_key_file must be configured") | |
| } | |
| if c.Details == nil { | |
| c.Details = make(map[string]any) | |
| } | |
| if c.Source == "" { | |
| c.Source = c.Client | |
| } | |
| for k, v := range DefaultPagerdutyDetails { | |
| if _, ok := c.Details[k]; !ok { | |
| c.Details[k] = v | |
| } | |
| } | |
| return nil | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@notify/pagerduty/config.go` around lines 86 - 112,
PagerdutyConfig.UnmarshalYAML leaves HTTPConfig nil when http_config is omitted,
which later causes a panic in PagerdutyConfig.Build when it dereferences
c.HTTPConfig. Initialize HTTPConfig to a default value during unmarshal,
alongside the existing defaulting for Details and Source, so existing receivers
created through Receiver/config wiring work without requiring explicit
http_config.
a5e642d to
5eb7cd3
Compare
0646fcf to
9fb2b47
Compare
Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
9fb2b47 to
cb89682
Compare
Pull Request Checklist
Which user-facing changes does this PR introduce?