Skip to content

Commit

Permalink
Better metadata error handling (#6685)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreYang authored May 19, 2020
1 parent afc5d0f commit a1c9331
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions envoy/datadog_checks/envoy/envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ def _collect_metadata(self, stats_url):
# }
raw_version = response.json()["version"].split('/')[1]
except requests.exceptions.Timeout:
msg = 'Envoy endpoint `{}` timed out after {} seconds'.format(server_info_url, self.http.options['timeout'])
self.log.info(msg)
self.log.warning(
'Envoy endpoint `%s` timed out after %s seconds', server_info_url, self.http.options['timeout']
)
return
except (requests.exceptions.RequestException, requests.exceptions.ConnectionError):
msg = 'Error accessing Envoy endpoint `{}`'.format(server_info_url)
self.log.info(msg)
except Exception as e:
self.log.warning('Error collecting Envoy version with url=`%s`. Error: %s', server_info_url, str(e))
return

self.set_metadata('version', raw_version)
11 changes: 10 additions & 1 deletion envoy/tests/test_envoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,22 @@ def test_metadata(datadog_agent):
instance = INSTANCES['main']
check = Envoy(CHECK_NAME, {}, [instance])
check.check_id = 'test:123'
check.log = mock.MagicMock()

with mock.patch('requests.get', side_effect=requests.exceptions.Timeout()):
check._collect_metadata(instance['stats_url'])
datadog_agent.assert_metadata_count(0)
with mock.patch('requests.get', side_effect=requests.exceptions.RequestException):
check.log.warning.assert_called_with(
'Envoy endpoint `%s` timed out after %s seconds', 'http://localhost:8001/server_info', (10.0, 10.0)
)
with mock.patch('requests.get', side_effect=requests.exceptions.RequestException('Req Exception')):
check._collect_metadata(instance['stats_url'])
datadog_agent.assert_metadata_count(0)
check.log.warning.assert_called_with(
'Error collecting Envoy version with url=`%s`. Error: %s',
'http://localhost:8001/server_info',
'Req Exception',
)

with mock.patch('requests.get', return_value=response('multiple_services')):
check._collect_metadata(instance['stats_url'])
Expand Down

0 comments on commit a1c9331

Please sign in to comment.