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

@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

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

PagerDuty configuration defaults and validation move into notify/pagerduty; the notifier, tests, and shared receiver configuration switch to the local types, while the previous definitions and tests are removed.

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, configuration fields, YAML unmarshalling, credential validation, detail defaults, source defaults, and corresponding tests.
Notifier switches to local config
notify/pagerduty/pagerduty.go, notify/pagerduty/pagerduty_test.go
The notifier constructor, internal configuration, and notifier tests use package-local PagerDuty configuration, link, and image types.
Shared config adopts PagerDuty package
config/config.go, config/notifiers.go, config/notifiers_test.go
The receiver references pagerduty.PagerdutyConfig, and the former shared PagerDuty definitions, defaults, and tests are removed.

Estimated code review effort: 3 (Moderate) | ~25 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 accurately summarizes the main change: moving PagerDuty config types into the pagerduty package.
Description check ✅ Passed The PR description follows the template and includes the checklist plus release-notes set to NONE for a no-user-facing-change refactor.
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.
✨ 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.

@TheMeier
TheMeier force-pushed the pagerduty_config branch from a5e642d to 5eb7cd3 Compare July 6, 2026 04:51
@TheMeier
TheMeier force-pushed the pagerduty_config branch 4 times, most recently from 0646fcf to 9fb2b47 Compare July 16, 2026 12:45
Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants