Skip to content
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

Fixed the heat endpoint for the Openstack Controller #17996

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 +30,20 @@ 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("/v1/" + self._current_project_id, "")
rahulkaukuntla marked this conversation as resolved.
Show resolved Hide resolved
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)
response.raise_for_status()
self.log.debug(response.json())
rahulkaukuntla marked this conversation as resolved.
Show resolved Hide resolved
return response.elapsed.total_seconds() * 1000

def get_auth_projects(self):
Expand Down Expand Up @@ -604,7 +609,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",
rahulkaukuntla marked this conversation as resolved.
Show resolved Hide resolved
"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
8 changes: 5 additions & 3 deletions openstack_controller/tests/test_unit_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,25 @@ def test_not_in_catalog(aggregator, check, dd_run_check, caplog, mock_http_post,


@pytest.mark.parametrize(
('mock_http_get', 'instance'),
('mock_http_get', 'instance', 'expected_api_calls'),
[
pytest.param(
{'http_error': {'/heat-api': MockResponse(status_code=500)}},
configs.REST,
2,
id='api rest',
),
pytest.param(
{'http_error': {'/heat-api': MockResponse(status_code=500)}},
configs.SDK,
3,
id='api sdk',
),
],
indirect=['mock_http_get'],
)
@pytest.mark.usefixtures('mock_http_get', 'mock_http_post', 'openstack_connection')
def test_response_time_exception(aggregator, check, dd_run_check, mock_http_get):
def test_response_time_exception(aggregator, check, dd_run_check, mock_http_get, expected_api_calls):
dd_run_check(check)
aggregator.assert_metric(
'openstack.heat.response_time',
Expand All @@ -132,7 +134,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') == expected_api_calls


@pytest.mark.parametrize(
Expand Down
Loading