Skip to content

Commit

Permalink
not predict for memory in ehpa
Browse files Browse the repository at this point in the history
  • Loading branch information
qmhu committed Feb 23, 2022
1 parent 24e4783 commit 31f356a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
14 changes: 6 additions & 8 deletions pkg/controller/ehpa/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ func (c *EffectiveHPAController) GetHPAMetrics(ctx context.Context, ehpa *autosc
for _, metric := range metrics {
// generate a custom metric for resource metric
if metric.Type == autoscalingv2.ResourceMetricSourceType {
name, err := GetPredictionMetricName(metric.Resource.Name)
if err != nil {
return nil, err
name := GetPredictionMetricName(metric.Resource.Name)
if len(name) == 0 {
continue
}

customMetric := &autoscalingv2.PodsMetricSource{
Expand Down Expand Up @@ -247,14 +247,12 @@ func (c *EffectiveHPAController) GetHPAMetrics(ctx context.Context, ehpa *autosc
}

// GetPredictionMetricName return metric name used by prediction
func GetPredictionMetricName(Name v1.ResourceName) (string, error) {
func GetPredictionMetricName(Name v1.ResourceName) string {
switch Name {
case v1.ResourceCPU:
return known.MetricNamePodCpuUsage, nil
case v1.ResourceMemory:
return known.MetricNamePodMemoryUsage, nil
return known.MetricNamePodCpuUsage
default:
return "", fmt.Errorf("resource name not predictable")
return ""
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/ehpa/predict.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ func (c *EffectiveHPAController) NewPredictionObject(ehpa *autoscalingapi.Effect
for _, metric := range ehpa.Spec.Metrics {
// Convert resource metric into prediction metric
if metric.Type == autoscalingv2.ResourceMetricSourceType {
metricName, err := GetPredictionMetricName(metric.Resource.Name)
if err != nil {
return nil, err
metricName := GetPredictionMetricName(metric.Resource.Name)
if len(metricName) == 0 {
continue
}

predictionMetrics = append(predictionMetrics, predictionapi.PredictionMetric{
Expand Down
3 changes: 1 addition & 2 deletions pkg/known/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ const (
)

const (
MetricNamePodCpuUsage = "pod_cpu_usage"
MetricNamePodMemoryUsage = "pod_memory_usage"
MetricNamePodCpuUsage = "crane_pod_cpu_usage"
)
7 changes: 0 additions & 7 deletions pkg/metricprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ func (p *MetricProvider) GetMetricBySelector(ctx context.Context, namespace stri

if info.Metric == known.MetricNamePodCpuUsage {
metric.Value = *resource.NewMilliQuantity(averageValue, resource.DecimalSI)
} else if info.Metric == known.MetricNamePodMemoryUsage {
metric.Value = *resource.NewMilliQuantity(averageValue, resource.BinarySI)
}

matchingMetrics = append(matchingMetrics, metric)
Expand Down Expand Up @@ -189,11 +187,6 @@ func ListAllLocalMetrics() []provider.CustomMetricInfo {
Namespaced: true,
Metric: known.MetricNamePodCpuUsage,
},
{
GroupResource: schema.GroupResource{Group: "", Resource: "pods"},
Namespaced: true,
Metric: known.MetricNamePodMemoryUsage,
},
}
}

Expand Down

0 comments on commit 31f356a

Please sign in to comment.