Skip to content

Conversation

@qiujian16
Copy link
Member

@qiujian16 qiujian16 commented Nov 26, 2025

Summary

basecontroller in library-go does not support contextual logging. The basecontroller in sdk-go has implemented contextual logging.

Related issue(s)

Fixes #

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 26, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2025

Important

Review skipped

More than 25% of the files skipped due to max files limit. The review is being skipped to prevent a low-quality review.

72 files out of 180 files are above the max files limit of 100. Please upgrade to Pro plan to get higher limits.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

@qiujian16 qiujian16 force-pushed the sdk-basecontroller branch 2 times, most recently from 849c62d to 7ac84ee Compare November 26, 2025 07:21
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 62.14834% with 148 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.19%. Comparing base (8f8cd01) to head (d81d810).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/common/recorder/event_recorder_wrapper.go 0.00% 25 Missing ⚠️
...ollers/migrationcontroller/migration_controller.go 46.66% 8 Missing ⚠️
...g/registration/hub/managedclusterset/controller.go 0.00% 6 Missing ⚠️
pkg/registration/spoke/spokeagent.go 28.57% 5 Missing ⚠️
...lers/klusterletcontroller/klusterlet_controller.go 60.00% 4 Missing ⚠️
pkg/registration/hub/importer/importer.go 69.23% 4 Missing ⚠️
...hub/managedcluster/managed_namespace_controller.go 60.00% 3 Missing and 1 partial ⚠️
...clusterset/default_managedclusterset_controller.go 50.00% 3 Missing and 1 partial ⚠️
...dclusterset/global_managedclusterset_controller.go 50.00% 3 Missing and 1 partial ⚠️
pkg/registration/register/secret_controller.go 42.85% 3 Missing and 1 partial ⚠️
... and 40 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1269   +/-   ##
=======================================
  Coverage   62.19%   62.19%           
=======================================
  Files         210      209    -1     
  Lines       17084    16992   -92     
=======================================
- Hits        10625    10568   -57     
+ Misses       5342     5308   -34     
+ Partials     1117     1116    -1     
Flag Coverage Δ
unit 62.19% <62.14%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

clusterv1informers.NewSharedInformerFactory(spokeClusterClient, 10*time.Minute),
aboutinformers.NewSharedInformerFactory(aboutClusterClient, 10*time.Minute),
controllerContext.EventRecorder,
events.NewContextualLoggingEventRecorder("registration-agent"),
Copy link
Member

Choose a reason for hiding this comment

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

Same question here, with this recorder, only log, no k8s event created?

@zhujian7
Copy link
Member

@qiujian16 I am a little confused about the title. From my understanding, most content in this PR is about recorder, but why the main benefit is better logging? Could you add some description to the PR to give some details?

@qiujian16
Copy link
Member Author

@qiujian16 I am a little confused about the title. From my understanding, most content in this PR is about recorder, but why the main benefit is better logging? Could you add some description to the PR to give some details?

added some explanation. The main reason is basecontroller in sdk-go has contextual logging implemented.

func (e *EventsRecorderWrapper) WithContext(ctx context.Context) librarygoevents.Recorder {
eCopy := *e
eCopy.ctx = ctx
return e
Copy link
Member

Choose a reason for hiding this comment

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

Should return eCopy?

func (e *EventsRecorderWrapper) WithContext(ctx context.Context) librarygoevents.Recorder {
	eCopy := *e
	eCopy.ctx = ctx
	return &eCopy    
}

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch, fixed

e.recorder.Warningf(e.ctx, reason, messageFmt, args...)
}

func (e *EventsRecorderWrapper) ForComponent(componentName string) librarygoevents.Recorder {
Copy link
Member

@xuezhaojun xuezhaojun Nov 28, 2025

Choose a reason for hiding this comment

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

Seems here we have similar issues for these 2 functions, expected to change to the following way:

func (e *EventsRecorderWrapper) ForComponent(componentName string) librarygoevents.Recorder {
    return &EventsRecorderWrapper{
        recorder: e.recorder.ForComponent(componentName),
        ctx:      e.ctx,
    }
}

func (e *EventsRecorderWrapper) WithComponentSuffix(suffix string) librarygoevents.Recorder {
    return &EventsRecorderWrapper{
        recorder: e.recorder.WithComponentSuffix(suffix),
        ctx:      e.ctx,
    }
}

Based on the interface defination, e.recorder.ForComponent(componentName) and e.recorder.WithComponentSuffix(suffix) returns new recorder instead of modifying the old recorder. So the old way will make new recorder not used.

Copy link
Member

Choose a reason for hiding this comment

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

interface defination:

	// ForComponent allows to fiddle the component name before sending the event to sink.
	// Making more unique components will prevent the spam filter in upstream event sink from dropping
	// events.
	ForComponent(componentName string) Recorder

	// WithComponentSuffix is similar to ForComponent except it just suffix the current component name instead of overriding.
	WithComponentSuffix(componentNameSuffix string) Recorder

Copy link
Member Author

Choose a reason for hiding this comment

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

this is intentional, we need this to return a new one to avoid race if multiple components call at the same time.

See implementation here https://github.com/openshift/library-go/blob/master/pkg/operator/events/recorder_logging.go#L35-L38

Copy link
Member

@xuezhaojun xuezhaojun Nov 28, 2025

Choose a reason for hiding this comment

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

But the current implementation doesn't use the new recorder, because:

func (e *EventsRecorderWrapper) ForComponent(componentName string) librarygoevents.Recorder {
	e.recorder.ForComponent(componentName)
	return e
}

equals to

func (e *EventsRecorderWrapper) ForComponent(componentName string) librarygoevents.Recorder {
	newRecorder := e.recorder.ForComponent(componentName) 
	return e // if we return `e` here, the above newRecorder is throwed.
}

Copy link
Member Author

Choose a reason for hiding this comment

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

ah right, updated.

@haoqing0110
Copy link
Member

LGTM

@xuezhaojun
Copy link
Member

Also look good to me!

@elgnay
Copy link
Contributor

elgnay commented Dec 1, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Dec 1, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 3331061 into open-cluster-management-io:main Dec 1, 2025
18 checks passed
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.

5 participants