diff --git a/openstack_controller/changelog.d/17773.added b/openstack_controller/changelog.d/17773.added new file mode 100644 index 0000000000000..488482beff721 --- /dev/null +++ b/openstack_controller/changelog.d/17773.added @@ -0,0 +1 @@ +Handle more exceptions by lowering severity of logs diff --git a/openstack_controller/datadog_checks/openstack_controller/api/catalog.py b/openstack_controller/datadog_checks/openstack_controller/api/catalog.py index ae21a48832ca0..ec49c6f4f3b9f 100644 --- a/openstack_controller/datadog_checks/openstack_controller/api/catalog.py +++ b/openstack_controller/datadog_checks/openstack_controller/api/catalog.py @@ -3,14 +3,6 @@ # Licensed under a 3-clause BSD style license (see LICENSE) -class CatalogEndPointFailure(Exception): - def __init__(self, service_types, interface, region_id): - self.message = ( - f'No endpoint found in catalog for services={service_types} interface={interface} region_id={region_id}' - ) - super().__init__(self.message) - - class Catalog: def __init__(self, catalog, endpoint_interface, endpoint_region_id): self.catalog = catalog @@ -38,4 +30,4 @@ def get_endpoint_by_type(self, service_types): matched_region_id = not self.endpoint_region_id or endpoint_region_id == self.endpoint_region_id if matched_interface and matched_region_id: return endpoint['url'] - raise CatalogEndPointFailure(service_types, self.endpoint_interface, self.endpoint_region_id) + return None diff --git a/openstack_controller/datadog_checks/openstack_controller/components/component.py b/openstack_controller/datadog_checks/openstack_controller/components/component.py index 0d9baa46f132f..46ab04586c4d3 100644 --- a/openstack_controller/datadog_checks/openstack_controller/components/component.py +++ b/openstack_controller/datadog_checks/openstack_controller/components/component.py @@ -6,7 +6,7 @@ from enum import Enum, unique from functools import wraps -from requests.exceptions import HTTPError +import requests from datadog_checks.base import AgentCheck @@ -75,8 +75,8 @@ 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.exceptions.RequestException as e: + self.check.log.debug("RequestException [%s]: %s", type(e), e) if report_service_check: self.check.service_check(self.SERVICE_CHECK, AgentCheck.CRITICAL, tags=tags) except Exception as e: diff --git a/openstack_controller/tests/conftest.py b/openstack_controller/tests/conftest.py index 2e3c6d27739cd..edc7e6e17decb 100644 --- a/openstack_controller/tests/conftest.py +++ b/openstack_controller/tests/conftest.py @@ -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) @@ -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')