Skip to content

Commit dc7acd0

Browse files
Add new handled exceptions (#17773)
* Add new handled exceptions * Added changelog * Update openstack_controller/changelog.d/17773.added Co-authored-by: Sarah Witt <sarah.witt@datadoghq.com> * return http error response instead of raising an exception * Catch all requests exceptions usingrequests.exceptions.RequestException * Remove CatalogEndPointFailure exception --------- Co-authored-by: Sarah Witt <sarah.witt@datadoghq.com>
1 parent 930ca7e commit dc7acd0

File tree

4 files changed

+7
-14
lines changed

4 files changed

+7
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Handle more exceptions by lowering severity of logs

openstack_controller/datadog_checks/openstack_controller/api/catalog.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

55

6-
class CatalogEndPointFailure(Exception):
7-
def __init__(self, service_types, interface, region_id):
8-
self.message = (
9-
f'No endpoint found in catalog for services={service_types} interface={interface} region_id={region_id}'
10-
)
11-
super().__init__(self.message)
12-
13-
146
class Catalog:
157
def __init__(self, catalog, endpoint_interface, endpoint_region_id):
168
self.catalog = catalog
@@ -38,4 +30,4 @@ def get_endpoint_by_type(self, service_types):
3830
matched_region_id = not self.endpoint_region_id or endpoint_region_id == self.endpoint_region_id
3931
if matched_interface and matched_region_id:
4032
return endpoint['url']
41-
raise CatalogEndPointFailure(service_types, self.endpoint_interface, self.endpoint_region_id)
33+
return None

openstack_controller/datadog_checks/openstack_controller/components/component.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from enum import Enum, unique
77
from functools import wraps
88

9-
from requests.exceptions import HTTPError
9+
import requests
1010

1111
from datadog_checks.base import AgentCheck
1212

@@ -75,8 +75,8 @@ def wrapper(self, *args, **kwargs):
7575
tags = argument_value('tags', func, *args, **kwargs)
7676
self.check.service_check(self.SERVICE_CHECK, AgentCheck.OK, tags=tags)
7777
return result if result is not None else True
78-
except HTTPError as e:
79-
self.check.log.error("HTTPError: %s", e.response)
78+
except requests.exceptions.RequestException as e:
79+
self.check.log.debug("RequestException [%s]: %s", type(e), e)
8080
if report_service_check:
8181
self.check.service_check(self.SERVICE_CHECK, AgentCheck.CRITICAL, tags=tags)
8282
except Exception as e:

openstack_controller/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ def get(url, *args, **kwargs):
989989
method = 'GET'
990990
url = get_url_path(url)
991991
if http_error and url in http_error:
992-
raise requests.exceptions.HTTPError(response=http_error[url])
992+
return http_error[url]
993993

994994
if data and url in data:
995995
return MockResponse(json_data=data[url], status_code=200)
@@ -1015,7 +1015,7 @@ def post(url, *args, **kwargs):
10151015
if exception and url in exception:
10161016
raise exception[url]
10171017
if http_error and url in http_error:
1018-
raise requests.exceptions.HTTPError(response=http_error[url])
1018+
return http_error[url]
10191019
if url == '/identity/v3/auth/tokens':
10201020
data = kwargs['json']
10211021
scope = data.get('auth', {}).get('scope', 'unscoped')

0 commit comments

Comments
 (0)