Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clearer retry logic with logging [RHELDST-9679] #31

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

amcmahon-rh
Copy link
Contributor

Poor retry logic in this library has made some pub tasks fail. The logs are also unclear as to whether retries are occurring or not. This change extends the urllib3 retry logic to include logging to resolve both issues. It also introduces new envvars to make the retry periods configurable. The default backoff settings retry the request 10 times over a 5 minute period.

I have also included the responses library for testing the retry logic. The mock_requests library appeared to not be able to support it, while responses had very clear support.

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0471367) 100.00% compared to head (d2b47e8) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #31   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          123       150   +27     
=========================================
+ Hits           123       150   +27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@amcmahon-rh amcmahon-rh force-pushed the clearRetry branch 3 times, most recently from f282166 to 78357ff Compare January 29, 2024 13:49
@amcmahon-rh
Copy link
Contributor Author

@rbikar @rohanpm @MichalHaluza could this PR be reviewed please.


url = 'https://fastpurge.example.com/ccu/v3/delete/cpcode/production'
# Decrease backoff, otherwise the test will run for 5 minutes
os.environ["FAST_PURGE_RETRY_BACKOFF"] = "0.001"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will not be reverted at the end of the test. This means for other tests run during the same process, it'll be effectively random whether FAST_PURGE_RETRY_BACKOFF=0.001 or not, based on whether each test function ran before or after this one.

Could you please use monkeypatch.setenv instead so it's automatically reverted?

Comment on lines 51 to 53
self._logger.error("An invalid status code %s was received "
"when trying to %s to %s: %s"
% (response.status, method, url, response.reason))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the preferred logging style is to let the logger itself do the interpolation, e.g.

Suggested change
self._logger.error("An invalid status code %s was received "
"when trying to %s to %s: %s"
% (response.status, method, url, response.reason))
self._logger.error("An invalid status code %s was received "
"when trying to %s to %s: %s",
response.status, method, url, response.reason)

One reason is that any exceptions while converting the arguments to strings will themselves then be gracefully logged instead of just crashing.

@amcmahon-rh amcmahon-rh force-pushed the clearRetry branch 2 times, most recently from c0fd128 to 917ea60 Compare February 1, 2024 09:34
tests/test_purge.py Outdated Show resolved Hide resolved
Poor retry logic in this library has made some pub tasks fail. The logs
are also unclear as to whether retries are occurring or not. This change
extends the urllib3 retry logic to include logging to resolve both
issues. It also introduces new envvars to make the retry periods
configurable. The default backoff settings retry the request 10 times
over a 5 minute period.
@amcmahon-rh amcmahon-rh merged commit 19a45cc into master Feb 6, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants