From bca8e121095664ffe80bdfb3ef4159c2260526e4 Mon Sep 17 00:00:00 2001 From: Ara Pulido Date: Tue, 21 Feb 2023 12:20:56 +0100 Subject: [PATCH 1/3] Check for response object before returning the generic error Signed-off-by: Ara Pulido --- pkg/scalers/datadog_scaler.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/scalers/datadog_scaler.go b/pkg/scalers/datadog_scaler.go index 364eb516ac0..e021bfa7cc9 100644 --- a/pkg/scalers/datadog_scaler.go +++ b/pkg/scalers/datadog_scaler.go @@ -286,19 +286,26 @@ func (s *datadogScaler) getQueryResult(ctx context.Context) (float64, error) { timeWindowTo := time.Now().Unix() - int64(s.metadata.timeWindowOffset) timeWindowFrom := timeWindowTo - int64(s.metadata.age) resp, r, err := s.apiClient.MetricsApi.QueryMetrics(ctx, timeWindowFrom, timeWindowTo, s.metadata.query) //nolint:bodyclose - if err != nil { - return -1, fmt.Errorf("error when retrieving Datadog metrics: %w", err) - } - if r.StatusCode == 429 { - rateLimit := r.Header.Get("X-Ratelimit-Limit") - rateLimitReset := r.Header.Get("X-Ratelimit-Reset") + if r != nil { + if r.StatusCode == 429 { + rateLimit := r.Header.Get("X-Ratelimit-Limit") + rateLimitReset := r.Header.Get("X-Ratelimit-Reset") + rateLimitPeriod := r.Header.Get("X-Ratelimit-Period") + + return -1, fmt.Errorf("your Datadog account reached the %s queries per %s seconds rate limit, next limit reset will happen in %s seconds", rateLimit, rateLimitPeriod, rateLimitReset) + } - return -1, fmt.Errorf("your Datadog account reached the %s queries per hour rate limit, next limit reset will happen in %s seconds", rateLimit, rateLimitReset) + if r.StatusCode != 200 { + if err != nil { + return -1, fmt.Errorf("error when retrieving Datadog metrics: %w", err) + } + return -1, fmt.Errorf("error when retrieving Datadog metrics") + } } - if r.StatusCode != 200 { - return -1, fmt.Errorf("error when retrieving Datadog metrics") + if err != nil { + return -1, fmt.Errorf("error when retrieving Datadog metrics: %w", err) } if resp.GetStatus() == "error" { From 15be70b83776b5e2017d286690078d4fd6ee2867 Mon Sep 17 00:00:00 2001 From: Ara Pulido Date: Tue, 21 Feb 2023 12:24:03 +0100 Subject: [PATCH 2/3] Update changelog for issue #4187 Signed-off-by: Ara Pulido --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f3ca53462..bc28d129a1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ Here is an overview of all new **experimental** features: - **Kafka Scaler**: Support 0 in activationLagThreshold configuration ([#4137](https://github.com/kedacore/keda/issues/4137)) - **Prometheus Metrics**: Expose Prometheus Metrics also when getting ScaledObject state ([#4075](https://github.com/kedacore/keda/issues/4075)) - **Redis Scalers**: Fix panic produced by incorrect logger initialization ([#4197](https://github.com/kedacore/keda/issues/4197)) +- **Datadog Scaler**: Return correct error when getting a 429 error ([#4187](https://github.com/kedacore/keda/issues/4187)) ### Deprecations From 0153b6efd93d4435788956baa6d6513ae6c3a178 Mon Sep 17 00:00:00 2001 From: Ara Pulido Date: Wed, 22 Feb 2023 09:17:08 +0100 Subject: [PATCH 3/3] Sort changelog alphabetically --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc28d129a1e..70edd011e30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,11 +78,11 @@ Here is an overview of all new **experimental** features: - **Azure Service Bus Scaler:** Use correct auth flows with pod identity ([#4026](https://github.com/kedacore/keda/issues/4026)|[#4123](https://github.com/kedacore/keda/issues/4123)) - **Cassandra Scaler**: Checking whether the port information is entered in the ClusterIPAddres is done correctly. ([#4110](https://github.com/kedacore/keda/issues/4110)) - **CPU Memory Scaler** Store forgotten logger ([#4022](https://github.com/kedacore/keda/issues/4022)) +- **Datadog Scaler**: Return correct error when getting a 429 error ([#4187](https://github.com/kedacore/keda/issues/4187)) - **Kafka Scaler**: Return error if the processing of the partition lag fails ([#4098](https://github.com/kedacore/keda/issues/4098)) - **Kafka Scaler**: Support 0 in activationLagThreshold configuration ([#4137](https://github.com/kedacore/keda/issues/4137)) - **Prometheus Metrics**: Expose Prometheus Metrics also when getting ScaledObject state ([#4075](https://github.com/kedacore/keda/issues/4075)) - **Redis Scalers**: Fix panic produced by incorrect logger initialization ([#4197](https://github.com/kedacore/keda/issues/4197)) -- **Datadog Scaler**: Return correct error when getting a 429 error ([#4187](https://github.com/kedacore/keda/issues/4187)) ### Deprecations