Skip to content

Add new handled exceptions #17773

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

Merged
merged 8 commits into from
Jun 11, 2024
Merged
1 change: 1 addition & 0 deletions openstack_controller/changelog.d/17773.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle more exceptions by lowering severity of logs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from enum import Enum, unique
from functools import wraps

from requests.exceptions import HTTPError
import requests

from datadog_checks.base import AgentCheck
from datadog_checks.openstack_controller.api.catalog import CatalogEndPointFailure


def argument_value(arg_name, func, *args, **kwargs):
Expand Down Expand Up @@ -75,10 +76,12 @@ def wrapper(self, *args, **kwargs):
tags = argument_value('tags', func, *args, **kwargs)
self.check.service_check(self.SERVICE_CHECK, AgentCheck.OK, tags=tags)
return result if result is not None else True
except HTTPError as e:
self.check.log.error("HTTPError: %s", e.response)
except (requests.HTTPError, requests.ConnectionError, requests.Timeout, requests.RequestException) as e:
self.check.log.debug("HTTPError: %s", e.response)
if report_service_check:
self.check.service_check(self.SERVICE_CHECK, AgentCheck.CRITICAL, tags=tags)
except CatalogEndPointFailure as e:
self.check.log.debug("CatalogEndPointFailure: %s", e)
except Exception as e:
self.check.log.error("Exception: %s", e)
return None
Expand Down
4 changes: 2 additions & 2 deletions openstack_controller/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ def get(url, *args, **kwargs):
method = 'GET'
url = get_url_path(url)
if http_error and url in http_error:
raise requests.exceptions.HTTPError(response=http_error[url])
return http_error[url]

if data and url in data:
return MockResponse(json_data=data[url], status_code=200)
Expand All @@ -1015,7 +1015,7 @@ def post(url, *args, **kwargs):
if exception and url in exception:
raise exception[url]
if http_error and url in http_error:
raise requests.exceptions.HTTPError(response=http_error[url])
return http_error[url]
if url == '/identity/v3/auth/tokens':
data = kwargs['json']
scope = data.get('auth', {}).get('scope', 'unscoped')
Expand Down
Loading