Skip to content

Commit

Permalink
DataDog: Check for response object before returning the generic error (
Browse files Browse the repository at this point in the history
…#4259)

Signed-off-by: Ara Pulido <ara.pulido@datadoghq.com>
  • Loading branch information
arapulido authored Feb 22, 2023
1 parent 69b3767 commit 8e7169d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ 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))
Expand Down
25 changes: 16 additions & 9 deletions pkg/scalers/datadog_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 8e7169d

Please sign in to comment.