From f1dd649a3906c40c54f985968995fbea0289fcca Mon Sep 17 00:00:00 2001 From: Jaromir Wysoglad Date: Thu, 24 Jul 2025 13:41:42 -0400 Subject: [PATCH] Rename Aetos's service type to metric-storage Also it's no longer required for the service name to be 'aetos', which better aligns to how other services work and a default 443 port is used for https. Depends-On: https://review.opendev.org/c/openstack/service-types-authority/+/955782 Change-Id: I0f53830cf7ace12d44812a0b2c52aaa7e2ac6d07 Signed-off-by: Jaromir Wysoglad --- observabilityclient/tests/unit/test_utils.py | 32 +++++++------------ observabilityclient/utils/metric_utils.py | 21 ++++++------ observabilityclient/v1/client.py | 2 +- ...e-aetos-service-type-37a53a86f4975803.yaml | 6 ++++ 4 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 releasenotes/notes/change-aetos-service-type-37a53a86f4975803.yaml diff --git a/observabilityclient/tests/unit/test_utils.py b/observabilityclient/tests/unit/test_utils.py index 950b7d2..5d98c29 100644 --- a/observabilityclient/tests/unit/test_utils.py +++ b/observabilityclient/tests/unit/test_utils.py @@ -16,7 +16,6 @@ import os from unittest import mock from keystoneauth1 import adapter -from keystoneauth1 import discover from keystoneauth1 import session import testtools @@ -51,11 +50,6 @@ class GetPrometheusClientTest(testtools.TestCase): super(GetPrometheusClientTest, self).setUp() config_data = 'host: "somehost"\nport: "1234"' self.config_file = mock.mock_open(read_data=config_data)("name", 'r') - self.prom_endpoint_data = discover.EndpointData( - catalog_url="http://localhost:1234/prometheus", - service_type="prometheus", - service_name="aetos" - ) def test_get_prometheus_client_from_file(self): with mock.patch.object(metric_utils, 'get_config_file', @@ -108,12 +102,13 @@ class GetPrometheusClientTest(testtools.TestCase): metric_utils.get_prometheus_client) def test_get_prometheus_client_from_keystone_http(self): + prom_endpoint = "http://localhost:1234/prometheus" keystone_session = session.Session() with mock.patch.dict(os.environ, {}), \ mock.patch.object(metric_utils, 'get_config_file', return_value=None), \ - mock.patch.object(adapter.Adapter, 'get_endpoint_data', - return_value=self.prom_endpoint_data), \ + mock.patch.object(adapter.Adapter, 'get_endpoint', + return_value=prom_endpoint), \ mock.patch.object(prometheus_client.PrometheusAPIClient, "__init__", return_value=None) as init_m, \ mock.patch.object(prometheus_client.PrometheusAPIClient, @@ -125,14 +120,13 @@ class GetPrometheusClientTest(testtools.TestCase): ca_m.assert_not_called() def test_get_prometheus_client_from_keystone_https(self): - self.prom_endpoint_data.catalog_url = \ - "https://localhost:1234/prometheus" + prom_endpoint = "https://localhost:1234/prometheus" keystone_session = session.Session() with mock.patch.dict(os.environ, {}), \ mock.patch.object(metric_utils, 'get_config_file', return_value=None), \ - mock.patch.object(adapter.Adapter, 'get_endpoint_data', - return_value=self.prom_endpoint_data), \ + mock.patch.object(adapter.Adapter, 'get_endpoint', + return_value=prom_endpoint), \ mock.patch.object(prometheus_client.PrometheusAPIClient, "__init__", return_value=None) as init_m, \ mock.patch.object(prometheus_client.PrometheusAPIClient, @@ -144,16 +138,15 @@ class GetPrometheusClientTest(testtools.TestCase): ca_m.assert_called_with(True) def test_get_prometheus_client_from_keystone_custom_ca(self): - self.prom_endpoint_data.catalog_url = \ - "https://localhost:1234/prometheus" + prom_endpoint = "https://localhost:1234/prometheus" keystone_session = session.Session() config_data = 'ca_cert: "ca/path"' config_file = mock.mock_open(read_data=config_data)("name", 'r') with mock.patch.dict(os.environ, {}), \ mock.patch.object(metric_utils, 'get_config_file', return_value=config_file), \ - mock.patch.object(adapter.Adapter, 'get_endpoint_data', - return_value=self.prom_endpoint_data), \ + mock.patch.object(adapter.Adapter, 'get_endpoint', + return_value=prom_endpoint), \ mock.patch.object(prometheus_client.PrometheusAPIClient, "__init__", return_value=None) as init_m, \ mock.patch.object(prometheus_client.PrometheusAPIClient, @@ -192,14 +185,13 @@ class GetPrometheusClientTest(testtools.TestCase): ) def test_get_prometheus_client_from_keystone_ipv6(self): - self.prom_endpoint_data.catalog_url = \ - "http://[2607:5300:201:2000::654]:80/prometheus" + prom_endpoint = "http://[2607:5300:201:2000::654]:80/prometheus" keystone_session = session.Session() with mock.patch.dict(os.environ, {}), \ mock.patch.object(metric_utils, 'get_config_file', return_value=None), \ - mock.patch.object(adapter.Adapter, 'get_endpoint_data', - return_value=self.prom_endpoint_data), \ + mock.patch.object(adapter.Adapter, 'get_endpoint', + return_value=prom_endpoint), \ mock.patch.object(prometheus_client.PrometheusAPIClient, "__init__", return_value=None) as init_m, \ mock.patch.object(prometheus_client.PrometheusAPIClient, diff --git a/observabilityclient/utils/metric_utils.py b/observabilityclient/utils/metric_utils.py index b8267f5..0548fb6 100644 --- a/observabilityclient/utils/metric_utils.py +++ b/observabilityclient/utils/metric_utils.py @@ -73,10 +73,9 @@ def get_prometheus_client(session=None, adapter_options={}): try: endpoint = adapter.Adapter( session=session, **adapter_options - ).get_endpoint_data() - parsed_url = parse.urlparse(endpoint.catalog_url) + ).get_endpoint() + parsed_url = parse.urlparse(endpoint) host = parsed_url.hostname - port = parsed_url.port if parsed_url.port is not None else 80 root_path = parsed_url.path.strip('/') if parsed_url.scheme == "https" and ca_cert is None: # NOTE(jwysogla): Use the default CA certs if the scheme @@ -84,11 +83,13 @@ def get_prometheus_client(session=None, adapter_options={}): # so that a custom certificate can be set in the config # file, while the endpoint is retrieved from keystone. ca_cert = True - if (endpoint.service_type == "prometheus" and - endpoint.service_name == "aetos"): - # We know this is Aetos and we can include keystone tokens - # when sending requests to it. - is_aetos = True + if parsed_url.port is not None: + port = parsed_url.port + elif parsed_url.scheme == "https": + port = 443 + else: + port = 80 + is_aetos = True except keystone_exception.EndpointNotFound: # NOTE(jwysogla): Don't do anything here. It's still possible # to get the correct endpoint configuration from the env vars. @@ -108,8 +109,8 @@ def get_prometheus_client(session=None, adapter_options={}): root_path = os.environ['PROMETHEUS_ROOT_PATH'] if host is None or port is None: raise ConfigurationError("Can't find prometheus host and " - "port configuration and endpoint for service" - "prometheus not found.") + "port configuration and endpoint for " + "metric-storage not found.") escaped_host = netutils.escape_ipv6(host) if is_aetos: client = PrometheusAPIClient( diff --git a/observabilityclient/v1/client.py b/observabilityclient/v1/client.py index 3e0a9bf..c2b62af 100644 --- a/observabilityclient/v1/client.py +++ b/observabilityclient/v1/client.py @@ -28,7 +28,7 @@ class Client(object): session_options = session_options or {} adapter_options = adapter_options or {} - adapter_options.setdefault('service_type', "prometheus") + adapter_options.setdefault('service_type', "metric-storage") if session is None: session = keystoneauth1.session.Session(**session_options) diff --git a/releasenotes/notes/change-aetos-service-type-37a53a86f4975803.yaml b/releasenotes/notes/change-aetos-service-type-37a53a86f4975803.yaml new file mode 100644 index 0000000..de63788 --- /dev/null +++ b/releasenotes/notes/change-aetos-service-type-37a53a86f4975803.yaml @@ -0,0 +1,6 @@ +--- +other: + - | + Service type used to automatically discover Aetos endpoint from + keystone was changed from 'prometheus' to 'metric-storage'. The + service name is no longer required to be 'aetos'.