Skip to content

Commit

Permalink
Fixed the heat endpoint for the Openstack Controller (DataDog#17996)
Browse files Browse the repository at this point in the history
* fixing the heat endpoint

* added a changelog

* addressed comments

* addressed comments

* lint
  • Loading branch information
rahulkaukuntla authored and ravindrasojitra-crest committed Aug 5, 2024
1 parent 7508c94 commit 64bbe65
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions openstack_controller/changelog.d/17996.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the heat endpoint for the Openstack Controller
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion openstack_controller/tests/test_unit_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 64bbe65

Please sign in to comment.