Skip to content

Commit

Permalink
[Spring Cloud] Fix source code deployment build log issues (#3818)
Browse files Browse the repository at this point in the history
* fix source code deploy log bug

* Bump spring-cloud version to 2.7.1
  • Loading branch information
RuoyuWang-MS authored Aug 26, 2021
1 parent 15743f1 commit 6751a13
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/spring-cloud/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Release History
===============
2.7.1
-----
* Fix source code deployment build log issues

2.7.0
-----
Expand Down
36 changes: 27 additions & 9 deletions src/spring-cloud/azext_spring_cloud/_stream_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,31 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
num_fails_for_backoff = 3
consecutive_sleep_in_sec = 0

blob_exists = False

def safe_get_blob_properties():
'''
In recent storage SDK, the get_blob_properties will output error logs on BlobNotFound (and also raise
AzureHttpError(404)). There is no way to suppress the error logging from the callsite.
However, in our scenario, such BlobNotFound error is expected before the build actually kicks off.
To get rid of the error logging, we only call the get_blob_properties after the blob is created.
'''
nonlocal blob_exists
if not blob_exists:
blob_exists = blob_service.exists(
container_name=container_name, blob_name=blob_name)
if blob_exists:
return blob_service.get_blob_properties(
container_name=container_name, blob_name=blob_name)
return None

# 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(
container_name=container_name, blob_name=blob_name)
metadata = props.metadata
available = props.properties.content_length
props = safe_get_blob_properties()
if props:
metadata = props.metadata
available = props.properties.content_length
except (AttributeError, AzureHttpError):
pass

Expand Down Expand Up @@ -127,7 +145,7 @@ def _stream_logs(no_format, # pylint: disable=too-many-locals, too-many-stateme
stream.write(curr_bytes[i + 1:])
logger_level_func(flush.decode('utf-8', errors='ignore'))
break
if curr_bytes[i:i + 1] == b'\r':
if curr_bytes[i:i + 1] == b'\n':
flush = curr_bytes[:i + 1] # won't logger.warning \n
stream = BytesIO()
stream.write(curr_bytes[i + 1:])
Expand All @@ -144,10 +162,10 @@ 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
props = safe_get_blob_properties()
if props:
metadata = props.metadata
available = props.properties.content_length
except AzureHttpError as ae:
if ae.status_code != 404:
raise CLIError(ae)
Expand Down
2 changes: 1 addition & 1 deletion src/spring-cloud/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# TODO: Confirm this is the right version number you want and it matches your
# HISTORY.rst entry.
VERSION = '2.7.0'
VERSION = '2.7.1'

# The full list of classifiers is available at
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down

0 comments on commit 6751a13

Please sign in to comment.