Skip to content
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

fix: unnecessary HPA updates when cpu utilization trigger is used #5822

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion controllers/keda/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,19 @@ func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(ctx context.Context,
}

metricSpecs := cache.GetMetricSpecForScaling(ctx)
var mSpecs []autoscalingv2.MetricSpec
var cpuUtilizationMetric int

for _, metricSpec := range metricSpecs {
if metricSpec.Resource != nil {
target := metricSpec.Resource.Target
Copy link
Member

Choose a reason for hiding this comment

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

Would be helpful to add a comment on this block to explain why we are doing this magic, and reference the issue

if target.Type == autoscalingv2.UtilizationMetricType && string(metricSpec.Resource.Name) == "cpu" {
cpuUtilizationMetric++
if cpuUtilizationMetric > 1 {
continue
}
}

resourceMetricNames = append(resourceMetricNames, string(metricSpec.Resource.Name))
}

Expand All @@ -238,8 +248,9 @@ func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(ctx context.Context,
metricSpec.External.Metric.Selector.MatchLabels[kedav1alpha1.ScaledObjectOwnerAnnotation] = scaledObject.Name
externalMetricNames = append(externalMetricNames, externalMetricName)
}
mSpecs = append(mSpecs, metricSpec)
}
scaledObjectMetricSpecs = append(scaledObjectMetricSpecs, metricSpecs...)
scaledObjectMetricSpecs = append(scaledObjectMetricSpecs, mSpecs...)

// sort metrics in ScaledObject, this way we always check the same resource in Reconcile loop and we can prevent unnecessary HPA updates,
// see https://github.com/kedacore/keda/issues/1531 for details
Expand Down
Loading