Skip to content

Commit

Permalink
check that ScaledObject name is specified as part of a query for gett…
Browse files Browse the repository at this point in the history
…ing metrics (#4097)

Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>

Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
  • Loading branch information
zroubalik authored Jan 12, 2023
1 parent f9e3875 commit 0eca1c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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

Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 0eca1c6

Please sign in to comment.