Skip to content

refactor(eventrecorder): rename EventRecorderConfig/Output and introduce output-type constants#5190

Merged
siavashs merged 5 commits into
prometheus:mainfrom
eyazici90:main
May 4, 2026
Merged

refactor(eventrecorder): rename EventRecorderConfig/Output and introduce output-type constants#5190
siavashs merged 5 commits into
prometheus:mainfrom
eyazici90:main

Conversation

@eyazici90
Copy link
Copy Markdown
Contributor

@eyazici90 eyazici90 commented Apr 24, 2026

Pull Request Checklist

Please check all the applicable boxes.

  • Please list all open issue(s) discussed with maintainers related to this change
    • Fixes #
  • Is this a new Receiver integration?
  • Is this a bugfix?
    • I have added tests that can reproduce the bug which pass with this bugfix applied
  • Is this a new feature?
    • I have added tests that test the new feature's functionality
  • Does this change affect performance?
    • I have provided benchmarks comparison that shows performance is improved or is not degraded
      • You can use benchstat to compare benchmarks
    • I have added new benchmarks if required or requested by maintainers
  • Is this a breaking change?
    • My changes do not break the existing cluster messages
    • My changes do not break the existing api
  • I have added/updated the required documentation
  • I have signed-off my commits
  • I will follow best practices for contributing to this project

Which user-facing changes does this PR introduce?


Summary by CodeRabbit

  • Refactor
    • Restructured event recorder configuration types and output handling for clearer, more maintainable config management.
    • Replaced literal type checks with named output constants and centralized validation, improving robustness of output selection.
    • Hot-reload logic for the event recorder now uses a semantic config comparison to avoid unnecessary rebuilds; no change to public behavior or configuration format.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

📝 Walkthrough

Walkthrough

Rename/refactor eventrecorder config types (EventRecorderConfigConfig, EventRecorderOutputOutput), move YAML unmarshalling into (*Output).UnmarshalYAML, introduce exported output-type constants (OutputFile, OutputWebhook), update all call sites and top-level config.Config to use the new types, and add configEqual helper.

Changes

Cohort / File(s) Summary
Top-level config
config/config.go
Change Config.EventRecorder field type from eventrecorder.EventRecorderConfigeventrecorder.Config; filepath resolution now checks eventrecorder.OutputFile constant when identifying file outputs.
EventRecorder config types
eventrecorder/config.go
Rename EventRecorderConfigConfig and EventRecorderOutputOutput; move YAML unmarshalling into (*Output).UnmarshalYAML; validate Output.Type against exported constants OutputFile/OutputWebhook; add configEqual(Config, Config) bool for semantic config comparison.
Recorder implementation
eventrecorder/eventrecorder.go
Update function/method signatures to accept Config (NewRecorderFromConfig, ApplyConfig); add exported constants OutputFile/OutputWebhook; switch internal selection/validation to use these constants; replace prior equality helper with configEqual.
Webhook output
eventrecorder/webhook.go
Change NewWebhookOutput parameter type from EventRecorderOutputOutput (internal field usage unchanged).
Tests
eventrecorder/eventrecorder_test.go, eventrecorder/webhook_test.go
Update tests to construct and use Config and Output types and to call configEqual; replace "file" literal with OutputFile where relevant.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • siavashs
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description uses the repository template but leaves all checklist items unchecked and the release-notes section empty, providing no substantive content about the changes. Complete the checklist by checking applicable boxes (e.g., 'breaking change' implications), categorize user-facing changes in release-notes, and provide context on why this refactoring was needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% 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 accurately summarizes the main changes: renaming EventRecorderConfig/Output types and introducing output-type constants in the eventrecorder package.
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.

✏️ 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.

@eyazici90 eyazici90 marked this pull request as ready for review April 24, 2026 20:04
@eyazici90 eyazici90 requested a review from a team as a code owner April 24, 2026 20:04
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
eventrecorder/eventrecorder.go (1)

46-49: Optional: consider untyped constants or a dedicated output-type string type.

Declaring OutputFile string = "file" ties each constant to the concrete string type. Either making them untyped (OutputFile = "file") or introducing a dedicated alias (type OutputType string) is more idiomatic and, in the latter case, lets the compiler catch bare string comparisons against Output.Type. Since Output.Type is a plain string today, this is purely a nit.

♻️ Option A: untyped string constants
 const (
-	OutputFile    string = "file"
-	OutputWebhook string = "webhook"
+	OutputFile    = "file"
+	OutputWebhook = "webhook"
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eventrecorder/eventrecorder.go` around lines 46 - 49, Change the typed string
constants OutputFile and OutputWebhook to either untyped constants or introduce
a dedicated alias type to make intent explicit: replace the current declarations
of OutputFile and OutputWebhook and, if you choose the alias approach, add type
OutputType string and update any uses (e.g., the Output.Type field and
comparisons against OutputFile/OutputWebhook) so the field and constants use
OutputType instead of plain string; otherwise simply remove the explicit
`string` type on the two constants to make them untyped.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@eventrecorder/eventrecorder.go`:
- Around line 46-49: Change the typed string constants OutputFile and
OutputWebhook to either untyped constants or introduce a dedicated alias type to
make intent explicit: replace the current declarations of OutputFile and
OutputWebhook and, if you choose the alias approach, add type OutputType string
and update any uses (e.g., the Output.Type field and comparisons against
OutputFile/OutputWebhook) so the field and constants use OutputType instead of
plain string; otherwise simply remove the explicit `string` type on the two
constants to make them untyped.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9bcce745-d430-4543-883d-f15d5d40bb80

📥 Commits

Reviewing files that changed from the base of the PR and between c769adc and db504a2.

📒 Files selected for processing (6)
  • config/config.go
  • eventrecorder/config.go
  • eventrecorder/eventrecorder.go
  • eventrecorder/eventrecorder_test.go
  • eventrecorder/webhook.go
  • eventrecorder/webhook_test.go

EventRecorderConfig / EventRecorderOutput repeat the package name. Idiomatic golang would be to export as Config  and Output so callers write eventrecorder.Config instead.

Signed-off-by: emreya <e.yazici1990@gmail.com>
This makes the switch in UnmarshalYAML and buildOutputs resilient to typos.

Signed-off-by: emreya <e.yazici1990@gmail.com>
…type

Closer to config struct declaration, in case of new field changes, changes are collocated in single file.

Signed-off-by: emreya <e.yazici1990@gmail.com>
Declaring string type is unnecessary for enum consts.

Signed-off-by: emreya <e.yazici1990@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

222-229: Use the exported eventrecorder.OutputFile constant.

This is the same string-literal duplication this PR is trying to eliminate. Replacing "file" here with eventrecorder.OutputFile keeps the type comparison resilient to typos and consistent with buildOutputs and UnmarshalYAML.

♻️ Proposed change
 	for i, out := range cfg.EventRecorder.Outputs {
-		if out.Type == "file" {
+		if out.Type == eventrecorder.OutputFile {
 			cfg.EventRecorder.Outputs[i].Path = join(out.Path)
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@config/config.go` around lines 222 - 229, Replace the string literal "file"
in the loop that processes cfg.EventRecorder.Outputs with the exported constant
eventrecorder.OutputFile to avoid duplication and typos; specifically, in the
loop iterating over cfg.EventRecorder.Outputs where you check out.Type and call
cfg.EventRecorder.Outputs[i].Path = join(out.Path), change the comparison to use
eventrecorder.OutputFile so it matches the usage in buildOutputs and
UnmarshalYAML and keeps behavior identical while relying on the shared constant.
eventrecorder/config.go (1)

82-84: Optional: rename helper to match the renamed type.

The renaming refactor dropped the EventRecorder prefix from the types, but the helper name still keeps the long form. Since this is unexported and used only within the package, consider configEqual (or configsEqual) for consistency with Config/Output.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eventrecorder/config.go` around lines 82 - 84, The helper function name
eventRecorderConfigEqual is inconsistent with the refactored Config/Output
types; rename this unexported helper to a shorter, package-consistent name such
as configEqual (or configsEqual) and update all internal references to
eventRecorderConfigEqual accordingly so the function signature and usages match
the new name while preserving its logic for comparing Config values.
eventrecorder/eventrecorder_test.go (1)

237-246: Use the new OutputFile constant in tests for consistency.

The PR introduces OutputFile/OutputWebhook to remove duplicated string literals, but these test fixtures still hardcode "file". Switching to the constant aligns the tests with the refactor's goal.

♻️ Proposed change
 	a := Config{
 		Outputs: []Output{
-			{Type: "file", Path: "/tmp/events.jsonl"},
+			{Type: OutputFile, Path: "/tmp/events.jsonl"},
 		},
 	}
 	b := Config{
 		Outputs: []Output{
-			{Type: "file", Path: "/tmp/events.jsonl"},
+			{Type: OutputFile, Path: "/tmp/events.jsonl"},
 		},
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eventrecorder/eventrecorder_test.go` around lines 237 - 246, Tests still use
the hardcoded "file" string for outputs; update the two Output entries in the
test fixtures (the Config/Output structs named a and b) to use the new
OutputFile constant instead of the literal "file" so the tests align with the
refactor (replace {Type: "file", ...} with {Type: OutputFile, ...} in both
places).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@config/config.go`:
- Around line 222-229: Replace the string literal "file" in the loop that
processes cfg.EventRecorder.Outputs with the exported constant
eventrecorder.OutputFile to avoid duplication and typos; specifically, in the
loop iterating over cfg.EventRecorder.Outputs where you check out.Type and call
cfg.EventRecorder.Outputs[i].Path = join(out.Path), change the comparison to use
eventrecorder.OutputFile so it matches the usage in buildOutputs and
UnmarshalYAML and keeps behavior identical while relying on the shared constant.

In `@eventrecorder/config.go`:
- Around line 82-84: The helper function name eventRecorderConfigEqual is
inconsistent with the refactored Config/Output types; rename this unexported
helper to a shorter, package-consistent name such as configEqual (or
configsEqual) and update all internal references to eventRecorderConfigEqual
accordingly so the function signature and usages match the new name while
preserving its logic for comparing Config values.

In `@eventrecorder/eventrecorder_test.go`:
- Around line 237-246: Tests still use the hardcoded "file" string for outputs;
update the two Output entries in the test fixtures (the Config/Output structs
named a and b) to use the new OutputFile constant instead of the literal "file"
so the tests align with the refactor (replace {Type: "file", ...} with {Type:
OutputFile, ...} in both places).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 23168401-53c2-4639-92a9-6bf75d4438bd

📥 Commits

Reviewing files that changed from the base of the PR and between db504a2 and 17ee06a.

📒 Files selected for processing (6)
  • config/config.go
  • eventrecorder/config.go
  • eventrecorder/eventrecorder.go
  • eventrecorder/eventrecorder_test.go
  • eventrecorder/webhook.go
  • eventrecorder/webhook_test.go
✅ Files skipped from review due to trivial changes (1)
  • eventrecorder/webhook_test.go

Replace remaining "file" string literals in config/config.go and tests with the OutputFile constant, and drop the package-name stutter from eventRecorderConfigEqual -> configEqual.

Signed-off-by: emreya <e.yazici1990@gmail.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
eventrecorder/eventrecorder_test.go (1)

236-236: Optional: rename test to drop the package-name stutter.

Since the helper was renamed from eventRecorderConfigEqual to configEqual to avoid eventrecorder. stutter, the test function name could follow suit (e.g., TestConfigEqual) for consistency.

♻️ Proposed rename
-func TestEventRecorderConfigEqual(t *testing.T) {
+func TestConfigEqual(t *testing.T) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eventrecorder/eventrecorder_test.go` at line 236, Rename the test function
TestEventRecorderConfigEqual to match the helper rename and drop the
package-name stutter (e.g., TestConfigEqual); update any references to that test
name (calls, comments) so it compiles and runs, ensuring the test still calls
configEqual (the renamed helper) and keeps its signature func TestConfigEqual(t
*testing.T).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@eventrecorder/eventrecorder_test.go`:
- Line 236: Rename the test function TestEventRecorderConfigEqual to match the
helper rename and drop the package-name stutter (e.g., TestConfigEqual); update
any references to that test name (calls, comments) so it compiles and runs,
ensuring the test still calls configEqual (the renamed helper) and keeps its
signature func TestConfigEqual(t *testing.T).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: b0acac3e-920c-4a08-90da-0dfae1179a3a

📥 Commits

Reviewing files that changed from the base of the PR and between 17ee06a and 7d74cb7.

📒 Files selected for processing (4)
  • config/config.go
  • eventrecorder/config.go
  • eventrecorder/eventrecorder.go
  • eventrecorder/eventrecorder_test.go
✅ Files skipped from review due to trivial changes (1)
  • eventrecorder/eventrecorder.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/config.go

@siavashs siavashs merged commit 75e3061 into prometheus:main May 4, 2026
8 checks passed
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.

2 participants