feat(eventrecorder): add stdout output type#5311
Conversation
Adds a new stdout_outputs destination to the event_recorder configuration. When running Alertmanager in a container, users can now capture structured alert events through the container runtime log driver (Docker, Kubernetes, etc.) without managing a separate file, Kafka cluster, or webhook endpoint. Implementation follows the existing per-type-list pattern used by file_outputs, webhook_outputs, and kafka_outputs. The StdoutOutput implements the Destination interface and serializes events as newline-delimited JSON via protojson, matching the format used by FileOutput. Closes prometheus#5306 Signed-off-by: Mihir Dixit <dixitmihir1@gmail.com>
📝 WalkthroughWalkthroughAdds ChangesStdout Output Destination
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
eventrecorder/recorder.go (1)
14-33: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick winUpdate package documentation to include stdout output.
The package-level documentation should be updated to reflect the new stdout output destination. Line 16-17 currently lists "(JSONL file, webhook, kafka)" but should include stdout. Similarly, the file layout comment around line 32 should list
stdout.goalongsidefile.go,webhook.go, andkafka.go.As per coding guidelines, package-level documentation must be kept up to date.
📝 Suggested documentation update
Update line 16-17 to mention stdout:
// significant Alertmanager events. Events are serialized as JSON and -// fanned out to one or more configured destinations (JSONL file, -// webhook, kafka). +// fanned out to one or more configured destinations (JSONL file, stdout, +// webhook, kafka).Add stdout.go to the package layout comment:
// - file.go File output and its config. // - webhook.go Webhook output and its config. // - kafka.go Kafka output and its config. +// - stdout.go Stdout output and its 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 `@eventrecorder/recorder.go` around lines 14 - 33, Update the package-level documentation in the eventrecorder package to reflect the new stdout output destination. In the main package comment (around the line describing destinations), change the list from "(JSONL file, webhook, kafka)" to include stdout as a new destination option. Additionally, update the package layout comment section to add stdout.go to the list of files documented, inserting it logically alongside the other output implementations like file.go, webhook.go, and kafka.go.Source: Coding guidelines
🧹 Nitpick comments (1)
eventrecorder/stdout_test.go (1)
98-120: ⚖️ Poor tradeoffConsider more deterministic synchronization for the integration test.
The
time.Sleep(100 * time.Millisecond)on line 114 introduces potential flakiness on slow CI systems. While acceptable for an integration test given the comprehensive unit test coverage, a more robust approach would be to wait on a specific condition (e.g., polling a metric or using a synchronization channel).That said, this is a low-priority improvement since the unit tests provide deterministic coverage of the core functionality.
🤖 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 `@eventrecorder/stdout_test.go` around lines 98 - 120, Replace the hardcoded time.Sleep(100 * time.Millisecond) in the TestStdoutOutput_IntegrationWithRecorder function with a more deterministic synchronization mechanism, such as polling a condition or using a synchronization channel, to ensure the test waits for the event to actually be processed rather than relying on an arbitrary delay that can be flaky on slow CI systems.
🤖 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.
Outside diff comments:
In `@eventrecorder/recorder.go`:
- Around line 14-33: Update the package-level documentation in the eventrecorder
package to reflect the new stdout output destination. In the main package
comment (around the line describing destinations), change the list from "(JSONL
file, webhook, kafka)" to include stdout as a new destination option.
Additionally, update the package layout comment section to add stdout.go to the
list of files documented, inserting it logically alongside the other output
implementations like file.go, webhook.go, and kafka.go.
---
Nitpick comments:
In `@eventrecorder/stdout_test.go`:
- Around line 98-120: Replace the hardcoded time.Sleep(100 * time.Millisecond)
in the TestStdoutOutput_IntegrationWithRecorder function with a more
deterministic synchronization mechanism, such as polling a condition or using a
synchronization channel, to ensure the test waits for the event to actually be
processed rather than relying on an arbitrary delay that can be flaky on slow CI
systems.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: e362c9ec-a123-4319-8a3c-023bcc979b6c
📒 Files selected for processing (4)
eventrecorder/config.goeventrecorder/recorder.goeventrecorder/stdout.goeventrecorder/stdout_test.go
Title:
eventrecorder: add stdout output typeAdds a new stdout_outputs destination to the event_recorder configuration. When running Alertmanager in a container, users can now capture structured alert events through the container runtime log driver (Docker, Kubernetes, etc.) without managing a separate file, Kafka cluster, or webhook endpoint. Implementation follows the existing per-type-list pattern used by file_outputs, webhook_outputs, and kafka_outputs. The StdoutOutput implements the Destination interface and serializes events as newline-delimited JSON via protojson, matching the format used by FileOutput. Closes #5306
Pull Request Checklist
Which user-facing changes does this PR introduce?
Description
Adds a
stdout_outputsdestination to theevent_recorderconfiguration block.When running Alertmanager in a container, alert events can now be captured through the container runtime's log driver (Docker, Kubernetes, Loki, etc.) alongside regular logs, without needing a separate file path, Kafka cluster, or webhook endpoint.
Config example:
Implementation notes:
file_outputs,webhook_outputs, andkafka_outputs.StdoutOutputserializes events as newline-delimited JSON viaprotojson, matching the format produced byFileOutput.Close()is a no-op — the process ownsos.Stdout.