-
Notifications
You must be signed in to change notification settings - Fork 470
[Misc] Added unit test for APA post autoscaler #1659
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
[Misc] Added unit test for APA post autoscaler #1659
Conversation
Summary of ChangesHello @nurali-techie, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness of the pod autoscaler by introducing a comprehensive suite of unit tests for the APA (Adaptive Pod Autoscaler) algorithm. It also improves the overall testability and code organization by refactoring the mock scaling context into a dedicated, reusable file and internalizing the base scaling context within its package. These changes collectively contribute to better maintainability and reliability of the autoscaling logic. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request is a valuable contribution, adding unit tests for the APA autoscaler algorithm and improving overall test coverage. The refactoring work is also well-executed: extracting the mock scaling context into a shared file is a great way to reduce code duplication, and making BaseScalingContext
unexported improves encapsulation within the context
package. The logic simplification in apa.go
is also a welcome improvement.
I have one suggestion regarding context.go
to further enhance encapsulation. Additionally, as a minor process note, the PR title prefix [Test]
doesn't seem to be in the list of approved prefixes in your contribution guidelines. You may want to adjust it.
// NewBaseScalingContext creates a new instance of BaseScalingContext with default values. | ||
func NewBaseScalingContext() *BaseScalingContext { | ||
return &BaseScalingContext{ | ||
func NewBaseScalingContext() *baseScalingContext { |
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.
To improve encapsulation and hide implementation details from consumers of this package, it's a best practice for exported factory functions to return an interface type. In this case, NewBaseScalingContext
should return ScalingContext
instead of the concrete (and now unexported) type *baseScalingContext
.
func NewBaseScalingContext() *baseScalingContext { | |
func NewBaseScalingContext() ScalingContext { |
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.
There are two method in baseScalingContext
which is not defined for ScalingContext
. These two methods are used in code so we can't incorporate this suggestion before adding thoese two method.
Two methods -- SetMinReplicas(), SetMaxReplicas()
For now, I think we can ignore this minor suggestion.
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.
we should all use ScalingContext
interface instead of BaseScalingContext
. so change BaseScalingContext
-> baseScalingContext
make sense to me
@googs1025 this PR is ready for review. Below is the details on the change made commit by commit so it's easy to review. commit1 -- refactor: move mock context to new file commit2 -- test: added test for APA scaling algo commit3 -- refactor: remove unnecessary type cast for better code readability |
0d13acb
to
a179779
Compare
a179779
to
fbb60c8
Compare
fbb60c8
to
061767a
Compare
maxScaleUp := math.Ceil(context.GetMaxScaleUpRate() * currentPodCount) | ||
maxScaleUp := int32(math.Ceil(context.GetMaxScaleUpRate() * currentPodCount)) | ||
expectedPods := int32(math.Ceil(currentPodCount * (currentUsePerPod / expectedUse))) | ||
if float64(expectedPods) > maxScaleUp { |
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 want to make sure one thing: we convert from float -> int to ensure the stability of the unit test, right?
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 am not quite sure on what you are referring about stability of unit test. Unit tests will work without this change (commit_link).
This change is made for better code readability. If you see, math.Ceil()
and math.Floor()
always return int
(check documentation) so it's safe to type cast to int.
Once we type cast both variable maxScaleUp
and expectedPods
to int
; we can work with them without any further type cast which simplify the code and improve readability.
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.
technically, math,Ceil()
math.Floor()
still return float but it's integer. The refactoring is about earlier type conversion, not about the return types here. so this is still ok
061767a
to
8a4e77e
Compare
Signed-off-by: Nurali Techie <[email protected]>
Signed-off-by: Nurali Techie <[email protected]>
Signed-off-by: Nurali Techie <[email protected]>
Signed-off-by: Nurali Techie <[email protected]>
8a4e77e
to
5ad92c5
Compare
@googs1025 need your input here. If it looks good to you, feel free to merge it |
will final review today |
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
Pull Request Description
There is a need to improve unit test coverage for pod autoscaler controller. With this PR, we are adding unit tests for APA algo.
Related Issues
Resolves: part of [#1649] (APA unit tests)
Important: Before submitting, please complete the description above and review the checklist below.
Contribution Guidelines (Expand for Details)
We appreciate your contribution to aibrix! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:
Pull Request Title Format
Your PR title should start with one of these prefixes to indicate the nature of the change:
[Bug]
: Corrections to existing functionality[CI]
: Changes to build process or CI pipeline[Docs]
: Updates or additions to documentation[API]
: Modifications to aibrix's API or interface[CLI]
: Changes or additions to the Command Line Interface[Misc]
: For changes not covered above (use sparingly)Note: For changes spanning multiple categories, use multiple prefixes in order of importance.
Submission Checklist
By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.