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

break loop once cronScaler found #191

Merged
merged 2 commits into from
Mar 9, 2022
Merged
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
22 changes: 13 additions & 9 deletions pkg/metricprovider/external_metric_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ func (p *ExternalMetricProvider) GetExternalMetric(ctx context.Context, namespac
return &external_metrics.ExternalMetricValueList{}, err
}
// Find the cron metric scaler
var cronScaler *CronScaler
for i := range ehpaList.Items {
cronScalers := GetCronScalersForEHPA(&ehpaList.Items[i])
for k := range cronScalers {
if cronScalers[k].Name() == info.Metric {
cronScaler = cronScalers[k]
}
}
}
cronScaler := findCronScaler(ehpaList.Items, info)
if cronScaler == nil {
return &external_metrics.ExternalMetricValueList{}, fmt.Errorf("cron metric %v/%v not found", namespace, info.Metric)
}
Expand All @@ -76,6 +68,18 @@ func (p *ExternalMetricProvider) GetExternalMetric(ctx context.Context, namespac
return &external_metrics.ExternalMetricValueList{Items: []external_metrics.ExternalMetricValue{value}}, nil
}

func findCronScaler(ehpas []autoscalingapi.EffectiveHorizontalPodAutoscaler, info provider.ExternalMetricInfo) *CronScaler {
for i := range ehpas {
cronScalers := GetCronScalersForEHPA(&ehpas[i])
for k := range cronScalers {
if cronScalers[k].Name() == info.Metric {
return cronScalers[k]
}
}
}
return nil
}

// ListAllExternalMetrics return external cron metrics
// Fetch metrics from cache directly to avoid the performance issue for apiserver when the metrics is large, because this api is called frequently.
func (p *ExternalMetricProvider) ListAllExternalMetrics() []provider.ExternalMetricInfo {
Expand Down