-
Notifications
You must be signed in to change notification settings - Fork 102
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
FIX: resilient environment settings #825
Merged
hmstepanek
merged 8 commits into
newrelic:main
from
aaeabdo:resilient-environment-settings
Jun 27, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a298b27
FIX: resilient environment settings
aaeabdo 5775452
Merge branch 'main' into resilient-environment-settings
mergify[bot] ab7a9cd
Merge branch 'main' into resilient-environment-settings
mergify[bot] 98bf646
Merge branch 'main' into resilient-environment-settings
mergify[bot] 7cac62c
Merge branch 'main' into resilient-environment-settings
hmstepanek bfaf52a
Merge branch 'main' into resilient-environment-settings
hmstepanek 9f9b13a
Merge branch 'main' into resilient-environment-settings
hmstepanek 84cdb08
Merge branch 'main' into resilient-environment-settings
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing something really obvious here but...I don't really understand this exception block. We are just grabbing the module out of sys.modules here so it's not being import inside the try block as far as I understand so how would this exception get raised in this case? It seems like adding the content inside the try block would be enough to handle the module failing to load.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you're correct; it is indeed confusing. I am currently developing an application that relies on a package using the 'generalimport' package. This package is used to import optional dependencies without having to install them. It raises an exception if the code attempts to call an optional dependency that hasn't been installed. In some way, 'if not module' is interpreted as if the code is trying to use the module, leading to the 'missing dependency' exception. I suspect the flaw lies in the 'generalimport' package. However, I believe the agent should be resilient enough not to fail when building environment settings. Catching the exception here prevents the agent from crashing. Does this make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for that explanation! Ideally we would have a test implemented for this. Let me get back to you on how we might go about setting up the env for that! I don't think we'd want to just add generalimport in as a dependency into the existing env cause then we'd be using it in all our tests. I think we'd instead want to make another env and only run through a couple tests but I'll consult with my team and see what they think would be best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I've talked to my team! As far as testing generalimport; we decided we're just going to manually test it for now which I've already done and this looks good to me! For the python2.7 failed relative imports; let's add a new test for that into https://github.com/newrelic/newrelic-python-agent/blob/main/tests/agent_unittests/test_environment.py. You could probably copy-modify test_plugin_list and maybe call it something like
test_failed_relative_imports_no_harm
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And...I just realized that python 2.7 logic was there already (sorry about that!) so never mind on adding a test for that! I'm gonna go ahead and run the tests for this and merge it if it looks ok in CI.