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

Filter returned metrics from api server based on queried name. Issue # 702 #732

Merged
merged 1 commit into from
Apr 8, 2020
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: 17 additions & 5 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -83,16 +84,27 @@ func (p *KedaProvider) GetExternalMetric(namespace string, metricSelector labels
}

for _, scaler := range scalers {
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...)
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
Expand Down