-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Add context-based warning suppression to SetEmulationVersion #133207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add context-based warning suppression to SetEmulationVersion #133207
Conversation
|
Welcome @PersistentJZH! |
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Hi @PersistentJZH. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: PersistentJZH The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This PR may require API review. If so, when the changes are ready, complete the pre-review checklist and request an API review. Status of requested reviews is tracked in the API Review project. |
/cc @Jefftree |
/ok-to-test |
@@ -165,6 +165,8 @@ type MutableVersionedFeatureGate interface { | |||
// Otherwise, the emulationVersion will be the same as the binary version. | |||
// If set, the feature defaults and availability will be as if the binary is at the emulated version. | |||
SetEmulationVersion(emulationVersion *version.Version) error | |||
// SetEmulationVersionWithContext is like SetEmulationVersion but accepts a context for controlling behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should still describe the behavior in the function description, other functions may get changed or removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will describe the behavior.
type testLoggerKey struct{} | ||
|
||
// WithWarningSuppressionContext returns a context with warning suppression flag | ||
func WithWarningSuppressionContext(ctx context.Context) context.Context { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imo I think we should have a different method of suppressing the warning than passing the value in the context. We shouldn't really have a scenario outside of testing where this isn't logged. @pohly's suggestion of passing a per test logger for this makes sense.
Possibly even we should error on this if we don't pass some allow override since we are setting an already set flag which is unusual during normal operation.
I think we should likely go with passing in a logger for now and follow up on what to do if the emulated version is set multiple times for a feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for @michaelasp's advice. I will use a context logger to optimize the logic and report an error if don't pass some allow override.
if err := gate.(featuregate.MutableVersionedFeatureGate).SetEmulationVersion(originalEmuVer); err != nil { | ||
// Use context to suppress warnings during test cleanup | ||
ctx := featuregate.WithWarningSuppressionContext(context.Background()) | ||
if err := gate.(featuregate.MutableVersionedFeatureGate).SetEmulationVersionWithContext(ctx, originalEmuVer); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably where we can pass some sort of logger that isn't spammy, we expect the values to be changed here so we could probably log to somewhere outside of the base klog.
…minate test noise Signed-off-by: zhihao jian <[email protected]> optimize SetEmulationVersionWithContext logic
adbd958
to
463f95f
Compare
@michaelasp thanks for code review. I have resolved all comments above, pls help to review again, thank you ! |
// warnings will be redirected to the test output instead of the global klog. | ||
// If features would change and no test logger is provided, an error will be returned to prevent | ||
// unexpected behavior in production environments. | ||
SetEmulationVersionWithContext(ctx context.Context, emulationVersion *version.Version) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding a WithContext version here is really confusing ... can we do something more scoped to the single integration test call site that will use this that doesn't expand the interface for all callers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, add SetEmulationVersionWithContext func here is confusing, but there doesn't seem to be a more elegant way to do this.
Is it possible to use klog.FromContext(ctx) to implement different loggers for different envs? However, even if we use klog.FromContext(ctx), we still need an additional parameter or additional method to pass context info.
eg: change SetEmulationVersion(emulationVersion *version.Version) error to SetEmulationVersion(ctx context.Context, emulationVersion *version.Version) error
The changes here are very large and all callers need to be changed, but it is not impossible to do so. Do you have any idea about this? @liggitt
What type of PR is this?
/kind feature
What this PR does / why we need it:
implement a context logger to optimize the warning logic
Which issue(s) this PR is related to:
Fix: #133056
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: