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 <jwysogla@redhat.com>
This commit is contained in:
Jaromir Wysoglad
2025-07-24 13:41:42 -04:00
parent 0293fa7aea
commit f1dd649a39
4 changed files with 30 additions and 31 deletions

View File

@@ -16,7 +16,6 @@ import os
from unittest import mock from unittest import mock
from keystoneauth1 import adapter from keystoneauth1 import adapter
from keystoneauth1 import discover
from keystoneauth1 import session from keystoneauth1 import session
import testtools import testtools
@@ -51,11 +50,6 @@ class GetPrometheusClientTest(testtools.TestCase):
super(GetPrometheusClientTest, self).setUp() super(GetPrometheusClientTest, self).setUp()
config_data = 'host: "somehost"\nport: "1234"' config_data = 'host: "somehost"\nport: "1234"'
self.config_file = mock.mock_open(read_data=config_data)("name", 'r') 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): def test_get_prometheus_client_from_file(self):
with mock.patch.object(metric_utils, 'get_config_file', with mock.patch.object(metric_utils, 'get_config_file',
@@ -108,12 +102,13 @@ class GetPrometheusClientTest(testtools.TestCase):
metric_utils.get_prometheus_client) metric_utils.get_prometheus_client)
def test_get_prometheus_client_from_keystone_http(self): def test_get_prometheus_client_from_keystone_http(self):
prom_endpoint = "http://localhost:1234/prometheus"
keystone_session = session.Session() keystone_session = session.Session()
with mock.patch.dict(os.environ, {}), \ with mock.patch.dict(os.environ, {}), \
mock.patch.object(metric_utils, 'get_config_file', mock.patch.object(metric_utils, 'get_config_file',
return_value=None), \ return_value=None), \
mock.patch.object(adapter.Adapter, 'get_endpoint_data', mock.patch.object(adapter.Adapter, 'get_endpoint',
return_value=self.prom_endpoint_data), \ return_value=prom_endpoint), \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,
"__init__", return_value=None) as init_m, \ "__init__", return_value=None) as init_m, \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,
@@ -125,14 +120,13 @@ class GetPrometheusClientTest(testtools.TestCase):
ca_m.assert_not_called() ca_m.assert_not_called()
def test_get_prometheus_client_from_keystone_https(self): def test_get_prometheus_client_from_keystone_https(self):
self.prom_endpoint_data.catalog_url = \ prom_endpoint = "https://localhost:1234/prometheus"
"https://localhost:1234/prometheus"
keystone_session = session.Session() keystone_session = session.Session()
with mock.patch.dict(os.environ, {}), \ with mock.patch.dict(os.environ, {}), \
mock.patch.object(metric_utils, 'get_config_file', mock.patch.object(metric_utils, 'get_config_file',
return_value=None), \ return_value=None), \
mock.patch.object(adapter.Adapter, 'get_endpoint_data', mock.patch.object(adapter.Adapter, 'get_endpoint',
return_value=self.prom_endpoint_data), \ return_value=prom_endpoint), \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,
"__init__", return_value=None) as init_m, \ "__init__", return_value=None) as init_m, \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,
@@ -144,16 +138,15 @@ class GetPrometheusClientTest(testtools.TestCase):
ca_m.assert_called_with(True) ca_m.assert_called_with(True)
def test_get_prometheus_client_from_keystone_custom_ca(self): def test_get_prometheus_client_from_keystone_custom_ca(self):
self.prom_endpoint_data.catalog_url = \ prom_endpoint = "https://localhost:1234/prometheus"
"https://localhost:1234/prometheus"
keystone_session = session.Session() keystone_session = session.Session()
config_data = 'ca_cert: "ca/path"' config_data = 'ca_cert: "ca/path"'
config_file = mock.mock_open(read_data=config_data)("name", 'r') config_file = mock.mock_open(read_data=config_data)("name", 'r')
with mock.patch.dict(os.environ, {}), \ with mock.patch.dict(os.environ, {}), \
mock.patch.object(metric_utils, 'get_config_file', mock.patch.object(metric_utils, 'get_config_file',
return_value=config_file), \ return_value=config_file), \
mock.patch.object(adapter.Adapter, 'get_endpoint_data', mock.patch.object(adapter.Adapter, 'get_endpoint',
return_value=self.prom_endpoint_data), \ return_value=prom_endpoint), \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,
"__init__", return_value=None) as init_m, \ "__init__", return_value=None) as init_m, \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,
@@ -192,14 +185,13 @@ class GetPrometheusClientTest(testtools.TestCase):
) )
def test_get_prometheus_client_from_keystone_ipv6(self): def test_get_prometheus_client_from_keystone_ipv6(self):
self.prom_endpoint_data.catalog_url = \ prom_endpoint = "http://[2607:5300:201:2000::654]:80/prometheus"
"http://[2607:5300:201:2000::654]:80/prometheus"
keystone_session = session.Session() keystone_session = session.Session()
with mock.patch.dict(os.environ, {}), \ with mock.patch.dict(os.environ, {}), \
mock.patch.object(metric_utils, 'get_config_file', mock.patch.object(metric_utils, 'get_config_file',
return_value=None), \ return_value=None), \
mock.patch.object(adapter.Adapter, 'get_endpoint_data', mock.patch.object(adapter.Adapter, 'get_endpoint',
return_value=self.prom_endpoint_data), \ return_value=prom_endpoint), \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,
"__init__", return_value=None) as init_m, \ "__init__", return_value=None) as init_m, \
mock.patch.object(prometheus_client.PrometheusAPIClient, mock.patch.object(prometheus_client.PrometheusAPIClient,

View File

@@ -73,10 +73,9 @@ def get_prometheus_client(session=None, adapter_options={}):
try: try:
endpoint = adapter.Adapter( endpoint = adapter.Adapter(
session=session, **adapter_options session=session, **adapter_options
).get_endpoint_data() ).get_endpoint()
parsed_url = parse.urlparse(endpoint.catalog_url) parsed_url = parse.urlparse(endpoint)
host = parsed_url.hostname host = parsed_url.hostname
port = parsed_url.port if parsed_url.port is not None else 80
root_path = parsed_url.path.strip('/') root_path = parsed_url.path.strip('/')
if parsed_url.scheme == "https" and ca_cert is None: if parsed_url.scheme == "https" and ca_cert is None:
# NOTE(jwysogla): Use the default CA certs if the scheme # NOTE(jwysogla): Use the default CA certs if the scheme
@@ -84,10 +83,12 @@ def get_prometheus_client(session=None, adapter_options={}):
# so that a custom certificate can be set in the config # so that a custom certificate can be set in the config
# file, while the endpoint is retrieved from keystone. # file, while the endpoint is retrieved from keystone.
ca_cert = True ca_cert = True
if (endpoint.service_type == "prometheus" and if parsed_url.port is not None:
endpoint.service_name == "aetos"): port = parsed_url.port
# We know this is Aetos and we can include keystone tokens elif parsed_url.scheme == "https":
# when sending requests to it. port = 443
else:
port = 80
is_aetos = True is_aetos = True
except keystone_exception.EndpointNotFound: except keystone_exception.EndpointNotFound:
# NOTE(jwysogla): Don't do anything here. It's still possible # NOTE(jwysogla): Don't do anything here. It's still possible
@@ -108,8 +109,8 @@ def get_prometheus_client(session=None, adapter_options={}):
root_path = os.environ['PROMETHEUS_ROOT_PATH'] root_path = os.environ['PROMETHEUS_ROOT_PATH']
if host is None or port is None: if host is None or port is None:
raise ConfigurationError("Can't find prometheus host and " raise ConfigurationError("Can't find prometheus host and "
"port configuration and endpoint for service" "port configuration and endpoint for "
"prometheus not found.") "metric-storage not found.")
escaped_host = netutils.escape_ipv6(host) escaped_host = netutils.escape_ipv6(host)
if is_aetos: if is_aetos:
client = PrometheusAPIClient( client = PrometheusAPIClient(

View File

@@ -28,7 +28,7 @@ class Client(object):
session_options = session_options or {} session_options = session_options or {}
adapter_options = adapter_options or {} adapter_options = adapter_options or {}
adapter_options.setdefault('service_type', "prometheus") adapter_options.setdefault('service_type', "metric-storage")
if session is None: if session is None:
session = keystoneauth1.session.Session(**session_options) session = keystoneauth1.session.Session(**session_options)

View File

@@ -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'.