这是indexloc提供的服务,不要输入任何密码
Skip to content

Custom Metrics HPA Autoscaler #12277

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

Merged
merged 4 commits into from
Dec 1, 2021

Conversation

enoodle
Copy link
Contributor

@enoodle enoodle commented Nov 15, 2021

Fixes #3134

This is based on #4112 , but tries to have a simpler solution with no added annotations, by assuming that any metric name other than cpu or memory is a custom metric name.

Proposed Changes

  • For HPA autoscaler if the metric name is not cpu or memory then it will be used as a custom metric on the pods with the target value used as averageUtilization value.

Release Note

Metrics with names other than "cpu" or "memory" are allowed as pod custom metrics.

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Nov 15, 2021
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 15, 2021
@knative-prow-robot
Copy link
Contributor

Hi @enoodle. Thanks for your PR.

I'm waiting for a knative 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/test-infra repository.

@knative-prow-robot knative-prow-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. area/API API objects and controllers area/autoscale labels Nov 15, 2021
@codecov
Copy link

codecov bot commented Nov 15, 2021

Codecov Report

Merging #12277 (27b469d) into main (5e96dc0) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12277      +/-   ##
==========================================
- Coverage   87.55%   87.53%   -0.02%     
==========================================
  Files         195      195              
  Lines        9600     9617      +17     
==========================================
+ Hits         8405     8418      +13     
- Misses        915      918       +3     
- Partials      280      281       +1     
Impacted Files Coverage Δ
pkg/apis/autoscaling/annotation_validation.go 100.00% <100.00%> (ø)
pkg/reconciler/autoscaling/hpa/resources/hpa.go 100.00% <100.00%> (ø)
pkg/autoscaler/statserver/server.go 77.66% <0.00%> (-1.95%) ⬇️
pkg/reconciler/configuration/configuration.go 84.61% <0.00%> (-1.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e96dc0...27b469d. Read the comment docs.

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

I like the idea in general, but haven't fully reviewed. I think we should break the API change out first.

@@ -22,7 +22,7 @@ import (
networkingclient "knative.dev/networking/pkg/client/injection/client"
sksinformer "knative.dev/networking/pkg/client/injection/informers/networking/v1alpha1/serverlessservice"
kubeclient "knative.dev/pkg/client/injection/kube/client"
hpainformer "knative.dev/pkg/client/injection/kube/informers/autoscaling/v2beta1/horizontalpodautoscaler"
hpainformer "knative.dev/pkg/client/injection/kube/informers/autoscaling/v2beta2/horizontalpodautoscaler"
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about making the API change to v2beta2 separate PR wise? It seems like that'd be a good change in isolation to the rest in this PR even. Would make the actual changes a lot smaller too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markusthoemmes
Copy link
Contributor

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 15, 2021
@knative-prow-robot knative-prow-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 15, 2021
@enoodle enoodle changed the title Custom Metrics and Stabilization Window for HPA Autoscaler Custom Metrics HPA Autoscaler Nov 15, 2021
@markusthoemmes
Copy link
Contributor

/hold

Until #12278 merges, which this'll rebase on I guess

@knative-prow-robot knative-prow-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 15, 2021
Type: autoscalingv2beta1.PodsMetricSourceType,
Pods: &autoscalingv2beta1.PodsMetricSource{
MetricName: pa.Metric(),
TargetAverageValue: *targetQuantity,
Copy link
Member

Choose a reason for hiding this comment

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

is the assumption that we only want this to be TargetAverageValue? would we ever want TargetValue or TargetAverageUtilization ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sort of, yes. This seems like the most simple option out of the three. I wanted a simple change without adding new annotations. If we add an annotation we can allow the user to choose between them.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure how it would clear for users that its only using the TargetAverage, can we at least document it somehow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -225,8 +225,7 @@ func validateMetric(annotations map[string]string) *apis.FieldError {
return nil
}
case HPA:
switch metric {
case CPU, Memory:
if metric != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is very important (and pretty subjective, so please feel free to disregard this comment), but stylistically, using a switch here looks a little nicer to me (as it mirrors the KPA case above), i.e.

case HPA:
	switch metric {
	case "":
		break
	default:
		return nil
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand, I will make that change.

@nader-ziada
Copy link
Member

I believe the hold can be removed now that #12278 is merged

@enoodle
Copy link
Contributor Author

enoodle commented Nov 17, 2021

Yes, I have rebased this PR since #12278 was merged.

@markusthoemmes
Copy link
Contributor

/hold cancel

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 17, 2021
@nader-ziada
Copy link
Member

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 17, 2021
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2021
@knative-prow-robot knative-prow-robot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 22, 2021
@enoodle
Copy link
Contributor Author

enoodle commented Nov 22, 2021

rebased on changes to hpa test.

@enoodle
Copy link
Contributor Author

enoodle commented Dec 1, 2021

/retest

@nader-ziada
Copy link
Member

@markusthoemmes I think this is ready to merge, would you mind taking a look

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 1, 2021
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enoodle, markusthoemmes

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 1, 2021
@knative-prow-robot knative-prow-robot merged commit b7aa4b7 into knative:main Dec 1, 2021
@enoodle enoodle deleted the custom-metrics-hpa branch December 1, 2021 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/API API objects and controllers area/autoscale cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HPA on custom metrics
5 participants