-
Notifications
You must be signed in to change notification settings - Fork 254
update retry logic and logging #474
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
Conversation
### What 1. configureable retry count 2. additional logging ### Why 1. pass retry count as a command line arg; default 5 2. show details when api requests fail ### Testing before merge compiles cleanly ### Validation after merge compile and test ### Issue addressed by this PR stellar/ops#2039
|
Good to have the number of retries configurable. I noticed an issue with how the --retries flag is wired up - it looks like the value doesn't actually propagate to the retry logic. Here's a quick test: from github_backup.github_backup import MAX_RETRIES as GB_MAX_RETRIES
from github_backup import max_retries
print(f'Before: github_backup.MAX_RETRIES = {GB_MAX_RETRIES}')
# Simulate what cli.py does
max_retries.MAX_RETRIES = 20
from github_backup.github_backup import MAX_RETRIES as GB_MAX_RETRIES_AFTER
print(f'After: github_backup.MAX_RETRIES = {GB_MAX_RETRIES_AFTER}')Output: The issue is that MAX_RETRIES = max_retries.MAX_RETRIES in github_backup.py copies the value at import time, so later updates to the module don't affect it. Adding a new file just to hold a single mutable global is also a bit heavyweight. Since --retries already has default=5 in argparse, you could just use A couple of other things:
|
|
Curious as to what https://github.com/stellar/ops/issues/2039 details, as it can't be accessed. Could you summarise it? |
Possibly, I'll have to try this out.
Ack |
We ran into an issue where the backup wasn't working but it wasn't clear from the logs what the problem was. We did some quick hacking of the script to see the problem was API calls failing. It'd be nice to have this level of logging by default. For max_retries, it'd be nice for the operator to be able to set this to whatever value they want. |
I'm not seeing what you're seeing. Perhaps you could make a new docker image with my branch and test? It seems to me the simplest way is to use a file with a mutable global, but if that's not acceptable, I can create a new function in |
The issue I saw was fixed in 1f2ec01 - removing MAX_RETRIES = max_retries.MAX_RETRIES addresses the import-time copy issue. I was looking at the original commit.
Passing the retry count as a parameter rather than using a separate module feels a lot cleaner to me. I think @josegonzalez is the only one who gets to pull the 'acceptable' card. :) Since retrieve_data already has args, it's a small change: def make_request_with_retry(request, auth, max_retries=5):
...
for attempt in range(max_retries):And in retrieve_data: http_response = make_request_with_retry(request, auth, args.max_retries)The other loop in fetch_all can use args.max_retries directly since it's nested inside retrieve_data and has access via closure. The global MAX_RETRIES could be removed. The existing tests would need updating for the new CLI option too, but that's easy enough. I can redo the tests if you want. This follows the existing pattern in the codebase and avoids the extra max_retries.py module. |
|
Whatever either:
Is fine with me, as long as it doesn't break existing functionality. |
Sounds good, I'll update the PR soon |
|
@Iamrodos I've made the updates. PTAL please. |
|
Thanks for the updates @mwtzzz! Changes look good. I've put together a patch to update the tests, plus fix a off-by-one-error (mine) that you can apply: What's in the patch:
To apply the patch: # From your branch
curl -L <patch-url> | git apply
# or download and:
git apply retry_fixes.patchAll 81 tests pass and linting (flake8, black) passes. Let me know if you have any questions. |
|
Thanks for your assistance @Iamrodos , I have applied your patch and updated the PR. |
|
Nice, all looks great. Helpful enhancement. |
What
Why
Testing before merge
compiles cleanly
Validation after merge
compile and test
Issue addressed by this PR
https://github.com/stellar/ops/issues/2039