Skip to content
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

Improve error message for vmSettings errors #2397

Merged
merged 4 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions azurelinuxagent/common/protocol/wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ def get_vm_settings():

except ProtocolError:
raise
except HttpError as http_error:
raise Exception("{0} [correlation ID: {1} eTag: {2}]".format(ustr(http_error), correlation_id, etag))
except Exception as exception:
error = textutil.format_exception(exception) # since this is a generic error, we format the exception to include the traceback
raise Exception("Error fetching vmSettings [correlation ID: {0} eTag: {1}]: {2}".format(correlation_id, etag, error))
Expand Down Expand Up @@ -1508,18 +1510,19 @@ def __init__(self, operation):
self._operation = operation
self._error_count = 0
self._next_period = datetime.now() + _ErrorReporter._Period
self._log_message_prefix = "[{0}] [Informational only, the Agent will continue normal operation]".format(self._operation)

def report_error(self, error):
self._error_count += 1
if self._error_count <= _ErrorReporter._MaxErrors:
logger.info("[{0}] {1}", self._operation, error)
logger.info("{0} {1}", self._log_message_prefix, error)
add_event(op=self._operation, message=error, is_success=False, log_event=False)

def report_summary(self):
if datetime.now() >= self._next_period:
self._next_period = datetime.now() + _ErrorReporter._Period
if self._error_count > 0:
message = "{0} errors in the last period".format(self._error_count)
logger.info("[{0}] {1}", self._operation, message)
logger.info("{0} {1}", self._log_message_prefix, message)
add_event(op=self._operation, message=message, is_success=False, log_event=False)
self._error_count = 0
18 changes: 9 additions & 9 deletions tests/protocol/test_wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,21 +1272,21 @@ def assert_no_exception(test_case, test_function, expected_error):
def test_error_in_http_request(test_case, mock_response, expected_error):
def do_mock_request():
with mock_wire_protocol(mockwiredata.DATA_FILE_VM_SETTINGS) as protocol:
def http_get_handler(url, *_, **__):
if self.is_host_plugin_vm_settings_request(url):
if isinstance(mock_response, Exception):
raise mock_response
return mock_response
return None
protocol.set_http_handlers(http_get_handler=http_get_handler)
protocol.do_not_mock = lambda method, url: method == "GET" and self.is_host_plugin_vm_settings_request(url)

protocol.client.update_goal_state()
def http_get_vm_settings(_method, _host, _relative_url, **kwargs):
if isinstance(mock_response, Exception):
raise mock_response
return mock_response

with patch("azurelinuxagent.common.utils.restutil._http_request", side_effect=http_get_vm_settings):
protocol.client.update_goal_state()

assert_no_exception(test_case, do_mock_request, expected_error)
#
# We test errors different kind of errors; none of them should make update_protocol raise an exception, but all of them should be reported
#
test_error_in_http_request("Internal error in the HostGAPlugin", MockHttpResponse(httpclient.BAD_GATEWAY), "[Internal error in HostGAPlugin]") # HostGAPlugin uses 502 for internal errors
test_error_in_http_request("Internal error in the HostGAPlugin", MockHttpResponse(httpclient.BAD_GATEWAY), "Status Code 502") # HostGAPlugin uses 502 for internal errors
test_error_in_http_request("Arbitrary error in the request (BAD_REQUEST)", MockHttpResponse(httpclient.BAD_REQUEST), "[HTTP Failed] [400: None]")
test_error_in_http_request("ProtocolError during the request", ProtocolError("GENERIC PROTOCOL ERROR"), "GENERIC PROTOCOL ERROR")
test_error_in_http_request("Generic error in the request", Exception("GENERIC REQUEST ERROR"), "GENERIC REQUEST ERROR")
Expand Down