Skip to content

Conversation

shaikenov
Copy link

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds a new metric to the exported prometheus metrics list: LongestNodeScaleDownTime

We want to track all the nodes that were marked as unneeded, but were unprocessed during the ScaleDown. If a node was unneeded, but unprocessed multiple times consecutively, we store only the earliest time it happened. The difference between the current time and the earliest time among all unprocessed nodes will give the longest time. This time can give us an indication of possible throttling and helps to better monitor what happens during ScaleDown.

Which issue(s) this PR fixes:

None

Special notes for your reviewer: this is a draft PR, work is still in progress

Does this PR introduce a user-facing change?

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

None

@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 5, 2025
Copy link

linux-foundation-easycla bot commented Oct 5, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: shaikenov / name: Olzhas Shaikenov (a279f58)

@k8s-ci-robot
Copy link
Contributor

Welcome @shaikenov!

It looks like this is your first PR to kubernetes/autoscaler 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/autoscaler has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @shaikenov. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 5, 2025
Copy link

@kada2004 kada2004 left a comment

Choose a reason for hiding this comment

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

very good

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kada2004, shaikenov
Once this PR has been reviewed and has the lgtm label, please assign aleksandra-malinowska for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaikenov shaikenov force-pushed the shaikenov-scaledown-unprocessed-node-tracking branch from b9e7969 to 86a98d1 Compare October 6, 2025 11:40
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 7, 2025
@shaikenov shaikenov force-pushed the shaikenov-scaledown-unprocessed-node-tracking branch from 86a98d1 to 0457f73 Compare October 8, 2025 08:56
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 8, 2025
@shaikenov shaikenov force-pushed the shaikenov-scaledown-unprocessed-node-tracking branch from 0457f73 to c2756ca Compare October 8, 2025 15:22
// We want to track all the nodes that were marked as unneeded, but were unprocessed during the ScaleDown.
// If a node was unneeded, but unprocessed multiple times consecutively, we store only the earliest time it happened.
// The difference between the current time and the earliest time among all unprocessed nodes will give the longest time
LongestNodeScaleDownTimeTrackerEnabled bool

Choose a reason for hiding this comment

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

This sounds a bit like a node has been deleted...

Copy link
Author

Choose a reason for hiding this comment

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

pointed that nodes are unprocessed and not deleted

Comment on lines +483 to +491
// if l.minimumTime is 0, then in previous iteration we also processed all the nodes, so the longest time is 0
// otherwise -> report the longest time from previous iteration and reset the minimumTime
if l.minimumTime.IsZero() {
longestTime = 0
} else {
longestTime = currentTime.Sub(l.minimumTime)
l.minimumTime = time.Time{}
}
l.nodeNamesWithTimeStamps = make(map[string]time.Time)

Choose a reason for hiding this comment

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

Seems like this will never be called, because you check for null in handleUnprocessedNodes and return early in that case. I would also add unit test covering this path.

Copy link
Author

Choose a reason for hiding this comment

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

in handleUnprocessedNodes() I do check the p.longestNodeScaleDownT for being null and not nodeNames. It is needed for the case when flag is disabled and longestNodeScaleDownT is not instantiated.
We will end up in this part of code if we have processed all the nodes.
About the unit tests I already check this behavior in "Test the functionality of longestNodeScaleDownT with all nodes processed in the first iteration" and "LongestLastScaleDownEvalDuration flag is disabled"

func TestLongestNodeScaleDownTime(t *testing.T) {
testCases := []struct {
name string
nodes []*apiv1.Node

Choose a reason for hiding this comment

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

Seems unused

Copy link
Author

Choose a reason for hiding this comment

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

yes, agree

assert.Equal(t, val, start)
}
}
tc.unprocessedNodes = []string{"n2", "n3"}

Choose a reason for hiding this comment

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

This is not very readable, I mean updating test case params here.

Copy link
Author

Choose a reason for hiding this comment

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

introduced 2d array for unprocessedNodes

testCases := []struct {
name string
nodes []*apiv1.Node
unprocessedNodesInFirstIter []string

Choose a reason for hiding this comment

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

I am wandering if having 2 dim array where each row reflects one iteration wouldn't be more flexible? You could also then get rid of run param.

Copy link
Author

Choose a reason for hiding this comment

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

agree

Comment on lines 1165 to 1178
registry := kube_util.NewListerRegistry(nil, nil, nil, nil, nil, nil, nil, nil, nil)
provider := testprovider.NewTestCloudProviderBuilder().Build()
provider.AddNodeGroup("ng1", 0, 0, 0)
for _, node := range tc.nodes {
provider.AddNode("ng1", node)
}
autoscalingCtx, err := NewScaleTestAutoscalingContext(config.AutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: 10 * time.Minute,
},
ScaleDownSimulationTimeout: 1 * time.Second,
MaxScaleDownParallelism: tc.maxParallel,
LongestNodeScaleDownTimeTrackerEnabled: tc.isFlagEnabled,
}, &fake.Clientset{}, registry, provider, nil, nil)

Choose a reason for hiding this comment

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

Seems like setup. Do we need to recreate it for each test case?

Copy link
Author

Choose a reason for hiding this comment

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

I think before autoscalingCtx instantiation - yes, we can put it as part of setup. autoscalingCtx has MaxScaleDownParallelism and LongestNodeScaleDownTimeTrackerEnabled which I alternate in different test cases, so I would prefer to have it recreated

@shaikenov shaikenov force-pushed the shaikenov-scaledown-unprocessed-node-tracking branch from c2756ca to a279f58 Compare October 10, 2025 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants