Skip to content

Commit

Permalink
Add error comparison
Browse files Browse the repository at this point in the history
Signed-off-by: constanca <[email protected]>
  • Loading branch information
constanca-m committed Mar 13, 2024
1 parent 0f6de47 commit 0d5b521
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion x-pack/metricbeat/module/azure/monitor/client_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package monitor
import (
"errors"
"fmt"
"net/http"
"strings"
"time"

Expand All @@ -31,14 +32,18 @@ func getMetricsDefinitionsWithRetry(client *azure.Client, resource *armresources
var respError *azcore.ResponseError
ok := errors.As(err, &respError)
if !ok {
return metricDefinitions, fmt.Errorf("%s, failed to cast error to azcore.ResponseError", errorMsg)
}
// Check for TooManyRequests error and retry if it is the case
if respError.StatusCode != http.StatusTooManyRequests {
return metricDefinitions, fmt.Errorf("%s, %w", errorMsg, err)
}

// Check if the error has the header Retry After.
// If it is present, then we should try to make this request again.
retryAfter := respError.RawResponse.Header.Get("Retry-After")
if retryAfter == "" {
return metricDefinitions, fmt.Errorf("%s %w", errorMsg, err)
return metricDefinitions, fmt.Errorf("%s %w, failed to find Retry-After header", errorMsg, err)
}

duration, errD := time.ParseDuration(retryAfter + "s")
Expand Down

0 comments on commit 0d5b521

Please sign in to comment.