From 64bbe65633ce1fce6054fc7b994cac2eb07cabd7 Mon Sep 17 00:00:00 2001 From: rahulkaukuntla <144174402+rahulkaukuntla@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:30:02 -0400 Subject: [PATCH] Fixed the heat endpoint for the Openstack Controller (#17996) * fixing the heat endpoint * added a changelog * addressed comments * addressed comments * lint --- openstack_controller/changelog.d/17996.fixed | 1 + .../openstack_controller/api/api_rest.py | 14 +++++++++----- .../openstack_controller/api/api_sdk.py | 10 ++++++++-- .../openstack_controller/components/heat.py | 2 +- .../tokens/1e6e233e637d4d55a50a62b63398ad15.json | 2 +- .../tokens/6e39099cccde4f809b003d9e0dd09304.json | 2 +- .../POST/identity/v3/auth/tokens/system.json | 14 ++++++++++++++ openstack_controller/tests/test_unit_heat.py | 2 +- 8 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 openstack_controller/changelog.d/17996.fixed diff --git a/openstack_controller/changelog.d/17996.fixed b/openstack_controller/changelog.d/17996.fixed new file mode 100644 index 0000000000000..de917a3d4e085 --- /dev/null +++ b/openstack_controller/changelog.d/17996.fixed @@ -0,0 +1 @@ +Fixed the heat endpoint for the Openstack Controller diff --git a/openstack_controller/datadog_checks/openstack_controller/api/api_rest.py b/openstack_controller/datadog_checks/openstack_controller/api/api_rest.py index 8bd2d8f8d7259..d5bd077ffda06 100644 --- a/openstack_controller/datadog_checks/openstack_controller/api/api_rest.py +++ b/openstack_controller/datadog_checks/openstack_controller/api/api_rest.py @@ -30,11 +30,15 @@ def has_admin_role(self): def component_in_catalog(self, component_types): return self._catalog.has_component(component_types) - def get_response_time(self, endpoint_types, remove_project_id=True): + def get_response_time(self, endpoint_types, remove_project_id=True, is_heat=False): endpoint = ( - self._catalog.get_endpoint_by_type(endpoint_types).replace(self._current_project_id, "") - if self._current_project_id and remove_project_id - else self._catalog.get_endpoint_by_type(endpoint_types) + self._catalog.get_endpoint_by_type(endpoint_types).replace(f"/v1/{self._current_project_id}", "") + if is_heat + else ( + self._catalog.get_endpoint_by_type(endpoint_types).replace(self._current_project_id, "") + if self._current_project_id and remove_project_id + else self._catalog.get_endpoint_by_type(endpoint_types) + ) ) self.log.debug("getting response time for `%s`", endpoint) response = self.http.get(endpoint) @@ -604,7 +608,7 @@ def get_glance_members(self, image_id): def get_heat_stacks(self, project_id): return self.make_paginated_request( - '{}/v1/{}/stacks'.format(self._catalog.get_endpoint_by_type(Component.Types.HEAT.value), project_id), + '{}/stacks'.format(self._catalog.get_endpoint_by_type(Component.Types.HEAT.value)), 'stacks', 'id', next_signifier='links', diff --git a/openstack_controller/datadog_checks/openstack_controller/api/api_sdk.py b/openstack_controller/datadog_checks/openstack_controller/api/api_sdk.py index ecb40a4de620f..0631690fec6f4 100644 --- a/openstack_controller/datadog_checks/openstack_controller/api/api_sdk.py +++ b/openstack_controller/datadog_checks/openstack_controller/api/api_sdk.py @@ -115,10 +115,16 @@ def authorize_project(self, project_id): self.connection.authorize() self.http.options['headers']['X-Auth-Token'] = self.connection.session.auth.get_token(self.connection.session) - def get_response_time(self, endpoint_types, remove_project_id=True): + def get_response_time(self, endpoint_types, remove_project_id=True, is_heat=False): endpoint = self._catalog.get_endpoint_by_type(endpoint_types) endpoint = ( - endpoint.replace(self._access.project_id, "") if self._access.project_id and remove_project_id else endpoint + self._catalog.get_endpoint_by_type(endpoint_types).replace(f"/v1/{self._access.project_id}", "") + if is_heat + else ( + endpoint.replace(self._access.project_id, "") + if self._access.project_id and remove_project_id + else endpoint + ) ) response = self.http.get(endpoint) response.raise_for_status() diff --git a/openstack_controller/datadog_checks/openstack_controller/components/heat.py b/openstack_controller/datadog_checks/openstack_controller/components/heat.py index cc06c11b8350d..2de85a370cbb0 100644 --- a/openstack_controller/datadog_checks/openstack_controller/components/heat.py +++ b/openstack_controller/datadog_checks/openstack_controller/components/heat.py @@ -26,7 +26,7 @@ def __init__(self, check): @Component.http_error(report_service_check=True) def _report_response_time(self, global_components_config, tags): self.check.log.debug("reporting `%s` response time", Heat.ID.value) - response_time = self.check.api.get_response_time(Heat.TYPES.value) + response_time = self.check.api.get_response_time(Heat.TYPES.value, is_heat=True) self.check.log.debug("`%s` response time: %s", Heat.ID.value, response_time) self.check.gauge(HEAT_RESPONSE_TIME, response_time, tags=tags) diff --git a/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/1e6e233e637d4d55a50a62b63398ad15.json b/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/1e6e233e637d4d55a50a62b63398ad15.json index 2d3af4388b620..f61231b95cf61 100644 --- a/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/1e6e233e637d4d55a50a62b63398ad15.json +++ b/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/1e6e233e637d4d55a50a62b63398ad15.json @@ -187,7 +187,7 @@ "id": "168f02a638de42f6b66b60b01f905830", "interface": "public", "region_id": "RegionOne", - "url": "http://127.0.0.1:8004/heat-api", + "url": "http://127.0.0.1:8004/heat-api/v1/1e6e233e637d4d55a50a62b63398ad15", "region": "RegionOne" } ], diff --git a/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/6e39099cccde4f809b003d9e0dd09304.json b/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/6e39099cccde4f809b003d9e0dd09304.json index e81e47f6ac1a6..aee4a1a31d53a 100644 --- a/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/6e39099cccde4f809b003d9e0dd09304.json +++ b/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/6e39099cccde4f809b003d9e0dd09304.json @@ -195,7 +195,7 @@ "id": "168f02a638de42f6b66b60b01f905830", "interface": "public", "region_id": "RegionOne", - "url": "http://127.0.0.1:8004/heat-api", + "url": "http://127.0.0.1:8004/heat-api/v1/6e39099cccde4f809b003d9e0dd09304", "region": "RegionOne" } ], diff --git a/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/system.json b/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/system.json index b4253722af112..45a4814029aa5 100644 --- a/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/system.json +++ b/openstack_controller/tests/fixtures/POST/identity/v3/auth/tokens/system.json @@ -103,6 +103,20 @@ "type": "volumev3", "name": "cinderv3" }, + { + "endpoints": [ + { + "id": "168f02a638de42f6b66b60b01f905830", + "interface": "public", + "region_id": "RegionOne", + "url": "http://127.0.0.1:8004/heat-api", + "region": "RegionOne" + } + ], + "id": "36f45c02edba4500adc2bc5974d22bf0", + "type": "orchestration", + "name": "heat" + }, { "endpoints": [ { diff --git a/openstack_controller/tests/test_unit_heat.py b/openstack_controller/tests/test_unit_heat.py index f1a6120c7267f..cef6d072d5d72 100644 --- a/openstack_controller/tests/test_unit_heat.py +++ b/openstack_controller/tests/test_unit_heat.py @@ -132,7 +132,7 @@ def test_response_time_exception(aggregator, check, dd_run_check, mock_http_get) for call in mock_http_get.call_args_list: args, kwargs = call args_list += list(args) - assert args_list.count('http://127.0.0.1:8004/heat-api') == 2 + assert args_list.count('http://127.0.0.1:8004/heat-api') == 3 @pytest.mark.parametrize(