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 prediction without resource metrics #568

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pkg/controller/ehpa/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (c *EffectiveHPAController) GetHPAMetrics(ctx context.Context, ehpa *autosc
continue
}

name := utils.GetPredictionMetricName(metric.Type, false)
name := utils.GetPredictionMetricName(metric.Type)
if len(name) == 0 {
continue
}
Expand Down Expand Up @@ -299,7 +299,7 @@ func GetCronMetricSpecsForHPA(ehpa *autoscalingapi.EffectiveHorizontalPodAutosca
Type: autoscalingv2.ExternalMetricSourceType,
External: &autoscalingv2.ExternalMetricSource{
Metric: autoscalingv2.MetricIdentifier{
Name: utils.GetPredictionMetricName(autoscalingv2.PodsMetricSourceType, true),
Name: utils.GetCronMetricName(),
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"targetKind": ehpa.Spec.ScaleTargetRef.Kind,
Expand Down
27 changes: 13 additions & 14 deletions pkg/utils/ehpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ func IsEHPAPredictionEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscal

func IsEHPAHasPredictionMetric(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool {
for _, metric := range ehpa.Spec.Metrics {
if metric.Type == autoscalingv2.ResourceMetricSourceType {
metricName := GetPredictionMetricName(metric.Type, false)
if len(metricName) == 0 {
continue
}
return true
metricName := GetPredictionMetricName(metric.Type)
if len(metricName) == 0 {
continue
}
return true
}

for key := range ehpa.Annotations {
Expand All @@ -39,19 +37,20 @@ func IsEHPACronEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bo
}

// GetPredictionMetricName return metric name used by prediction
func GetPredictionMetricName(sourceType autoscalingv2.MetricSourceType, isCron bool) (metricName string) {
if isCron {
metricName = known.MetricNameCron
} else {
switch sourceType {
case autoscalingv2.ResourceMetricSourceType, autoscalingv2.PodsMetricSourceType, autoscalingv2.ExternalMetricSourceType:
metricName = known.MetricNamePrediction
}
func GetPredictionMetricName(sourceType autoscalingv2.MetricSourceType) (metricName string) {
switch sourceType {
case autoscalingv2.ResourceMetricSourceType, autoscalingv2.PodsMetricSourceType, autoscalingv2.ExternalMetricSourceType:
metricName = known.MetricNamePrediction
}

return metricName
}

// GetCronMetricName return metric name used by cron
func GetCronMetricName() string {
return known.MetricNameCron
}

// GetGeneralPredictionMetricName return metric name used by prediction
func GetMetricIdentifier(metric autoscalingv2.MetricSpec, name string) string {
var prefix string
Expand Down