Skip to content

feat(eventrecorder): add stdout output type#5311

Open
mihir-dixit2k27 wants to merge 2 commits into
prometheus:mainfrom
mihir-dixit2k27:feat/event-recorder-stdout
Open

feat(eventrecorder): add stdout output type#5311
mihir-dixit2k27 wants to merge 2 commits into
prometheus:mainfrom
mihir-dixit2k27:feat/event-recorder-stdout

Conversation

@mihir-dixit2k27

Copy link
Copy Markdown
Contributor

Title: eventrecorder: add stdout output type

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 #5306

Pull Request Checklist

Which user-facing changes does this PR introduce?

[FEATURE] event_recorder: Add stdout_outputs destination type to stream alert events as newline-delimited JSON to stdout, enabling container deployments to capture events via the runtime log driver without a separate file, Kafka, or webhook setup.

Description

Adds a stdout_outputs destination to the event_recorder configuration 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:

event_recorder:
  outputs:
    stdout_outputs:
      - {}

Implementation notes:

  • Follows the existing per-type-list pattern used by file_outputs, webhook_outputs, and kafka_outputs.
  • StdoutOutput serializes events as newline-delimited JSON via protojson, matching the format produced by FileOutput.
  • Close() is a no-op — the process owns os.Stdout.
  • No new dependencies introduced.

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>
@mihir-dixit2k27 mihir-dixit2k27 requested a review from a team as a code owner June 18, 2026 01:31
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds StdoutOutput as a new event recorder destination. A new StdoutOutputConfig struct and StdoutOutput type are introduced in stdout.go, with SendEvent serializing events as newline-delimited JSON to os.Stdout. Config gains a StdoutOutputs field, and buildOutputs iterates it to wire up instances. Tests cover unit behavior, integration, config equality, and YAML unmarshalling.

Changes

Stdout Output Destination

Layer / File(s) Summary
StdoutOutput implementation
eventrecorder/stdout.go
Defines StdoutOutputConfig (empty struct, always-equal) and StdoutOutput with Name() returning "stdout", SendEvent() emitting protojson + newline to os.Stdout with serializeError wrapping, and a no-op Close().
Config field and recorder wiring
eventrecorder/config.go, eventrecorder/recorder.go
Adds StdoutOutputs []StdoutOutputConfig to Config, extends totalOutputs() and configEqual() to include the new slice, and extends buildOutputs to append &StdoutOutput{} for each configured entry.
Unit, integration, and config tests
eventrecorder/stdout_test.go
captureStdout helper swaps os.Stdout with a pipe. Tests cover Name(), SendEvent() JSONL framing (single and double), Close(), Destination interface compliance, recorder integration, config equality, totalOutputs() counting, and YAML unmarshalling of stdout_outputs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% 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 'feat(eventrecorder): add stdout output type' clearly and concisely describes the main change—adding stdout as a new destination type for the event recorder.
Description check ✅ Passed The PR description is comprehensive and well-structured. It includes all essential elements: feature rationale, configuration example, implementation notes, checklist items completed, release notes, and issue reference.
Linked Issues check ✅ Passed The code changes fully implement the requirements from issue #5306: they add stdout_outputs destination type to event_recorder configuration, enabling structured event logging to stdout for containerized deployments without extra infrastructure.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the stdout output feature. Modifications to config.go, recorder.go, and the new stdout.go and stdout_test.go files are all within scope of the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@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.

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 win

Update 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.go alongside file.go, webhook.go, and kafka.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 tradeoff

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between f29d44c and f6ec39e.

📒 Files selected for processing (4)
  • eventrecorder/config.go
  • eventrecorder/recorder.go
  • eventrecorder/stdout.go
  • eventrecorder/stdout_test.go

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.

Allow event_recorder to send send eventes to stdout

1 participant