DataDog / datadog-ci-rb

Ruby library for Datadog test visibility
https://docs.datadoghq.com/continuous_integration/tests/ruby
Other
8 stars 4 forks source link

[SDTEST-292] Retry HTTP requests on 429 and 5xx responses #243

Closed anmarchenko closed 1 month ago

anmarchenko commented 1 month ago

What does this PR do? Expands failed requests retry logic for HTTP client in this library to be as follows:

  1. If response HTTP code is 5xx, retry up to 3 times with exponential backoff
  2. If response HTTP code is 429, retry up to 3 times, take backoff value from X-RateLimit-Reset response header (stop retrying if backoff value is over 30)
  3. If response HTTP code is 4xx (but not 429), fail immediately without retries
  4. If exception is raised due to network issues, retry up to 3 times with exponential backoff

Motivation Better handling of transient server errors and rate limit hits: we have some requests failing with 429/503 according to internal telemetry

How to test the change? Unit tests are provided for each of the above cases

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 98.59155% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.88%. Comparing base (570d019) to head (82207ac).

Files with missing lines Patch % Lines
lib/datadog/ci/transport/http.rb 94.44% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #243 +/- ## ========================================== - Coverage 98.89% 98.88% -0.01% ========================================== Files 279 279 Lines 13524 13575 +51 Branches 620 625 +5 ========================================== + Hits 13374 13424 +50 - Misses 150 151 +1 ``` | [Flag](https://app.codecov.io/gh/DataDog/datadog-ci-rb/pull/243/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | Coverage Δ | | |---|---|---| | [](https://app.codecov.io/gh/DataDog/datadog-ci-rb/pull/243/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | `98.88% <98.59%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.