Conversation
524ffdc to
c524d30
Compare
|
Needs a rebase. |
c524d30 to
0d00817
Compare
|
i rebased, but the history is not super clean, should i squash? |
|
Squashing the commit sounds like a good idea to me. Just a question would it make sense to add a minimal test for the new function? |
|
probably! not sure where to start with that though |
|
How about something like this TheMeier@ada4ea8 |
that looks fantastic. |
|
So how about you steal it into your branch and then squash everything ;) |
0d00817 to
b128ac0
Compare
done! ... and rebased. |
b128ac0 to
1d339ce
Compare
|
so this has conflicted again, but before i start fixing this, perhaps it would be best to get a confirmation it's worth my time... ;) is this go or not? especially in view of log restructuring that's happening in parallel in #5072 |
Spaceman1701
left a comment
There was a problem hiding this comment.
I think this still makes sense in light of #5072 (which in my opinion is mostly for machine consumption).
1d339ce to
887ecc0
Compare
|
conflicts resolved, rebased. |
|
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:
📝 WalkthroughWalkthroughAdds a CLI flag Changes
sequenceDiagram
participant CLI as CLI (`main.go`)
participant Sil as Silences (`silence/silence.go`)
participant Log as Logger (slog)
CLI->>Sil: initialize with Options{Logging: flag}
Note right of Sil: runtime events (create/update/expire)
Sil->>Log: logSilence(msg, sil) when Logging=true
Log-->>Sil: write structured log output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@silence/silence_test.go`:
- Around line 2842-2866: The test builds a pb.Silence using time.Time for
StartsAt/EndsAt and sets Matchers directly, but pb.Silence.StartAt/EndsAt are
*timestamppb.Timestamp and production code moves matchers into MatcherSets via
Set()/validateSilence()/postprocessUnmarshalledSilence; update the test to
construct StartsAt and EndsAt using timestamppb.New(...) and to populate
MatcherSets (not Matchers) to mirror real post-processed silence objects, and
also update assertions/log expectations if logSilence was changed to read from
MatcherSets instead of Matchers.
In `@silence/silence.go`:
- Around line 1426-1449: logSilence currently iterates over sil.Matchers which
is cleared by postprocessUnmarshalledSilence after validateSilence, so matcher
info is never logged; update logSilence to iterate over sil.MatcherSets (e.g.,
loop through each MatcherSet and then its Matchers to build listMatchers)
instead of sil.Matchers, preserving the same formatting logic and using the
existing matcherTypeOperator mapping; this change ties into functions Set,
validateSilence and postprocessUnmarshalledSilence where MatcherSets is
populated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4e701aca-4089-4f2c-ad9a-b5d5f2d99e4a
📒 Files selected for processing (3)
cmd/alertmanager/main.gosilence/silence.gosilence/silence_test.go
887ecc0 to
a64d508
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
silence/silence.go (1)
1434-1438:⚠️ Potential issue | 🔴 Critical
logSilencereads the wrong matcher field, so matcher logs are effectively empty.At Line 1434,
logSilenceiteratessil.Matchers, but normal flows clear that field during postprocessing (see Line 1371) before these log calls run. Usesil.MatcherSetsinstead (and flatten each set’sMatchers).🐛 Proposed fix
func (s *Silences) logSilence(msg string, sil *pb.Silence) { var listMatchers []string matcherTypeOperator := map[string]string{ "EQUAL": "=", "REGEXP": "=~", "NOT_EQUAL": "!=", "NOT_REGEXP": "!~", } - for _, matcher := range sil.Matchers { - ms := []string{matcher.Name, matcherTypeOperator[matcher.Type.String()], matcher.Pattern} - m := strings.Join(ms, ``) - listMatchers = append(listMatchers, m) + for _, matcherSet := range sil.MatcherSets { + for _, matcher := range matcherSet.Matchers { + ms := []string{matcher.Name, matcherTypeOperator[matcher.Type.String()], matcher.Pattern} + m := strings.Join(ms, ``) + listMatchers = append(listMatchers, m) + } } strMatchers := strings.Join(listMatchers, `,`)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@silence/silence.go` around lines 1434 - 1438, The logSilence code is iterating sil.Matchers which is cleared earlier, producing empty matcher logs; change the loop to iterate sil.MatcherSets and for each MatcherSet iterate its Matchers to flatten them into listMatchers (preserving the existing string assembly using matcher.Name, matcherTypeOperator[matcher.Type.String()], matcher.Pattern); update the loop that builds listMatchers so it references MatcherSet.Matchers instead of sil.Matchers and append each formatted matcher string as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@silence/silence_test.go`:
- Around line 2868-2869: The two assertions use fmt.Printf (which returns (int,
error)) and an incorrect format string; replace fmt.Printf with fmt.Sprintf to
produce a string, use the time package constant time.RFC3339 in now.Format, and
for the EndsAt assertion format the expected timestamp as now.Add(time.Hour).For
example, change the require.Contains checks that reference logOutput and now to
compare against fmt.Sprintf("StartsAt=%s", now.Format(time.RFC3339)) and
fmt.Sprintf("EndsAt=%s", now.Add(time.Hour).Format(time.RFC3339)).
---
Duplicate comments:
In `@silence/silence.go`:
- Around line 1434-1438: The logSilence code is iterating sil.Matchers which is
cleared earlier, producing empty matcher logs; change the loop to iterate
sil.MatcherSets and for each MatcherSet iterate its Matchers to flatten them
into listMatchers (preserving the existing string assembly using matcher.Name,
matcherTypeOperator[matcher.Type.String()], matcher.Pattern); update the loop
that builds listMatchers so it references MatcherSet.Matchers instead of
sil.Matchers and append each formatted matcher string as before.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 425fea03-edfc-436a-b8a8-48a6c11024c3
📒 Files selected for processing (3)
cmd/alertmanager/main.gosilence/silence.gosilence/silence_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- cmd/alertmanager/main.go
a64d508 to
9ace411
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
silence/silence.go (1)
1434-1438:⚠️ Potential issue | 🔴 CriticalBug:
sil.Matchersis always empty whenlogSilenceis called.After
validateSilence()is called,postprocessUnmarshalledSilence()moves matchers toMatcherSetsand setssil.Matchers = nil(line 1371). Since all call sites invokelogSilenceafter validation, the matchers will never be logged.Iterate over
sil.MatcherSetsinstead.,
🐛 Proposed fix to iterate over MatcherSets
- for _, matcher := range sil.Matchers { - ms := []string{matcher.Name, matcherTypeOperator[matcher.Type.String()], matcher.Pattern} - m := strings.Join(ms, ``) - listMatchers = append(listMatchers, m) + for _, ms := range sil.MatcherSets { + for _, matcher := range ms.Matchers { + m := matcher.Name + matcherTypeOperator[matcher.Type.String()] + matcher.Pattern + listMatchers = append(listMatchers, m) + } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@silence/silence.go` around lines 1434 - 1438, logSilence currently iterates sil.Matchers which is cleared by postprocessUnmarshalledSilence; change logSilence to iterate sil.MatcherSets instead. Specifically, replace the loop over sil.Matchers with a loop over sil.MatcherSets, and for each MatcherSet iterate its Matchers to build the ms string (using Matcher.Name, matcherTypeOperator[Matcher.Type.String()], Matcher.Pattern) and append to listMatchers; keep the same string-joining and append logic so the output format is unchanged. Ensure references to sil.Matchers are removed/updated and only sil.MatcherSets, MatcherSet.Match ers, and the existing matcherTypeOperator mapping are used.
🧹 Nitpick comments (1)
silence/silence.go (1)
1446-1447: Timestamp format may not be human-readable.Passing
*timestamppb.Timestampdirectly to slog will use the protobufString()method, which produces a debug format likeseconds:1234 nanos:0rather than RFC3339. For readable logs, format explicitly.♻️ Proposed fix for RFC3339 formatting
s.logger.Info( msg, "Id", sil.Id, "CreatedBy", sil.CreatedBy, "Comment", sil.Comment, - "StartsAt", sil.StartsAt, - "EndsAt", sil.EndsAt, + "StartsAt", sil.StartsAt.AsTime().Format(time.RFC3339), + "EndsAt", sil.EndsAt.AsTime().Format(time.RFC3339), "Matchers", strMatchers, )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@silence/silence.go` around lines 1446 - 1447, The StartsAt/EndsAt fields are protobuf *timestamppb.Timestamp and will log as debug protobuf strings; convert each to a Go time and format using RFC3339 before passing to slog (e.g., use timestamppb.AsTime or t := sil.StartsAt.AsTime()/timestamppb.AsTime(sil.StartsAt) and then t.Format(time.RFC3339)), also guard for nil (use empty string or zero time) so the logging call that references "StartsAt" and "EndsAt" on the sil object emits human-readable RFC3339 timestamps instead of the protobuf String() output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@silence/silence.go`:
- Around line 1434-1438: logSilence currently iterates sil.Matchers which is
cleared by postprocessUnmarshalledSilence; change logSilence to iterate
sil.MatcherSets instead. Specifically, replace the loop over sil.Matchers with a
loop over sil.MatcherSets, and for each MatcherSet iterate its Matchers to build
the ms string (using Matcher.Name, matcherTypeOperator[Matcher.Type.String()],
Matcher.Pattern) and append to listMatchers; keep the same string-joining and
append logic so the output format is unchanged. Ensure references to
sil.Matchers are removed/updated and only sil.MatcherSets, MatcherSet.Match ers,
and the existing matcherTypeOperator mapping are used.
---
Nitpick comments:
In `@silence/silence.go`:
- Around line 1446-1447: The StartsAt/EndsAt fields are protobuf
*timestamppb.Timestamp and will log as debug protobuf strings; convert each to a
Go time and format using RFC3339 before passing to slog (e.g., use
timestamppb.AsTime or t :=
sil.StartsAt.AsTime()/timestamppb.AsTime(sil.StartsAt) and then
t.Format(time.RFC3339)), also guard for nil (use empty string or zero time) so
the logging call that references "StartsAt" and "EndsAt" on the sil object emits
human-readable RFC3339 timestamps instead of the protobuf String() output.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 71a525f1-eb5d-4fc6-baff-2bc073295289
📒 Files selected for processing (3)
cmd/alertmanager/main.gosilence/silence.gosilence/silence_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- cmd/alertmanager/main.go
- silence/silence_test.go
9ace411 to
6617ff3
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
silence/silence.go (1)
1442-1450: Consider using snake_case for log keys to match codebase conventions.Other logging in this file uses snake_case keys (e.g.,
"silence_id"at line 791,"err"throughout). Using PascalCase here creates inconsistency.♻️ Suggested change for consistency
s.logger.Info( msg, - "Id", sil.Id, - "CreatedBy", sil.CreatedBy, - "Comment", sil.Comment, - "StartsAt", sil.StartsAt.AsTime().Format(time.RFC3339), - "EndsAt", sil.EndsAt.AsTime().Format(time.RFC3339), - "Matchers", strMatchers, + "id", sil.Id, + "created_by", sil.CreatedBy, + "comment", sil.Comment, + "starts_at", sil.StartsAt.AsTime().Format(time.RFC3339), + "ends_at", sil.EndsAt.AsTime().Format(time.RFC3339), + "matchers", strMatchers, )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@silence/silence.go` around lines 1442 - 1450, The log call using s.logger.Info with keys "Id", "CreatedBy", "Comment", "StartsAt", "EndsAt", "Matchers" is inconsistent with the codebase snake_case convention; update the keys to snake_case (e.g., "silence_id" or "id" for sil.Id, "created_by" for sil.CreatedBy, "comment", "starts_at", "ends_at", "matchers") while keeping the same values (msg, sil.Id, sil.CreatedBy, sil.Comment, sil.StartsAt.AsTime().Format(...), sil.EndsAt.AsTime().Format(...), strMatchers) to match existing logging style used elsewhere in this file and preserve context from s.logger.Info.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@silence/silence.go`:
- Around line 1442-1450: The log call using s.logger.Info with keys "Id",
"CreatedBy", "Comment", "StartsAt", "EndsAt", "Matchers" is inconsistent with
the codebase snake_case convention; update the keys to snake_case (e.g.,
"silence_id" or "id" for sil.Id, "created_by" for sil.CreatedBy, "comment",
"starts_at", "ends_at", "matchers") while keeping the same values (msg, sil.Id,
sil.CreatedBy, sil.Comment, sil.StartsAt.AsTime().Format(...),
sil.EndsAt.AsTime().Format(...), strMatchers) to match existing logging style
used elsewhere in this file and preserve context from s.logger.Info.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a40b560b-0877-43b0-bca7-eb22233f79d3
📒 Files selected for processing (3)
cmd/alertmanager/main.gosilence/silence.gosilence/silence_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- cmd/alertmanager/main.go
- silence/silence_test.go
37a6eb9 to
3f79f4b
Compare
This code was originally written by m-masataka, but tweaked by anarcat, and re-tweaked by @coderabbitai, which seems to be an automated AI test suite that was introduced on the project recently. Tests were written by TheMeier. I reviewed the AI output and could not find any better way to do things. Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com> Signed-off-by: Antoine Beaupré <anarcat@debian.org> Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
3f79f4b to
d8c9da1
Compare
|
whoohoo! thanks! :) |
* [CHANGE] `go get github.com/prometheus/alertmanager/ui` will now fail as compiled UI assets are no longer checked into the repository. Downstream builds that rely on these assets being present in the source tree must now build the UI from source. prometheus#5113 * [CHANGE] The '--enable-feature=auto-gomaxprocs' option is deprecated and will be removed in v0.33. This flag currently has no effect and can be safely removed from any startup scripts. prometheus#5090 * [CHANGE] Update internal function signatures across multiple packages. This affects any project that integrates `Alertmanager` code. * [ENHANCEMENT] Add static asset caching. prometheus#5113 * [ENHANCEMENT] Reduce memory allocations through pre-sizing collections and batch allocation. prometheus#5020 * [ENHANCEMENT] Replace help with documentation in navigation bar. prometheus#4943 * [ENHANCEMENT] docs(ha): Update high availability documentation. prometheus#5136 * [ENHANCEMENT] docs: Add `auth_secret_file` for smtp in document. prometheus#5036 * [ENHANCEMENT] docs: Add description for global `telegram_bot_token`. prometheus#5114 * [ENHANCEMENT] docs: Add note about notifier timeouts. prometheus#5077 * [ENHANCEMENT] docs: Fix `force_implicit_tls` config field name. prometheus#5030 * [ENHANCEMENT] docs: Link community supported integrations. prometheus#4978 * [ENHANCEMENT] docs: Remove duplicate header. prometheus#5034 * [ENHANCEMENT] docs: Update mutual tls reference in high availability documentation. prometheus#5120 * [ENHANCEMENT] tracing: Use noop spans when tracing disabled. prometheus#5118 * [FEATURE] Add silence annotations. prometheus#4965 * [FEATURE] Add silence logging option. prometheus#4163 * [FEATURE] Add support for multiple matcher set silences. prometheus#4957 * [FEATURE] Add the reason for notifying in dedup stage. prometheus#4971 * [FEATURE] mattermost: Flatten attachments into top-level config. prometheus#5009 * [FEATURE] mattermost: Support global webhook url. prometheus#4998 * [FEATURE] slack: Add default color from template. prometheus#5014 * [FEATURE] slack: Allow receiver to edit existing messages. prometheus#5007 * [FEATURE] template: Add dict, map and append functions. prometheus#5093 * [FEATURE] webhook: Add full payload templating support for notifier. prometheus#5011 * [BUGFIX] config: Check for empty cluster tls client config. prometheus#5126 * [BUGFIX] config: Don't crash upon reading empty config for notifier. prometheus#4979 * [BUGFIX] config: Fix ipv6 address handling in hostport.string(). prometheus#5040 * [BUGFIX] mattermost: Omit empty text field in notifications. prometheus#4985 * [BUGFIX] telegram: Send fallback message when notification exceeds character limit. prometheus#5074 * [BUGFIX] ui: Fix escaping for matcher values with quotes. prometheus#4862 * [BUGFIX] ui: Handle special chars in silence regex-matchers. prometheus#4942 * [BUGFIX] ui: Support utf-8 label names in matchers. prometheus#5089 Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
* [CHANGE] `go get github.com/prometheus/alertmanager/ui` will now fail as compiled UI assets are no longer checked into the repository. Downstream builds that rely on these assets being present in the source tree must now build the UI from source. #5113 * [CHANGE] The '--enable-feature=auto-gomaxprocs' option is deprecated and will be removed in v0.33. This flag currently has no effect and can be safely removed from any startup scripts. #5090 * [CHANGE] Update internal function signatures across multiple packages. This affects any project that integrates `Alertmanager` code. * [ENHANCEMENT] Add static asset caching. #5113 * [ENHANCEMENT] Reduce memory allocations through pre-sizing collections and batch allocation. #5020 * [ENHANCEMENT] Replace help with documentation in navigation bar. #4943 * [ENHANCEMENT] docs(ha): Update high availability documentation. #5136 * [ENHANCEMENT] docs: Add `auth_secret_file` for smtp in document. #5036 * [ENHANCEMENT] docs: Add description for global `telegram_bot_token`. #5114 * [ENHANCEMENT] docs: Add note about notifier timeouts. #5077 * [ENHANCEMENT] docs: Fix `force_implicit_tls` config field name. #5030 * [ENHANCEMENT] docs: Link community supported integrations. #4978 * [ENHANCEMENT] docs: Remove duplicate header. #5034 * [ENHANCEMENT] docs: Update mutual tls reference in high availability documentation. #5120 * [ENHANCEMENT] tracing: Use noop spans when tracing disabled. #5118 * [FEATURE] Add silence annotations. #4965 * [FEATURE] Add silence logging option. #4163 * [FEATURE] Add support for multiple matcher set silences. #4957 * [FEATURE] Add the reason for notifying in dedup stage. #4971 * [FEATURE] mattermost: Flatten attachments into top-level config. #5009 * [FEATURE] mattermost: Support global webhook url. #4998 * [FEATURE] slack: Add default color from template. #5014 * [FEATURE] slack: Allow receiver to edit existing messages. #5007 * [FEATURE] template: Add dict, map and append functions. #5093 * [FEATURE] webhook: Add full payload templating support for notifier. #5011 * [BUGFIX] config: Check for empty cluster tls client config. #5126 * [BUGFIX] config: Don't crash upon reading empty config for notifier. #4979 * [BUGFIX] config: Fix ipv6 address handling in hostport.string(). #5040 * [BUGFIX] mattermost: Omit empty text field in notifications. #4985 * [BUGFIX] telegram: Send fallback message when notification exceeds character limit. #5074 * [BUGFIX] ui: Fix escaping for matcher values with quotes. #4862 * [BUGFIX] ui: Handle special chars in silence regex-matchers. #4942 * [BUGFIX] ui: Support utf-8 label names in matchers. #5089 Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
Past silences are really important to postmortem our alert management operations.
We need to get "when" and "what kind of" create/edit/delete silences.
So this PR added optional function that logging silence change.
Reroll of #2536 to address review item.
Summary by CodeRabbit
New Features
Tests