Skip to content

Conversation

nurali-techie
Copy link
Contributor

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

  • PR title includes appropriate prefix(es)
  • Changes are clearly explained in the PR description
  • New and existing tests pass successfully
  • Code adheres to project style and best practices
  • Documentation updated to reflect changes (if applicable)
  • Thorough testing completed, no regressions introduced

By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.

Copy link
Contributor

Summary of Changes

Hello @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

  • New Unit Tests for APA Algorithm: Comprehensive unit tests have been added for the APAAlgorithm.computeTargetReplicas function, covering various scaling scenarios including basic scale-up/down, rate limiting, and tolerance checks.
  • Refactored Test Mocking: A dedicated mockScalingContext has been introduced in its own file (mock_context_test.go) to centralize and improve reusability of the ScalingContext mock across different autoscaler algorithm tests.
  • Internalized Base Scaling Context: The BaseScalingContext struct in pkg/controller/podautoscaler/context/context.go has been renamed to baseScalingContext (unexported), making it an internal implementation detail of the package.
  • Minor Type Correction in APA Algorithm: Type casting for maxScaleUp and maxScaleDown variables in apa.go was adjusted from float64 to int32 to ensure consistency in scaling calculations.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@nurali-techie nurali-techie changed the title [Test] Added unit test for APA post autoscaler [Misc] Added unit test for APA post autoscaler Oct 13, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
func NewBaseScalingContext() *baseScalingContext {
func NewBaseScalingContext() ScalingContext {

Copy link
Contributor Author

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.

Copy link
Collaborator

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

@nurali-techie
Copy link
Contributor Author

@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
I have moved mockScalingContext to new file as it is now getting used by multiple tests (KPA, APA). I have alos made baseScalingContext to private from public to make sure that we always use NewBaseScalingContext() to create new instance.

commit2 -- test: added test for APA scaling algo
This has the main unit tests changes.

commit3 -- refactor: remove unnecessary type cast for better code readability
I see that unnecessary type cast is done in APA computeTargetReplicas(). So removed them for better code readability.

@nurali-techie nurali-techie force-pushed the nur/patch-pa-ctrl-test1 branch from 0d13acb to a179779 Compare October 13, 2025 17:35
@Jeffwan Jeffwan requested a review from googs1025 October 14, 2025 04:39
@nurali-techie nurali-techie force-pushed the nur/patch-pa-ctrl-test1 branch from a179779 to fbb60c8 Compare October 14, 2025 18:32
@Jeffwan Jeffwan force-pushed the nur/patch-pa-ctrl-test1 branch from fbb60c8 to 061767a Compare October 15, 2025 03:12
maxScaleUp := math.Ceil(context.GetMaxScaleUpRate() * currentPodCount)
maxScaleUp := int32(math.Ceil(context.GetMaxScaleUpRate() * currentPodCount))
expectedPods := int32(math.Ceil(currentPodCount * (currentUsePerPod / expectedUse)))
if float64(expectedPods) > maxScaleUp {
Copy link
Collaborator

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?

Copy link
Contributor Author

@nurali-techie nurali-techie Oct 15, 2025

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.

Copy link
Collaborator

@Jeffwan Jeffwan Oct 15, 2025

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

@nurali-techie nurali-techie force-pushed the nur/patch-pa-ctrl-test1 branch from 061767a to 8a4e77e Compare October 15, 2025 17:13
@Jeffwan Jeffwan force-pushed the nur/patch-pa-ctrl-test1 branch from 8a4e77e to 5ad92c5 Compare October 17, 2025 03:47
@Jeffwan
Copy link
Collaborator

Jeffwan commented Oct 17, 2025

@googs1025 need your input here. If it looks good to you, feel free to merge it

@googs1025
Copy link
Collaborator

will final review today

Copy link
Collaborator

@googs1025 googs1025 left a comment

Choose a reason for hiding this comment

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

LGTM

@googs1025 googs1025 merged commit 2aff67a into vllm-project:main Oct 17, 2025
14 checks passed
@nurali-techie nurali-techie deleted the nur/patch-pa-ctrl-test1 branch October 17, 2025 06:25
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.

3 participants