Skip to content

feat(eventrecorder): add outputs name - #5393

Open
siavashs wants to merge 1 commit into
prometheus:mainfrom
siavashs:fix/eventrecorder-metric-label-values
Open

feat(eventrecorder): add outputs name#5393
siavashs wants to merge 1 commit into
prometheus:mainfrom
siavashs:fix/eventrecorder-metric-label-values

Conversation

@siavashs

@siavashs siavashs commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Require every output to have a safe, unique name and use only the type-qualified name in metrics and logs. Avoid exposing webhook URLs, Kafka brokers, topics, and raw transport errors.

Which user-facing changes does this PR introduce?

[CHANGE] eventrecorder: All outputs now require a configured `name`, used instead of URLs, brokers, topics, or other destination configuration in metric label values and logs.

@siavashs
siavashs requested a review from a team as a code owner July 17, 2026 11:31
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d5679b67-62f7-46ef-b82e-fa10c643dac8

📥 Commits

Reviewing files that changed from the base of the PR and between da274a4 and 6d83ebe.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • config/config_test.go
  • docs/configuration.md
  • eventrecorder/webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • config/config_test.go
  • docs/configuration.md

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Event recorder outputs now require validated configured names. Type-qualified names are used for metrics, logs, output construction, duplicate detection, and configuration equality across file, webhook, Kafka, and stdout destinations.

Changes

Event recorder output naming

Layer / File(s) Summary
Output name contract and validation
eventrecorder/config.go, eventrecorder/file.go, eventrecorder/webhook.go, eventrecorder/kafka.go, eventrecorder/stdout.go
Adds required name validation, type-qualified identifiers, duplicate detection, and name-aware configuration equality.
Destination identity and construction
eventrecorder/file.go, eventrecorder/webhook.go, eventrecorder/kafka.go, eventrecorder/stdout.go
Constructors and destination Name() methods now use configured names instead of paths, URLs, brokers, topics, or constants.
Recorder wiring and logging
eventrecorder/recorder.go, eventrecorder/file.go, eventrecorder/webhook.go, eventrecorder/kafka.go
Output creation uses validated identifiers, stdout entries are initialized through its constructor, and logs omit sensitive destination details and raw errors.
Tests and documentation
eventrecorder/*_test.go, config/config_test.go, docs/configuration.md, CHANGELOG.md
Updates fixtures and assertions for required names, duplicate validation, equality, identifier generation, log redaction, configuration examples, and changelog text.

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

Merge Risk: ⚪ Minimal · up to 6d83e

The change updates output names used in logs and metrics, and the supplied evidence does not identify a current correctness or security defect; no actionable merge-blocking risk remains beyond normal checks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the main behavior and includes release notes, but it omits the required pull request checklist. Complete the required checklist, including tests, documentation, API compatibility, sign-off, and applicable issue or performance details.
Docstring Coverage ⚠️ Warning Docstring coverage is 22.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the eventrecorder change to add configured names for outputs.
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.

@siavashs
siavashs marked this pull request as draft July 17, 2026 13:56
@siavashs

Copy link
Copy Markdown
Contributor Author

we actually need to fix this for other outputs too, for example the secret url from webhook leaks into metrics and logs.

@siavashs
siavashs force-pushed the fix/eventrecorder-metric-label-values branch from 3d8503f to 7953a47 Compare July 18, 2026 12:04
@siavashs siavashs changed the title fix(eventrecorder): kafka outputs name feat(eventrecorder): add outputs name Jul 18, 2026
@siavashs
siavashs marked this pull request as ready for review July 18, 2026 12:05
Comment thread eventrecorder/file.go Outdated
f, err := openAppend(fo.path)
if err != nil {
fo.logger.Error("Failed to reopen event recorder file", "path", fo.path, "err", err)
fo.logger.Error("Failed to reopen event recorder file", "output", fo.name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would like to have the file path also in this error log.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess for files it is fine to keep the path, since they are not technically a secret.

Comment thread eventrecorder/file.go Outdated
}
fo.logger.Error("fsnotify error on event recorder directory", "err", err)
_ = err
fo.logger.Error("fsnotify error on event recorder directory", "output", fo.name)

@TheMeier TheMeier Jul 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

filepath (or its dirname) would also be helpful in this error log

@siavashs
siavashs force-pushed the fix/eventrecorder-metric-label-values branch from 7953a47 to da274a4 Compare July 27, 2026 09:45

@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: 3

🧹 Nitpick comments (1)
config/config_test.go (1)

56-57: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Assert that the configured name is parsed.

Since this change adds the required name field, also verify its value; otherwise the test does not protect the new configuration contract.

Proposed test assertion
  require.Len(t, cfg.EventRecorder.WebhookOutputs, 1)
+ require.Equal(t, "pipelines", cfg.EventRecorder.WebhookOutputs[0].Name)
  require.True(t, cfg.EventRecorder.WebhookOutputs[0].Batch)
🤖 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_test.go` around lines 56 - 57, Update the configuration parsing
test in config_test.go to assert that the parsed pipeline name equals the
configured “pipelines” value, alongside the existing URL assertions, so the
required name field is covered.
🤖 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 `@eventrecorder/recorder.go`:
- Line 182: Update the file event recorder initialization error log in the
relevant recorder flow to remove the raw `"path"` field and `"err"` value,
retaining only the type-qualified identifier from safeOutputIdentifier("file",
fc.Name), consistent with webhook and Kafka logging.

In `@eventrecorder/webhook_test.go`:
- Around line 494-500: Update TestWebhookOutputConfig_MalformedURLDoesNotLeak to
assert independently that the malformed-URL error omits each sensitive
component, including the token value, alongside the existing secret and password
checks.
- Around line 503-506: The test TestNewWebhookOutput_ValidatesProgrammaticConfig
currently omits only the URL, so it does not verify empty-name validation. Add a
separate case using a valid URL with Name empty, and assert that
NewWebhookOutput returns an error.

---

Nitpick comments:
In `@config/config_test.go`:
- Around line 56-57: Update the configuration parsing test in config_test.go to
assert that the parsed pipeline name equals the configured “pipelines” value,
alongside the existing URL assertions, so the required name field is covered.
🪄 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: Pro Plus

Run ID: e3af1292-600c-4ecb-b436-38c906632484

📥 Commits

Reviewing files that changed from the base of the PR and between 7953a47 and da274a4.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • config/config_test.go
  • docs/configuration.md
  • eventrecorder/config.go
  • eventrecorder/file.go
  • eventrecorder/file_test.go
  • eventrecorder/kafka.go
  • eventrecorder/kafka_test.go
  • eventrecorder/recorder.go
  • eventrecorder/recorder_test.go
  • eventrecorder/stdout.go
  • eventrecorder/stdout_test.go
  • eventrecorder/webhook.go
  • eventrecorder/webhook_test.go
🚧 Files skipped from review as they are similar to previous changes (11)
  • CHANGELOG.md
  • docs/configuration.md
  • eventrecorder/config.go
  • eventrecorder/recorder_test.go
  • eventrecorder/stdout.go
  • eventrecorder/file_test.go
  • eventrecorder/kafka.go
  • eventrecorder/stdout_test.go
  • eventrecorder/kafka_test.go
  • eventrecorder/webhook.go
  • eventrecorder/file.go

Comment thread eventrecorder/recorder.go
fo, err := NewFileOutput(fc, logger)
if err != nil {
logger.Error("Failed to create file event recorder output", "path", fc.Path, "err", err)
logger.Error("Failed to create file event recorder output", "output", safeOutputIdentifier("file", fc.Name), "path", fc.Path, "err", err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Do not log the file path or raw initialization error.

"path": fc.Path directly exposes the destination path, and err can repeat it through openAppend or file-watcher errors. Keep only the type-qualified output identifier, consistent with the webhook and Kafka logs.

Proposed fix
-			logger.Error("Failed to create file event recorder output", "output", safeOutputIdentifier("file", fc.Name), "path", fc.Path, "err", err)
+			logger.Error("Failed to create file event recorder output", "output", safeOutputIdentifier("file", fc.Name))
📝 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
logger.Error("Failed to create file event recorder output", "output", safeOutputIdentifier("file", fc.Name), "path", fc.Path, "err", err)
logger.Error("Failed to create file event recorder output", "output", safeOutputIdentifier("file", fc.Name))
🤖 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` at line 182, Update the file event recorder
initialization error log in the relevant recorder flow to remove the raw
`"path"` field and `"err"` value, retaining only the type-qualified identifier
from safeOutputIdentifier("file", fc.Name), consistent with webhook and Kafka
logging.

Comment thread eventrecorder/webhook_test.go
Comment thread eventrecorder/webhook_test.go
Require every output to have a safe, unique name and use only the
type-qualified name in metrics and logs. Avoid exposing webhook URLs,
Kafka brokers, topics, and raw transport errors.

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
@siavashs
siavashs force-pushed the fix/eventrecorder-metric-label-values branch from da274a4 to 6d83ebe Compare August 17, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants