Skip to content

refactor(pagerduty): move configuration types into pagerduty package#5325

Open
TheMeier wants to merge 1 commit into
prometheus:mainfrom
TheMeier:pagerduty_config
Open

refactor(pagerduty): move configuration types into pagerduty package#5325
TheMeier wants to merge 1 commit into
prometheus:mainfrom
TheMeier:pagerduty_config

Conversation

@TheMeier

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Which user-facing changes does this PR introduce?

NONE
Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
@TheMeier TheMeier requested a review from a team as a code owner June 25, 2026 04:19
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

PagerDuty config defaults and validation move into notify/pagerduty, the notifier and its tests switch to those local types, and config now references the new PagerDuty config type while removing the old in-package definitions and tests.

Changes

PagerDuty config relocation

Layer / File(s) Summary
PagerDuty config module and validation
notify/pagerduty/config.go, notify/pagerduty/config_test.go
Defines PagerDuty defaults, config fields, YAML unmarshalling, and tests for routing key, service key, details, and source handling.
Notifier uses local PagerDuty config
notify/pagerduty/pagerduty.go
The PagerDuty notifier constructor and internal config field now use the package-local PagerDuty config type.
PagerDuty tests use local types
notify/pagerduty/pagerduty_test.go
PagerDuty notifier tests now construct package-local config, link, and image types throughout.
Shared config switches to PagerDuty package
config/config.go, config/notifiers.go, config/notifiers_test.go
config/config.go now imports the PagerDuty config type, and the old in-package PagerDuty defaults, types, and tests are removed from config.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately describes the main PagerDuty config refactor.
Description check ✅ Passed The description follows the repository template and includes the checklist plus release-notes marked NONE.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d4284cf and 501568e.

📒 Files selected for processing (7)
  • config/config.go
  • config/notifiers.go
  • config/notifiers_test.go
  • notify/pagerduty/config.go
  • notify/pagerduty/config_test.go
  • notify/pagerduty/pagerduty.go
  • notify/pagerduty/pagerduty_test.go
💤 Files with no reviewable changes (2)
  • config/notifiers_test.go
  • config/notifiers.go
Comment on lines +86 to +112
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.

Suggested change
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant