-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[ACR] Fix#16700: Use "exists" api to check storage blob existence #17299
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme | |
if not no_format: | ||
colorama.init() | ||
|
||
log_exist = False | ||
stream = BytesIO() | ||
metadata = {} | ||
start = 0 | ||
|
@@ -92,10 +93,18 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme | |
# Try to get the initial properties so there's no waiting. | ||
# If the storage call fails, we'll just sleep and try again after. | ||
try: | ||
props = blob_service.get_blob_properties( | ||
# Need to call "exists" API to prevent storage SDK logging BlobNotFound error | ||
log_exist = blob_service.exists( | ||
container_name=container_name, blob_name=blob_name) | ||
metadata = props.metadata | ||
available = props.properties.content_length | ||
|
||
if log_exist: | ||
props = blob_service.get_blob_properties( | ||
container_name=container_name, blob_name=blob_name) | ||
metadata = props.metadata | ||
available = props.properties.content_length | ||
else: | ||
# Wait a little bit before checking the existence again | ||
time.sleep(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does it retry after sleep? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code will continue to the loop, since log_exists is false in this case, it will execute L158-159 to check the existence again |
||
except (AttributeError, AzureHttpError): | ||
pass | ||
|
||
|
@@ -140,10 +149,14 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme | |
return | ||
|
||
try: | ||
props = blob_service.get_blob_properties( | ||
container_name=container_name, blob_name=blob_name) | ||
metadata = props.metadata | ||
available = props.properties.content_length | ||
if log_exist: | ||
props = blob_service.get_blob_properties( | ||
container_name=container_name, blob_name=blob_name) | ||
metadata = props.metadata | ||
available = props.properties.content_length | ||
else: | ||
log_exist = blob_service.exists( | ||
container_name=container_name, blob_name=blob_name) | ||
except AzureHttpError as ae: | ||
if ae.status_code != 404: | ||
raise CLIError(ae) | ||
|
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.
@northtyphoon can
props
be null?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, it will throw error like AureHttpError, in that case, we will retry or just exit if the code doesn't know how to handle it