-
Notifications
You must be signed in to change notification settings - Fork 29
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
refactor: introduce http get utility; use it in mariner provider #376
Conversation
Every time the application uses requests.get, issue a log message at INFO level containing the requested URL. Signed-off-by: Will Murphy <[email protected]>
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.
There might be an opportunity for refactoring downloading files from a single util function that we can reuse everywhere. That way logging is done the same way, at the same level, can be stubbed out the same way, etc.
based on an offline conversation, this seems like the right time to invest in the common util function to get default retry, logging, and raise behavior for the common requests.get()
…ng-of-network-requests
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
src/vunnel/utils/http.py
Outdated
timeout: int = DEFAULT_TIMEOUT, | ||
**kwargs: Any, | ||
) -> requests.Response: | ||
logger.debug(f"attempting get request on {url}") |
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.
nit/suggestion: since this will show up a lot, the smaller the better
logger.debug(f"attempting get request on {url}") | |
logger.debug(f"http GET {url}") |
src/vunnel/utils/http.py
Outdated
if isinstance(last_exception, BaseException): | ||
logger.error(f"last retry of GET {url} failed with {last_exception}") | ||
raise last_exception | ||
raise Exception("unreachable") |
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.
why not this?
if isinstance(last_exception, BaseException): | |
logger.error(f"last retry of GET {url} failed with {last_exception}") | |
raise last_exception | |
raise Exception("unreachable") | |
logger.error(f"last retry of GET {url} failed with {last_exception}") | |
raise last_exception |
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 had that at first, but the type of last_exception
is Exception | None
, and the static analysis tools can't tell that it's guaranteed not to be None
by the time that line is reached, so I have to check that last_exception
isn't None
before returning it, or static analysis fails. I can change to if last_exception
instead of the isinstance
, but I haven't figured out how to not need this at all.
@@ -91,7 +91,7 @@ def disable_get_requests(monkeypatch): | |||
def disabled(*args, **kwargs): | |||
raise RuntimeError("requests disabled but HTTP GET attempted") | |||
|
|||
monkeypatch.setattr(parser.requests, "get", disabled) | |||
monkeypatch.setattr(utils.http, "get", disabled) |
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.
This could be something like this:
@pytest.fixture()
def disable_get_requests(monkeypatch):
def disabled(*args, **kwargs):
raise RuntimeError("requests disabled but HTTP GET attempted")
from vunnel import utils
monkeypatch.setattr(utils.http, "get", disabled)
and put into conftest.py
generically for anyone to use
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.
🙌
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Create a wrapper for
requests.get
at utils/http.py. The wrapper should always log the URL on failures, and should handle retries. Unit test the wrapper, and use it in the mariner provider.Follow up PRs will introduce the wrapper into other providers.
See #310