Skip to content

Commit

Permalink
Only return metrics matching MetricName. Issue #702 (#727)
Browse files Browse the repository at this point in the history
Signed-off-by: zhak <zhak@kimonocloud.com>

Co-authored-by: zhak <zhak@kimonocloud.com>
  • Loading branch information
ycabrer and zhak authored Apr 6, 2020
1 parent e79249a commit 47afebc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,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 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")
}

return &external_metrics.ExternalMetricValueList{
Items: matchingMetrics,
}, nil
Expand Down

0 comments on commit 47afebc

Please sign in to comment.