-
Notifications
You must be signed in to change notification settings - Fork 5
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
818 stac requests resilience #1022
Open
JeroenVerstraelen
wants to merge
13
commits into
master
Choose a base branch
from
818-stac-requests-resilience
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−60
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a1c187b
add custom StacApiIO with timeout and retry support #818
JeroenVerstraelen 068a741
add test for the new custom StacApiIO #818
JeroenVerstraelen 0ac36c0
add retry and timeout support to load_stac requests #818
JeroenVerstraelen c4ccbf3
simplify custom StacApiIO implementation #818
JeroenVerstraelen 8709adf
add UrlopenMocker to test_api_result.py #818
JeroenVerstraelen 822c96d
adjust load_stac tests to use new StacApiIO #818
JeroenVerstraelen afb1c18
loosen restriction on urllib3 version #818
JeroenVerstraelen 92fdf5a
remove test_stac_client.py #818
JeroenVerstraelen 9d3d3ce
avoid importing pystac.stac_io._is_url #818
JeroenVerstraelen dd00806
fix: use timeout field properly in StacApiIO #818
JeroenVerstraelen ee361d2
rename UrlopenMocker to UrllibPoolManagerMocker #818
JeroenVerstraelen cdd75f2
rename urllib_poolmanager_mocker to urllib_poolmanager_mock #818
JeroenVerstraelen 0369576
fix: don't encode urllib_poolmanager_mock data #818
JeroenVerstraelen 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import ( | ||
Dict, | ||
Optional, | ||
) | ||
from urllib.error import HTTPError | ||
from urllib.parse import urlparse | ||
|
||
from pystac.stac_io import DefaultStacIO | ||
from urllib3 import Retry, PoolManager | ||
|
||
|
||
class StacApiIO(DefaultStacIO): | ||
"""A STAC IO implementation that supports reading with timeout and retry.""" | ||
|
||
def __init__( | ||
self, | ||
headers: Optional[Dict[str, str]] = None, | ||
timeout: Optional[float] = None, | ||
retry: Optional[Retry] = None, | ||
): | ||
super().__init__(headers=headers) | ||
self.timeout = timeout or 20 | ||
self.retry = retry or Retry() | ||
|
||
def read_text_from_href(self, href: str) -> str: | ||
"""Reads file as a UTF-8 string, with retry and timeout support. | ||
soxofaan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Args: | ||
href : The URI of the file to open. | ||
""" | ||
is_url = urlparse(href).scheme != "" | ||
if is_url: | ||
http = PoolManager(retries=self.retry, timeout=self.timeout) | ||
try: | ||
response = http.request( | ||
"GET", href | ||
) | ||
return response.data.decode("utf-8") | ||
except HTTPError as e: | ||
raise Exception("Could not read uri {}".format(href)) from e | ||
else: | ||
return super().read_text_from_href(href) |
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
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
Oops, something went wrong.
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.
Can you document what this class adds on top of the existing DefaultStacIO?
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.
Done.
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.
While checking some pystac details I stumbled on
pystac.stac_io.RetryStacIO
https://pystac.readthedocs.io/en/stable/api/stac_io.html#pystac.stac_io.RetryStacIO shouldn't we just use that instead?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.
as discussed: RetryStacIO does not have timeout control.
I opened a ticket to feature-request that already:
I would add a technical debt comment to migrate to that solution in the future instead of having to maintain this home-grown wrapper/hack