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 exponential retry on fetch #60

Merged
merged 1 commit into from
May 6, 2021
Merged

Conversation

go-dima
Copy link
Contributor

@go-dima go-dima commented Mar 30, 2021

What does this PR do?

  • Add a retry for 500 server error using exponential backoff mechanism

@go-dima go-dima requested a review from a team as a code owner March 30, 2021 14:13
@go-dima
Copy link
Contributor Author

go-dima commented Apr 4, 2021

PR fails due to missing dependency -backoff module.
What is the correct way to add this in the project? The options I found weer requirements.txt (didn't work) or in the dockerfile itself.

@rpothier
Copy link
Contributor

rpothier commented Apr 5, 2021

Hi @go-dima
Looking at the error message.
ERROR: Found 1 import issue(s) on python 2.7 which need to be resolved:
ERROR: plugins/lookup/conjur_variable.py:100:0: traceback: ImportError: No module named backoff
See documentation for help: https://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/import.html

The issue seems to be that Ansible is requiring the import in a try/except block.
I just added comments on the review.

@@ -97,6 +97,7 @@
from stat import S_IRUSR, S_IWUSR
from tempfile import gettempdir, NamedTemporaryFile
import yaml
import backoff
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a try/except block as described in https://docs.ansible.com/ansible/devel/dev_guide/testing/sanity/import.html

try:
    import backoff
except ImportError as imp_exc:
    BACKOFF_IMPORT_ERROR = imp_exc
else:
    BACKOFF_IMPORT_ERROR = None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take a look. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rpothier, Same result. It looks like the module isn't found, although it is supported officially.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm looking into it also. When you say it's officially supported, do you mean by python? or Ansible?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @go-dima I did some research with Ansible and it looks like they do not support non standard libraries.
Ansible has ansible.module_utils.api.retry can you use that instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like ansible retry doesn't fit - it expects an exception to identify failure for retry. I'll keep looking for a suitable solution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rpothier
I decided to implement it myself, care to tae a look?
I also need an approval to run workflows now :)

requirements.txt Outdated Show resolved Hide resolved
@go-dima go-dima requested review from rpothier and removed request for a team April 29, 2021 06:52
@go-dima
Copy link
Contributor Author

go-dima commented Apr 29, 2021

@rpothier
Looks like I have yml issues, although my change didn't involve such.
I'll be glad to get some help on the matter.

@rpothier
Copy link
Contributor

rpothier commented Apr 30, 2021

Hi @go-dima, I tried re-running it, but same results. I'll try a baseline run.

I'm seeing the same errors on another branch, so the errors are not due to your changes.
You can check #61 to verify
the errors are the same.

@rpothier
Copy link
Contributor

rpothier commented May 3, 2021

@go-dima I have posted #61 with a fix for the sanity errors.

@go-dima
Copy link
Contributor Author

go-dima commented May 4, 2021

Thanks for the update! I'll wait for #61 and update this one.

@go-dima
Copy link
Contributor Author

go-dima commented May 4, 2021

@rpothier can you re-trigger the build please? (I don't have permissions)

@rpothier
Copy link
Contributor

rpothier commented May 4, 2021

@go-dima Did you rebase with the latest?

Copy link
Contributor

@rpothier rpothier left a comment

Choose a reason for hiding this comment

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

Can you summarize the testing that was done to validate this?

@rpothier
Copy link
Contributor

rpothier commented May 5, 2021

@go-dima Woohoo! tests all pass. Changes look good.
Please squash the commits and can you describe the testing that was done?

@go-dima
Copy link
Contributor Author

go-dima commented May 5, 2021

@rpothier
Latest was merged 👍

Regarding the tests:
We work with a docker worker to run our plays, so I changed the image to include the plugin from my branch. I triggered a workflow that uses the plugin multiple times in different places, to make sure the change doesn't break the successful flow.

I don't have a proper way to make sure that the retry happens during the plugin (since I cannot force 500 reply), but I did test the code in a standalone scenario with a simulated 500 error.

Regarding the squash - I plan to perform the merge itself with 'squash and merge' option.

rpothier
rpothier previously approved these changes May 5, 2021
Copy link
Contributor

@rpothier rpothier left a comment

Choose a reason for hiding this comment

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

LGTM

@go-dima
Copy link
Contributor Author

go-dima commented May 5, 2021

@rpothier
I don't have write access (no surprising actually...)
Can you merge please? 🥇

@rpothier
Copy link
Contributor

rpothier commented May 5, 2021

@go-dima Can you sign off your commit ? https://github.com/cyberark/community/blob/master/CONTRIBUTING.md#signing-off-a-commit

@go-dima
Copy link
Contributor Author

go-dima commented May 6, 2021

@rpothier Done
Since I already making changes, I squashed everything to a single commit

Implement custom retry decorator

Signed-off-by: Dima Gonikman <dima.gonikman@gmail.com>
Copy link
Contributor

@rpothier rpothier left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants