Repository navigation
bugfix ensure legacy matchers field is populated in snapshots - #5330
Conversation
Signed-off-by: Ethan Hunter <[email protected]>
Signed-off-by: Ethan Hunter <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughSnapshot marshalling now routes each silence through the compatibility-aware marshal path before writing. A regression test verifies the in-memory silence is unchanged and the encoded snapshot still contains the legacy matcher field. ChangesSilence snapshot compatibility
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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
🧹 Nitpick comments (1)
silence/state_test.go (1)
54-60: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winCover the “first matcher set wins” wire contract.
With only one
MatcherSet, this still passes ifMarshalBinaryaccidentally copies the wrong set into legacyMatchers. Adding a second distinct set would pin the backward-compatibility rule that the wireMatchersmirrorMatcherSets[0].Also applies to: 79-85
🤖 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 `@silence/state_test.go` around lines 54 - 60, The current test only uses one MatcherSet, so it can’t detect if MarshalBinary maps the wrong set into the legacy Matchers field. Update the silence/state_test.go coverage around Silence.MarshalBinary to build at least two distinct MatcherSets and assert that the wire legacy Matchers always mirror MatcherSets[0], using the existing pb.Silence, pb.MatcherSet, and MarshalBinary path to lock in the “first matcher set wins” contract.
🤖 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 `@silence/silence.go`:
- Around line 1369-1371: The error returned from marshalMeshSilence is missing
snapshot-generation context, so update the error handling in the marshal path to
wrap the failure with fmt.Errorf("generating snapshot: %w", err). Keep the
change localized to the code that calls marshalMeshSilence so the existing
diagnostic context is preserved consistently with the repository’s Go
error-handling pattern.
---
Nitpick comments:
In `@silence/state_test.go`:
- Around line 54-60: The current test only uses one MatcherSet, so it can’t
detect if MarshalBinary maps the wrong set into the legacy Matchers field.
Update the silence/state_test.go coverage around Silence.MarshalBinary to build
at least two distinct MatcherSets and assert that the wire legacy Matchers
always mirror MatcherSets[0], using the existing pb.Silence, pb.MatcherSet, and
MarshalBinary path to lock in the “first matcher set wins” contract.
🪄 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: 72cf88b6-f21e-4cd8-8964-fc909a4f6ae2
📒 Files selected for processing (2)
silence/silence.gosilence/state_test.go
| b, err := marshalMeshSilence(e) | ||
| if err != nil { | ||
| return nil, err |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
cat -n silence/silence.go | sed -n '1360,1380p'Repository: prometheus/alertmanager
Length of output: 658
🏁 Script executed:
grep -n "return nil, err\|return err\|fmt.Errorf.*err" silence/silence.go | head -30Repository: prometheus/alertmanager
Length of output: 1291
🏁 Script executed:
head -50 silence/silence.go | grep -E "import|\"fmt\""Repository: prometheus/alertmanager
Length of output: 177
🏁 Script executed:
grep -B20 "func (s state) MarshalBinary" silence/silence.go | head -25Repository: prometheus/alertmanager
Length of output: 723
🏁 Script executed:
sed -n '1,30p' silence/silence.go | grep "import\|\""Repository: prometheus/alertmanager
Length of output: 417
Wrap the marshal failure with snapshot context.
Returning the raw error from marshalMeshSilence here obscures the operation being performed. Please wrap the error with fmt.Errorf("generating snapshot: %w", err) to maintain diagnostic context, consistent with the repository's error-handling guidelines for Go code.
🤖 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 `@silence/silence.go` around lines 1369 - 1371, The error returned from
marshalMeshSilence is missing snapshot-generation context, so update the error
handling in the marshal path to wrap the failure with fmt.Errorf("generating
snapshot: %w", err). Keep the change localized to the code that calls
marshalMeshSilence so the existing diagnostic context is preserved consistently
with the repository’s Go error-handling pattern.
Source: Coding guidelines
Signed-off-by: Ethan Hunter <[email protected]>
Changes
silences.stateto usemarshalMeshSilencewhen writing a snapshot to match the behavior of sending a gossip message.marhsalMeshSilenceensures that the legacymatchersfield is populated (which allows older Alertmanager versions to read the message). This fixes a bug when downgrading to older versions of Alertmanager that don't support the new fields. While downgrades are not generally supported, this specific case was meant to be backwards and forwards compatible.Pull Request Checklist
Please check all the applicable boxes.
Which user-facing changes does this PR introduce?