From 00e9f563ce24b79d2ebb95b24ea2e42d9d7ae5ee Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Thu, 12 Jan 2023 13:33:56 +0100 Subject: [PATCH] check that ScaledObject name is specified as part of a query for getting metrics Signed-off-by: Zbynek Roubalik --- CHANGELOG.md | 1 + pkg/provider/provider.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67233d402e3..a9dd089a2b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ New deprecation(s): - **RabbitMQ Scaler:** Move from `streadway/amqp` to `rabbitmq/amqp091-go` ([#4004](https://github.com/kedacore/keda/pull/4039)) - **General:** Compare error with `errors.Is` ([#4004](https://github.com/kedacore/keda/pull/4004)) +- **General:** Check that ScaledObject name is specified as part of a query for getting metrics ([#4088](https://github.com/kedacore/keda/pull/4088)) ## v2.9.1 diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index f6b1eea34e5..8561ed9956e 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -99,6 +99,12 @@ func (p *KedaProvider) GetExternalMetric(ctx context.Context, namespace string, // selector is in form: `scaledobject.keda.sh/name: scaledobject-name` scaledObjectName := selector.Get(kedav1alpha1.ScaledObjectOwnerAnnotation) + if scaledObjectName == "" { + err := fmt.Errorf("scaledObject name is not specified") + logger.Error(err, fmt.Sprintf("please specify scaledObject name, it needs to be set as value of label selector %q on the query", kedav1alpha1.ScaledObjectOwnerAnnotation)) + + return &external_metrics.ExternalMetricValueList{}, err + } metrics, promMetrics, err := p.grpcClient.GetMetrics(ctx, scaledObjectName, namespace, info.Metric) logger.V(1).WithValues("scaledObjectName", scaledObjectName, "scaledObjectNamespace", namespace, "metrics", metrics).Info("Receiving metrics")