-
Notifications
You must be signed in to change notification settings - Fork 40k
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
add additional log & UT for HPA #127394
base: master
Are you sure you want to change the base?
add additional log & UT for HPA #127394
Conversation
Hi @kevinteng525. 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: kevinteng525 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 |
@@ -843,11 +843,13 @@ func (a *HorizontalController) reconcileAutoscaler(ctx context.Context, hpaShare | |||
retErr = err | |||
} | |||
|
|||
logger.V(4).Info("Proposing desired replicas", | |||
logger.V(2).Info("Proposing desired replicas", |
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.
Why do we need to increase the original log level? If we need to troubleshoot a problem, we should increase the level of the controller-manager log instead of changing the log level.
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.
changed back log level to 4, thanks!
/test pull-kubernetes-unit |
1 similar comment
/test pull-kubernetes-unit |
@kevinteng525: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
/ok-to-test /test pull-kubernetes-unit |
b1f3879
to
abce1d8
Compare
b060f39
to
f56faef
Compare
/cc @mengjiao-liu @gjtempleton |
/wg structured-logging |
"metric", metricName, | ||
"timestamp", metricTimestamp, | ||
"scaleTarget", reference) | ||
"scaleTarget", reference, |
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 checked and found that the modified logs below also use reference := fmt.Sprintf("%s/%s/%s", hpa.Spec.ScaleTargetRef.Kind, hpa.Namespace, hpa.Spec.ScaleTargetRef.Name)
many times. Then you can directly use the following method at the top level of the call(Maybe under line 815), and the logs below will also have this key-value pair.
If other key-value pairs are used multiple times, you can also add them here.
if loggerV := logger.V(4); loggerV.Enabled() {
logger = klog.LoggerWithValues(
logger,
"scaleTarget", reference,
"currentReplicas", currentReplicas,
...
)
ctx = klog.NewContext(ctx, logger)
}
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 it's for logging, and is only utilized 3 times within this method. The rest are used in other methods. Switching to loggerV
with V(4)
might add complexity and reduce readability. It also can't be used for other verbose levels. I would suggest we keep it simple.
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.
It makes sense.
add additional log & UT for HPA
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.
/lgtm
From WG-structured-logging side
LGTM label has been added. Git tree hash: a96248aab189d27d8f3d9b60f6582f9f30f1fd01
|
What type of PR is this?
/kind feature
What this PR does / why we need it:
We are encountering an issue in production where the Horizontal Pod Autoscaler (HPA) sometimes scales up later than expected when advanced policies are defined. This issue cannot be reproduced with a testing application using the same strategy, nor can it be consistently reproduced with the same production application at a later time.
This PR adds additional logging to the HPA for enhanced troubleshooting, helping diagnose intermittent scale delay issues. The current logs lack sufficient details, and the HPA status does not retain enough information for effective diagnosis. This enhancement will provide greater visibility into metrics and events during scaling, aiding in identifying and resolving the delay problem. Additionally, unit tests have been added to help reproduce and address the issue.
Which issue(s) this PR fixes:
N/A
Special notes for your reviewer:
This enhancement addresses the need for better diagnostics in production environments where the scaling delay cannot be reproduced in testing pools or via unit tests alone.
As
normalizeDesiredReplicasWithBehaviors
needs to consider past recommendations and scale-up/scale-down events, this PR logs all relevant data to aid in troubleshooting.Before this PR
After this PR
Does this PR introduce a user-facing change?
No user-facing change.