Skip to content

refactor(sns): move configuration types into sns package#5385

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

refactor(sns): move configuration types into sns package#5385
TheMeier wants to merge 1 commit into
prometheus:mainfrom
TheMeier:sns_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 July 14, 2026 18:04
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

SNS configuration ownership moves from config to notify/sns. Receiver configuration, notifier constructors, HTTP helpers, and tests now use sns.SNSConfig, while SNS defaults and YAML validation are defined in the notifier package.

Changes

SNS configuration migration

Layer / File(s) Summary
Define SNS configuration contract
notify/sns/config.go, notify/sns/config_test.go
Adds SNSConfig, default values, YAML validation, and table-driven validation tests.
Wire receiver configuration to notify/sns
config/config.go, config/notifiers.go, config/notifiers_test.go
Updates Receiver.SNSConfigs to use sns.SNSConfig and removes the former config-package SNS definitions and tests.
Update notifier contracts and tests
notify/sns/sns.go, notify/sns/sns_test.go
Changes notifier constructors, stored configuration, HTTP helpers, and test fixtures to use the local SNSConfig type.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main refactor: moving SNS configuration types into the sns package.
Description check ✅ Passed The description follows the template, includes checklist items, and correctly sets release notes to NONE.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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: 2

🤖 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/sns/config_test.go`:
- Around line 59-60: Add a test case in the notification configuration
validation tests covering simultaneous target_arn, topic_arn, and phone_number
values. Assert that validation fails for all three targets, guarding the
three-variable XOR behavior while preserving existing cases.

In `@notify/sns/config.go`:
- Around line 61-63: Update the SNS validation in the config validation method
around TargetARN, TopicARN, and PhoneNumber to count the non-empty targets and
return the existing error unless exactly one is provided. Remove the chained
boolean XOR condition and preserve the current error message.
🪄 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: e4e97394-bcaf-44f4-bb7f-4cebab72d509

📥 Commits

Reviewing files that changed from the base of the PR and between 3d96a34 and 8897168.

📒 Files selected for processing (7)
  • config/config.go
  • config/notifiers.go
  • config/notifiers_test.go
  • notify/sns/config.go
  • notify/sns/config_test.go
  • notify/sns/sns.go
  • notify/sns/sns_test.go
💤 Files with no reviewable changes (2)
  • config/notifiers_test.go
  • config/notifiers.go

Comment thread notify/sns/config_test.go
Comment thread notify/sns/config.go
Comment on lines +61 to +63
if (c.TargetARN == "") != (c.TopicARN == "") != (c.PhoneNumber == "") {
return errors.New("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fix the boolean logic to correctly enforce that exactly one target is provided.

Chaining != operators on booleans acts as an XOR operation. A three-variable XOR (A != B != C) evaluates to false when exactly one variable is false (correct), but it also evaluates to false when all three variables are false.

Therefore, if a user provides target_arn, topic_arn, and phone_number at the same time, this condition will evaluate to false and incorrectly accept the configuration without returning an error.

Replace it with a simple counter for readability and correctness.

🐛 Proposed fix
-	if (c.TargetARN == "") != (c.TopicARN == "") != (c.PhoneNumber == "") {
-		return errors.New("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config")
+	targets := 0
+	if c.TargetARN != "" {
+		targets++
+	}
+	if c.TopicARN != "" {
+		targets++
+	}
+	if c.PhoneNumber != "" {
+		targets++
+	}
+	if targets != 1 {
+		return errors.New("must provide exactly one of Target ARN, Topic ARN, or Phone Number for SNS 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
if (c.TargetARN == "") != (c.TopicARN == "") != (c.PhoneNumber == "") {
return errors.New("must provide either a Target ARN, Topic ARN, or Phone Number for SNS config")
}
targets := 0
if c.TargetARN != "" {
targets++
}
if c.TopicARN != "" {
targets++
}
if c.PhoneNumber != "" {
targets++
}
if targets != 1 {
return errors.New("must provide exactly one of Target ARN, Topic ARN, or Phone Number for SNS config")
}
🤖 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/sns/config.go` around lines 61 - 63, Update the SNS validation in the
config validation method around TargetARN, TopicARN, and PhoneNumber to count
the non-empty targets and return the existing error unless exactly one is
provided. Remove the chained boolean XOR condition and preserve the current
error message.

Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>

@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 `@config/config.go`:
- Line 989: Restore the exported config.SNSConfig symbol by adding a type alias
to sns.SNSConfig in the config package, while keeping SNSConfigs’ existing field
type and tags unchanged.
🪄 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: 092e6112-609d-4ec9-ac93-5a61a46c371b

📥 Commits

Reviewing files that changed from the base of the PR and between 20ea3bf and 7fe5440.

📒 Files selected for processing (7)
  • config/config.go
  • config/notifiers.go
  • config/notifiers_test.go
  • notify/sns/config.go
  • notify/sns/config_test.go
  • notify/sns/sns.go
  • notify/sns/sns_test.go
💤 Files with no reviewable changes (2)
  • config/notifiers.go
  • config/notifiers_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • notify/sns/config.go
  • notify/sns/sns.go
  • notify/sns/sns_test.go
  • notify/sns/config_test.go

Comment thread config/config.go
PushoverConfigs []*PushoverConfig `yaml:"pushover_configs,omitempty" json:"pushover_configs,omitempty"`
VictorOpsConfigs []*VictorOpsConfig `yaml:"victorops_configs,omitempty" json:"victorops_configs,omitempty"`
SNSConfigs []*SNSConfig `yaml:"sns_configs,omitempty" json:"sns_configs,omitempty"`
SNSConfigs []*sns.SNSConfig `yaml:"sns_configs,omitempty" json:"sns_configs,omitempty"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Files mentioning config.SNSConfig:\n'
rg -n --hidden --glob '!**/vendor/**' '\bconfig\.SNSConfig\b' .

printf '\nDefinitions of SNSConfig in config package:\n'
rg -n --hidden --glob '!**/vendor/**' 'type\s+SNSConfig\b|SNSConfig\s*=' config

printf '\nNearby context in config/config.go around line 989 and any SNSConfig definitions:\n'
python3 - <<'PY'
from pathlib import Path
p = Path('config/config.go')
lines = p.read_text().splitlines()
for start in [930, 970, 980, 990, 1000]:
    if start <= len(lines):
        end = min(len(lines), start+35)
        print(f"\n--- {p}:{start}-{end} ---")
        for i in range(start-1, end):
            print(f"{i+1:4d}: {lines[i]}")
PY

Repository: prometheus/alertmanager

Length of output: 196


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'SNSConfig declarations/aliases in config package:\n'
rg -n --hidden --glob '!**/vendor/**' 'type\s+SNSConfig\b|SNSConfig\s*=' config

printf '\nReceiver and related SNS snippets from config/config.go:\n'
python3 - <<'PY'
from pathlib import Path
p = Path('config/config.go')
lines = p.read_text().splitlines()
targets = []
for i, line in enumerate(lines, 1):
    if 'SNSConfig' in line or 'SNSConfigs' in line:
        targets.append(i)
for i in targets[:20]:
    start = max(1, i-8)
    end = min(len(lines), i+8)
    print(f"\n--- {p}:{start}-{end} ---")
    for j in range(start, end+1):
        print(f"{j:4d}: {lines[j-1]}")
PY

Repository: prometheus/alertmanager

Length of output: 211


Preserve the exported config.SNSConfig alias.

This removes the config.SNSConfig symbol and breaks downstream code that still imports config. If config is a supported API, add a compatibility alias such as type SNSConfig = sns.SNSConfig.

🤖 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 `@config/config.go` at line 989, Restore the exported config.SNSConfig symbol
by adding a type alias to sns.SNSConfig in the config package, while keeping
SNSConfigs’ existing field type and tags unchanged.

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.

1 participant