Filter returned metrics from api server based on queried name
@@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
+ "strings"
kedav1alpha1 "github.com/kedacore/keda/pkg/apis/keda/v1alpha1"
"github.com/kedacore/keda/pkg/handler"
@@ -83,16 +84,27 @@ func (p *KedaProvider) GetExternalMetric(namespace string, metricSelector labels
}
for _, scaler := range scalers {
+ metricSpecs := scaler.GetMetricSpecForScaling()
+
+ for _, metricSpec := range metricSpecs {
+ // Filter only the desired metric
+ if strings.EqualFold(metricSpec.External.MetricName, info.Metric) {
metrics, err := scaler.GetMetrics(context.TODO(), info.Metric, metricSelector)
if err != nil {
logger.Error(err, "error getting metric for scaler", "ScaledObject.Namespace", scaledObject.Namespace, "ScaledObject.Name", scaledObject.Name, "Scaler", scaler)
} else {
matchingMetrics = append(matchingMetrics, metrics...)
}
+ }
+ }
scaler.Close()
}
+ if len(matchingMetrics) <= 0 {
+ return nil, fmt.Errorf("No matching metrics found for " + info.Metric)
+ }
+
return &external_metrics.ExternalMetricValueList{
Items: matchingMetrics,
}, nil
