python-observabilityclient 1.0.0__tar.gz → 1.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/.zuul.yaml +0 -1
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/AUTHORS +1 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/ChangeLog +22 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/PKG-INFO +4 -5
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/README.md +1 -1
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/prometheus_client.py +1 -2
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/rbac.py +33 -6
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/functional/base.py +3 -3
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/unit/test_rbac.py +78 -9
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/unit/test_utils.py +36 -11
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/utils/metric_utils.py +65 -33
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/v1/client.py +1 -1
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/python_observabilityclient.egg-info/PKG-INFO +4 -5
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/python_observabilityclient.egg-info/SOURCES.txt +7 -0
- python_observabilityclient-1.2.0/python_observabilityclient.egg-info/pbr.json +1 -0
- python_observabilityclient-1.2.0/releasenotes/notes/allow-for-providing-metric-names-list-for-rbac-e46a4fd0df3fad73.yaml +10 -0
- python_observabilityclient-1.2.0/releasenotes/notes/allow-for-specifying-rbac-label-name-f99084757cde5f19.yaml +6 -0
- python_observabilityclient-1.2.0/releasenotes/notes/change-aetos-service-type-37a53a86f4975803.yaml +6 -0
- python_observabilityclient-1.2.0/releasenotes/notes/disable-config-overrides-for-keystone-discovered-endpoints-0b36ad382f029fa0.yaml +7 -0
- python_observabilityclient-1.2.0/releasenotes/notes/fix-ipv6-escaping-faef776565954baa.yaml +4 -0
- python_observabilityclient-1.2.0/releasenotes/notes/remove-py39-a3f911847e0075b6.yaml +5 -0
- python_observabilityclient-1.2.0/releasenotes/notes/send-token-only-when-communicating-with-aetos-21299ccc710f6473.yaml +9 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/setup.cfg +2 -3
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/test-requirements.txt +1 -1
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/tox.ini +1 -1
- python_observabilityclient-1.0.0/python_observabilityclient.egg-info/pbr.json +0 -1
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/.coveragerc +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/LICENSE +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/doc/requirements.txt +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/__init__.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/client.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/i18n.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/plugin.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/functional/__init__.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/functional/test_cli.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/functional/test_python_api.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/unit/__init__.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/unit/test_cli.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/unit/test_prometheus_client.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/tests/unit/test_python_api.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/utils/__init__.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/v1/__init__.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/v1/base.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/v1/cli.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/v1/python_api.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/pyproject.toml +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/python_observabilityclient.egg-info/dependency_links.txt +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/python_observabilityclient.egg-info/entry_points.txt +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/python_observabilityclient.egg-info/not-zip-safe +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/python_observabilityclient.egg-info/requires.txt +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/python_observabilityclient.egg-info/top_level.txt +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/notes/add-root-path-192ac0e6ea99b84f.yaml +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/notes/refactor-rbac-967ed5edcc1ef2a4.yaml +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/notes/remove-py38-acd461c4350f0dca.yaml +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/2025.1.rst +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/_static/.placeholder +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/conf.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/index.rst +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/unreleased.rst +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/requirements.txt +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/setup.py +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/tools/fix_ca_bundle.sh +0 -0
- {python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/tools/install_deps.sh +0 -0
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
CHANGES
|
|
2
2
|
=======
|
|
3
3
|
|
|
4
|
+
1.2.0
|
|
5
|
+
-----
|
|
6
|
+
|
|
7
|
+
* Fix PrometheusAPIClient set\_client\_cert
|
|
8
|
+
|
|
9
|
+
1.1.0
|
|
10
|
+
-----
|
|
11
|
+
|
|
12
|
+
* Split get\_prometheus\_client to multiple functions
|
|
13
|
+
* Rename Aetos's service type to metric-storage
|
|
14
|
+
* Allow for providing metric names to modify\_query
|
|
15
|
+
* Allow for specifying rbac label name
|
|
16
|
+
* Fix inconsistent indentation
|
|
17
|
+
* Send keystone tokens to Aetos only
|
|
18
|
+
* Replace os-client-config
|
|
19
|
+
* Remove Python 3.9 support
|
|
20
|
+
* Fix IPv6 host IP escaping
|
|
21
|
+
* Zuul: do not use USE\_PYTHON3
|
|
22
|
+
* Add a testcase for specifying project label
|
|
23
|
+
* Change URLs to point to the correct repository
|
|
24
|
+
|
|
4
25
|
1.0.0
|
|
5
26
|
-----
|
|
6
27
|
|
|
@@ -22,6 +43,7 @@ CHANGES
|
|
|
22
43
|
* Check if the HOME env var is set, otherwise use a default
|
|
23
44
|
* Update master for stable/2025.1
|
|
24
45
|
* Ignore false-positive E231 error
|
|
46
|
+
* Update default envlist
|
|
25
47
|
|
|
26
48
|
0.4.0
|
|
27
49
|
-----
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-observabilityclient
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: OpenStack Observability Client
|
|
5
|
-
Home-page: https://
|
|
5
|
+
Home-page: https://opendev.org/openstack/python-observabilityclient
|
|
6
6
|
Author: OpenStack
|
|
7
7
|
Author-email: openstack-discuss@lists.openstack.org
|
|
8
8
|
License: Apache License, Version 2.0
|
|
@@ -17,11 +17,10 @@ Classifier: Programming Language :: Python
|
|
|
17
17
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
18
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
19
|
Classifier: Programming Language :: Python :: 3
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.10
|
|
25
24
|
Description-Content-Type: text/markdown; charset=UTF-8
|
|
26
25
|
License-File: LICENSE
|
|
27
26
|
Requires-Dist: osc-lib>=1.0.1
|
|
@@ -44,7 +43,7 @@ Install your OpenStack environment and patch your `openstack` client application
|
|
|
44
43
|
su - stack
|
|
45
44
|
|
|
46
45
|
# clone and install observability client plugin
|
|
47
|
-
git clone https://
|
|
46
|
+
git clone https://opendev.org/openstack/python-observabilityclient.git
|
|
48
47
|
cd python-observabilityclient
|
|
49
48
|
sudo python setup.py install --prefix=/usr
|
|
50
49
|
```
|
|
@@ -13,7 +13,7 @@ Install your OpenStack environment and patch your `openstack` client application
|
|
|
13
13
|
su - stack
|
|
14
14
|
|
|
15
15
|
# clone and install observability client plugin
|
|
16
|
-
git clone https://
|
|
16
|
+
git clone https://opendev.org/openstack/python-observabilityclient.git
|
|
17
17
|
cd python-observabilityclient
|
|
18
18
|
sudo python setup.py install --prefix=/usr
|
|
19
19
|
```
|
|
@@ -70,8 +70,7 @@ class PrometheusAPIClient(object):
|
|
|
70
70
|
self._session.verify = ca_cert
|
|
71
71
|
|
|
72
72
|
def set_client_cert(self, client_cert, client_key):
|
|
73
|
-
self._session.cert = client_cert
|
|
74
|
-
self._session.key = client_key
|
|
73
|
+
self._session.cert = (client_cert, client_key)
|
|
75
74
|
|
|
76
75
|
def set_basic_auth(self, auth_user, auth_password):
|
|
77
76
|
self._session.auth = (auth_user, auth_password)
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/rbac.py
RENAMED
|
@@ -18,10 +18,24 @@ from observabilityclient.utils.metric_utils import format_labels
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
class PromQLRbac(object):
|
|
21
|
-
def __init__(self, prom_api_client, project_id):
|
|
21
|
+
def __init__(self, prom_api_client, project_id, project_label='project'):
|
|
22
22
|
self.client = prom_api_client
|
|
23
|
+
|
|
24
|
+
# NOTE(jwysogla): Since Prometheus 3, metric and label names can
|
|
25
|
+
# utilize all unicode characters. But the syntax is a little different
|
|
26
|
+
# and some parts of the queries need to be quoted or escaped. The
|
|
27
|
+
# rest of this module doesn't support that right now, so use a
|
|
28
|
+
# Prometheus 2 regex and raise an exception when it doesn't match.
|
|
29
|
+
# See https://prometheus.io/docs/concepts/data_model/
|
|
30
|
+
label_name_regex = "[a-zA-Z_][a-zA-Z0-9_]*"
|
|
31
|
+
if not re.fullmatch(label_name_regex, project_label):
|
|
32
|
+
raise ValueError(
|
|
33
|
+
f"Project label {project_label} doesn't match the "
|
|
34
|
+
f"label name regex: {label_name_regex}"
|
|
35
|
+
)
|
|
36
|
+
|
|
23
37
|
self.labels = {
|
|
24
|
-
|
|
38
|
+
project_label: project_id
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
def _find_label_value_end(self, query, start, quote_char):
|
|
@@ -83,14 +97,27 @@ class PromQLRbac(object):
|
|
|
83
97
|
f"{labels_str}"
|
|
84
98
|
f"{query[location:]}")
|
|
85
99
|
|
|
86
|
-
def modify_query(self, query):
|
|
100
|
+
def modify_query(self, query, metric_names=None):
|
|
87
101
|
"""Add rbac labels to a query.
|
|
88
102
|
|
|
89
103
|
:param query: The query to modify
|
|
90
104
|
:type query: str
|
|
105
|
+
|
|
106
|
+
:param metric_names: List of metric names currently stored in
|
|
107
|
+
prometheus. For correct function of the query
|
|
108
|
+
modification, it's important for the list to be
|
|
109
|
+
accurate and to include all metrics across all
|
|
110
|
+
tenants. This parameter can be unspecified or
|
|
111
|
+
None, in which case the list will be retrieved
|
|
112
|
+
from Prometheus by sending an API request to it.
|
|
113
|
+
It's advised to provide the metric list when
|
|
114
|
+
doing a query modification in a loop for
|
|
115
|
+
performance purposes.
|
|
116
|
+
:type metric_names: list
|
|
91
117
|
"""
|
|
92
|
-
|
|
93
|
-
metric_names
|
|
118
|
+
|
|
119
|
+
if metric_names is None:
|
|
120
|
+
metric_names = self.client.label_values("__name__")
|
|
94
121
|
|
|
95
122
|
# We need to detect the locations of metric names
|
|
96
123
|
# inside the query
|
|
@@ -111,7 +138,7 @@ class PromQLRbac(object):
|
|
|
111
138
|
name_end_locations = [0]
|
|
112
139
|
for name_end_location in name_end_locations:
|
|
113
140
|
if (name_end_location < len(query) and
|
|
114
|
-
|
|
141
|
+
query[name_end_location] == "{"):
|
|
115
142
|
# There is already a label section
|
|
116
143
|
labels_end = self._find_label_section_end(
|
|
117
144
|
query,
|
|
@@ -22,7 +22,7 @@ from observabilityclient import client
|
|
|
22
22
|
|
|
23
23
|
from keystoneauth1 import loading
|
|
24
24
|
from keystoneauth1 import session
|
|
25
|
-
import
|
|
25
|
+
from openstack import config as occ
|
|
26
26
|
from tempest.lib.cli import output_parser
|
|
27
27
|
from tempest.lib import exceptions
|
|
28
28
|
import testtools
|
|
@@ -33,8 +33,8 @@ LOG = logging.getLogger(__name__)
|
|
|
33
33
|
|
|
34
34
|
class PythonAPITestCase(testtools.TestCase):
|
|
35
35
|
def _getKeystoneSession(self):
|
|
36
|
-
conf =
|
|
37
|
-
creds = conf.
|
|
36
|
+
conf = occ.OpenStackConfig()
|
|
37
|
+
creds = conf.get_one(cloud=ADMIN_CLOUD).get_auth_args()
|
|
38
38
|
ks_creds = dict(
|
|
39
39
|
auth_url=creds["auth_url"],
|
|
40
40
|
username=creds["username"],
|
|
@@ -27,15 +27,17 @@ class PromQLRbacTest(testtools.TestCase):
|
|
|
27
27
|
self.rbac.labels = {
|
|
28
28
|
"project": "project123"
|
|
29
29
|
}
|
|
30
|
-
self.rbac.client.label_values =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
self.rbac.client.label_values = mock.MagicMock(
|
|
31
|
+
return_value=[
|
|
32
|
+
'test_query',
|
|
33
|
+
'cpu_temp_celsius',
|
|
34
|
+
'http_requests',
|
|
35
|
+
'test:query:with:colon:',
|
|
36
|
+
'test_query_with_digit1',
|
|
37
|
+
'method_code:http_errors:rate5m',
|
|
38
|
+
'method:http_requests:rate5m'
|
|
39
|
+
]
|
|
40
|
+
)
|
|
39
41
|
self.test_cases = [
|
|
40
42
|
(
|
|
41
43
|
"test_query",
|
|
@@ -167,6 +169,12 @@ class PromQLRbacTest(testtools.TestCase):
|
|
|
167
169
|
f"{{project='{self.project_id}'}}"
|
|
168
170
|
f"[10m])))"
|
|
169
171
|
)
|
|
172
|
+
), (
|
|
173
|
+
"test_query{project='some_id'}",
|
|
174
|
+
|
|
175
|
+
(f"test_query{{project='some_id', "
|
|
176
|
+
f"project='{self.project_id}'}}"
|
|
177
|
+
)
|
|
170
178
|
)
|
|
171
179
|
]
|
|
172
180
|
|
|
@@ -186,3 +194,64 @@ class PromQLRbacTest(testtools.TestCase):
|
|
|
186
194
|
expected = f"{query}{{project='{self.project_id}'}}"
|
|
187
195
|
ret = self.rbac.append_rbac_labels(query)
|
|
188
196
|
self.assertEqual(expected, ret)
|
|
197
|
+
|
|
198
|
+
def test_setting_different_project_label_name(self):
|
|
199
|
+
query = 'test_query'
|
|
200
|
+
project_label = 'different_name'
|
|
201
|
+
project_value = 'some_project'
|
|
202
|
+
|
|
203
|
+
rbac_instance = rbac.PromQLRbac(
|
|
204
|
+
mock.Mock(), project_value, project_label=project_label
|
|
205
|
+
)
|
|
206
|
+
rbac_instance.client.label_values = lambda label: [
|
|
207
|
+
query,
|
|
208
|
+
]
|
|
209
|
+
|
|
210
|
+
expected = f"{query}{{{project_label}='{project_value}'}}"
|
|
211
|
+
|
|
212
|
+
ret = rbac_instance.modify_query(query)
|
|
213
|
+
|
|
214
|
+
self.assertEqual(expected, ret)
|
|
215
|
+
|
|
216
|
+
def test_setting_illegal_project_label_name(self):
|
|
217
|
+
# Try setting a label name with a white space character inside
|
|
218
|
+
project_label = 'different name'
|
|
219
|
+
project_value = 'some_project'
|
|
220
|
+
|
|
221
|
+
args = (mock.Mock(), project_value)
|
|
222
|
+
kwargs = {'project_label': project_label}
|
|
223
|
+
|
|
224
|
+
self.assertRaises(ValueError, rbac.PromQLRbac, *args, **kwargs)
|
|
225
|
+
|
|
226
|
+
# Try setting an empty label name
|
|
227
|
+
project_label = ''
|
|
228
|
+
|
|
229
|
+
kwargs = {'project_label': project_label}
|
|
230
|
+
|
|
231
|
+
self.assertRaises(ValueError, rbac.PromQLRbac, *args, **kwargs)
|
|
232
|
+
|
|
233
|
+
def test_specifying_metric_names(self):
|
|
234
|
+
query = "test_query"
|
|
235
|
+
metric_names = [
|
|
236
|
+
"metric_name1",
|
|
237
|
+
"foo",
|
|
238
|
+
"bar",
|
|
239
|
+
"test_query"
|
|
240
|
+
]
|
|
241
|
+
|
|
242
|
+
expected = "test_query{project='project123'}"
|
|
243
|
+
|
|
244
|
+
ret = self.rbac.modify_query(query, metric_names)
|
|
245
|
+
|
|
246
|
+
self.assertEqual(expected, ret)
|
|
247
|
+
self.rbac.client.label_values.assert_not_called()
|
|
248
|
+
|
|
249
|
+
def test_not_specifying_metric_names(self):
|
|
250
|
+
query = "test_query"
|
|
251
|
+
|
|
252
|
+
expected = "test_query{project='project123'}"
|
|
253
|
+
|
|
254
|
+
ret = self.rbac.modify_query(query)
|
|
255
|
+
|
|
256
|
+
self.assertEqual(expected, ret)
|
|
257
|
+
self.rbac.client.label_values.assert_called_once()
|
|
@@ -102,13 +102,13 @@ class GetPrometheusClientTest(testtools.TestCase):
|
|
|
102
102
|
metric_utils.get_prometheus_client)
|
|
103
103
|
|
|
104
104
|
def test_get_prometheus_client_from_keystone_http(self):
|
|
105
|
-
|
|
105
|
+
prom_endpoint = "http://localhost:1234/prometheus"
|
|
106
106
|
keystone_session = session.Session()
|
|
107
107
|
with mock.patch.dict(os.environ, {}), \
|
|
108
108
|
mock.patch.object(metric_utils, 'get_config_file',
|
|
109
109
|
return_value=None), \
|
|
110
110
|
mock.patch.object(adapter.Adapter, 'get_endpoint',
|
|
111
|
-
return_value=
|
|
111
|
+
return_value=prom_endpoint), \
|
|
112
112
|
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
113
113
|
"__init__", return_value=None) as init_m, \
|
|
114
114
|
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
@@ -120,13 +120,13 @@ class GetPrometheusClientTest(testtools.TestCase):
|
|
|
120
120
|
ca_m.assert_not_called()
|
|
121
121
|
|
|
122
122
|
def test_get_prometheus_client_from_keystone_https(self):
|
|
123
|
-
|
|
123
|
+
prom_endpoint = "https://localhost:1234/prometheus"
|
|
124
124
|
keystone_session = session.Session()
|
|
125
125
|
with mock.patch.dict(os.environ, {}), \
|
|
126
126
|
mock.patch.object(metric_utils, 'get_config_file',
|
|
127
127
|
return_value=None), \
|
|
128
128
|
mock.patch.object(adapter.Adapter, 'get_endpoint',
|
|
129
|
-
return_value=
|
|
129
|
+
return_value=prom_endpoint), \
|
|
130
130
|
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
131
131
|
"__init__", return_value=None) as init_m, \
|
|
132
132
|
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
@@ -137,25 +137,50 @@ class GetPrometheusClientTest(testtools.TestCase):
|
|
|
137
137
|
)
|
|
138
138
|
ca_m.assert_called_with(True)
|
|
139
139
|
|
|
140
|
-
def
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
def test_get_prometheus_client_from_env_vars_ipv6(self):
|
|
141
|
+
patched_env = {'PROMETHEUS_HOST': '2607:5300:201:2000::654',
|
|
142
|
+
'PROMETHEUS_PORT': '1234'}
|
|
143
|
+
with mock.patch.dict(os.environ, patched_env), \
|
|
144
|
+
mock.patch.object(metric_utils, 'get_config_file',
|
|
145
|
+
return_value=None), \
|
|
146
|
+
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
147
|
+
"__init__", return_value=None) as m:
|
|
148
|
+
metric_utils.get_prometheus_client()
|
|
149
|
+
m.assert_called_with("[2607:5300:201:2000::654]:1234", None, "")
|
|
150
|
+
|
|
151
|
+
def test_get_prometheus_client_from_conf_file_ipv6(self):
|
|
152
|
+
config_data = '''
|
|
153
|
+
host: "2607:5300:201:2000::654"
|
|
154
|
+
port: "80"
|
|
155
|
+
'''
|
|
144
156
|
config_file = mock.mock_open(read_data=config_data)("name", 'r')
|
|
145
157
|
with mock.patch.dict(os.environ, {}), \
|
|
146
158
|
mock.patch.object(metric_utils, 'get_config_file',
|
|
147
159
|
return_value=config_file), \
|
|
160
|
+
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
161
|
+
"__init__", return_value=None) as init_m:
|
|
162
|
+
metric_utils.get_prometheus_client()
|
|
163
|
+
init_m.assert_called_with(
|
|
164
|
+
"[2607:5300:201:2000::654]:80", None, ""
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
def test_get_prometheus_client_from_keystone_ipv6(self):
|
|
168
|
+
prom_endpoint = "http://[2607:5300:201:2000::654]:80/prometheus"
|
|
169
|
+
keystone_session = session.Session()
|
|
170
|
+
with mock.patch.dict(os.environ, {}), \
|
|
171
|
+
mock.patch.object(metric_utils, 'get_config_file',
|
|
172
|
+
return_value=None), \
|
|
148
173
|
mock.patch.object(adapter.Adapter, 'get_endpoint',
|
|
149
|
-
return_value=
|
|
174
|
+
return_value=prom_endpoint), \
|
|
150
175
|
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
151
176
|
"__init__", return_value=None) as init_m, \
|
|
152
177
|
mock.patch.object(prometheus_client.PrometheusAPIClient,
|
|
153
178
|
"set_ca_cert") as ca_m:
|
|
154
179
|
metric_utils.get_prometheus_client(keystone_session)
|
|
155
180
|
init_m.assert_called_with(
|
|
156
|
-
"
|
|
181
|
+
"[2607:5300:201:2000::654]:80", keystone_session, "prometheus"
|
|
157
182
|
)
|
|
158
|
-
ca_m.
|
|
183
|
+
ca_m.assert_not_called()
|
|
159
184
|
|
|
160
185
|
|
|
161
186
|
class FormatLabelsTest(testtools.TestCase):
|
|
@@ -18,6 +18,7 @@ from urllib import parse
|
|
|
18
18
|
|
|
19
19
|
from keystoneauth1 import adapter
|
|
20
20
|
from keystoneauth1.exceptions import catalog as keystone_exception
|
|
21
|
+
from oslo_utils import netutils
|
|
21
22
|
import yaml
|
|
22
23
|
|
|
23
24
|
from observabilityclient.prometheus_client import PrometheusAPIClient
|
|
@@ -48,11 +49,33 @@ def get_config_file():
|
|
|
48
49
|
return None
|
|
49
50
|
|
|
50
51
|
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
def get_prom_client_from_keystone(session, adapter_options=None):
|
|
53
|
+
if adapter_options is None:
|
|
54
|
+
adapter_options = {}
|
|
55
|
+
endpoint = adapter.Adapter(
|
|
56
|
+
session=session, **adapter_options
|
|
57
|
+
).get_endpoint()
|
|
58
|
+
parsed_url = parse.urlparse(endpoint)
|
|
59
|
+
|
|
60
|
+
escaped_host = netutils.escape_ipv6(parsed_url.hostname)
|
|
61
|
+
root_path = parsed_url.path.strip('/')
|
|
62
|
+
tls = parsed_url.scheme == "https"
|
|
63
|
+
|
|
64
|
+
if parsed_url.port is not None:
|
|
65
|
+
url = f'{escaped_host}:{parsed_url.port}'
|
|
66
|
+
else:
|
|
67
|
+
url = escaped_host
|
|
68
|
+
|
|
69
|
+
client = PrometheusAPIClient(url, session, root_path)
|
|
70
|
+
|
|
71
|
+
if tls:
|
|
72
|
+
client.set_ca_cert(True)
|
|
73
|
+
return client
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_prom_client_from_file_or_env():
|
|
77
|
+
host = port = ca_cert = None
|
|
78
|
+
root_path = ''
|
|
56
79
|
conf_file = get_config_file()
|
|
57
80
|
if conf_file is not None:
|
|
58
81
|
conf = yaml.safe_load(conf_file)
|
|
@@ -65,31 +88,6 @@ def get_prometheus_client(session=None, adapter_options={}):
|
|
|
65
88
|
if 'root_path' in conf:
|
|
66
89
|
root_path = conf['root_path']
|
|
67
90
|
conf_file.close()
|
|
68
|
-
|
|
69
|
-
if session is not None and (host is None or port is None):
|
|
70
|
-
try:
|
|
71
|
-
endpoint = adapter.Adapter(
|
|
72
|
-
session=session, **adapter_options
|
|
73
|
-
).get_endpoint()
|
|
74
|
-
parsed_url = parse.urlparse(endpoint)
|
|
75
|
-
host = parsed_url.hostname
|
|
76
|
-
port = parsed_url.port if parsed_url.port is not None else 80
|
|
77
|
-
root_path = parsed_url.path.strip('/')
|
|
78
|
-
if parsed_url.scheme == "https" and ca_cert is None:
|
|
79
|
-
# NOTE(jwysogla): Use the default CA certs if the scheme
|
|
80
|
-
# is https, but keep the original value if already set,
|
|
81
|
-
# so that a custom certificate can be set in the config
|
|
82
|
-
# file, while the endpoint is retrieved from keystone.
|
|
83
|
-
ca_cert = True
|
|
84
|
-
except keystone_exception.EndpointNotFound:
|
|
85
|
-
# NOTE(jwysogla): Don't do anything here. It's still possible
|
|
86
|
-
# to get the correct endpoint configuration from the env vars.
|
|
87
|
-
# If that doesn't work, the same error message is part of the
|
|
88
|
-
# exception raised below.
|
|
89
|
-
pass
|
|
90
|
-
|
|
91
|
-
# NOTE(jwysogla): We allow to overide the prometheus.yaml by
|
|
92
|
-
# the environment variables
|
|
93
91
|
if 'PROMETHEUS_HOST' in os.environ:
|
|
94
92
|
host = os.environ['PROMETHEUS_HOST']
|
|
95
93
|
if 'PROMETHEUS_PORT' in os.environ:
|
|
@@ -100,14 +98,48 @@ def get_prometheus_client(session=None, adapter_options={}):
|
|
|
100
98
|
root_path = os.environ['PROMETHEUS_ROOT_PATH']
|
|
101
99
|
if host is None or port is None:
|
|
102
100
|
raise ConfigurationError("Can't find prometheus host and "
|
|
103
|
-
"port configuration
|
|
104
|
-
"
|
|
105
|
-
|
|
101
|
+
"port configuration in config file or "
|
|
102
|
+
"environment variables.")
|
|
103
|
+
escaped_host = netutils.escape_ipv6(host)
|
|
104
|
+
client = PrometheusAPIClient(
|
|
105
|
+
f"{escaped_host}:{port}", None, root_path
|
|
106
|
+
)
|
|
106
107
|
if ca_cert is not None:
|
|
107
108
|
client.set_ca_cert(ca_cert)
|
|
108
109
|
return client
|
|
109
110
|
|
|
110
111
|
|
|
112
|
+
def get_prometheus_client(session=None, adapter_options=None):
|
|
113
|
+
if adapter_options is None:
|
|
114
|
+
adapter_options = {}
|
|
115
|
+
|
|
116
|
+
keystone_error = None
|
|
117
|
+
if session is not None:
|
|
118
|
+
try:
|
|
119
|
+
return get_prom_client_from_keystone(session, adapter_options)
|
|
120
|
+
except keystone_exception.EndpointNotFound as e:
|
|
121
|
+
# NOTE(jwysogla): Fallback to get the endpoint configuration from
|
|
122
|
+
# the config file and env vars. If that doesn't work, the error
|
|
123
|
+
# message is raised as ConfigurationError later.
|
|
124
|
+
keystone_error = e
|
|
125
|
+
LOG.debug("Aetos endpoint discovery from Keystone failed: %s", e)
|
|
126
|
+
|
|
127
|
+
# NOTE(jwysogla): Always fallback to the original method of discovery
|
|
128
|
+
# through config file and env variables for backwards compatibility.
|
|
129
|
+
try:
|
|
130
|
+
return get_prom_client_from_file_or_env()
|
|
131
|
+
except ConfigurationError as e:
|
|
132
|
+
if keystone_error is not None:
|
|
133
|
+
raise ConfigurationError(
|
|
134
|
+
f"Failed to configure Prometheus client. "
|
|
135
|
+
f"Aetos discovery from keystone failed: '{keystone_error}'. "
|
|
136
|
+
f"Prometheus configuration from config file and environment "
|
|
137
|
+
f"variables failed: '{e}'"
|
|
138
|
+
)
|
|
139
|
+
else:
|
|
140
|
+
raise e
|
|
141
|
+
|
|
142
|
+
|
|
111
143
|
def get_client(obj):
|
|
112
144
|
return obj.app.client_manager.observabilityclient
|
|
113
145
|
|
|
@@ -28,7 +28,7 @@ class Client(object):
|
|
|
28
28
|
session_options = session_options or {}
|
|
29
29
|
adapter_options = adapter_options or {}
|
|
30
30
|
|
|
31
|
-
adapter_options.setdefault('service_type', "
|
|
31
|
+
adapter_options.setdefault('service_type', "metric-storage")
|
|
32
32
|
|
|
33
33
|
if session is None:
|
|
34
34
|
session = keystoneauth1.session.Session(**session_options)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-observabilityclient
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: OpenStack Observability Client
|
|
5
|
-
Home-page: https://
|
|
5
|
+
Home-page: https://opendev.org/openstack/python-observabilityclient
|
|
6
6
|
Author: OpenStack
|
|
7
7
|
Author-email: openstack-discuss@lists.openstack.org
|
|
8
8
|
License: Apache License, Version 2.0
|
|
@@ -17,11 +17,10 @@ Classifier: Programming Language :: Python
|
|
|
17
17
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
18
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
19
|
Classifier: Programming Language :: Python :: 3
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
21
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
-
Requires-Python: >=3.
|
|
23
|
+
Requires-Python: >=3.10
|
|
25
24
|
Description-Content-Type: text/markdown; charset=UTF-8
|
|
26
25
|
License-File: LICENSE
|
|
27
26
|
Requires-Dist: osc-lib>=1.0.1
|
|
@@ -44,7 +43,7 @@ Install your OpenStack environment and patch your `openstack` client application
|
|
|
44
43
|
su - stack
|
|
45
44
|
|
|
46
45
|
# clone and install observability client plugin
|
|
47
|
-
git clone https://
|
|
46
|
+
git clone https://opendev.org/openstack/python-observabilityclient.git
|
|
48
47
|
cd python-observabilityclient
|
|
49
48
|
sudo python setup.py install --prefix=/usr
|
|
50
49
|
```
|
|
@@ -43,8 +43,15 @@ python_observabilityclient.egg-info/pbr.json
|
|
|
43
43
|
python_observabilityclient.egg-info/requires.txt
|
|
44
44
|
python_observabilityclient.egg-info/top_level.txt
|
|
45
45
|
releasenotes/notes/add-root-path-192ac0e6ea99b84f.yaml
|
|
46
|
+
releasenotes/notes/allow-for-providing-metric-names-list-for-rbac-e46a4fd0df3fad73.yaml
|
|
47
|
+
releasenotes/notes/allow-for-specifying-rbac-label-name-f99084757cde5f19.yaml
|
|
48
|
+
releasenotes/notes/change-aetos-service-type-37a53a86f4975803.yaml
|
|
49
|
+
releasenotes/notes/disable-config-overrides-for-keystone-discovered-endpoints-0b36ad382f029fa0.yaml
|
|
50
|
+
releasenotes/notes/fix-ipv6-escaping-faef776565954baa.yaml
|
|
46
51
|
releasenotes/notes/refactor-rbac-967ed5edcc1ef2a4.yaml
|
|
47
52
|
releasenotes/notes/remove-py38-acd461c4350f0dca.yaml
|
|
53
|
+
releasenotes/notes/remove-py39-a3f911847e0075b6.yaml
|
|
54
|
+
releasenotes/notes/send-token-only-when-communicating-with-aetos-21299ccc710f6473.yaml
|
|
48
55
|
releasenotes/source/2025.1.rst
|
|
49
56
|
releasenotes/source/conf.py
|
|
50
57
|
releasenotes/source/index.rst
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"git_version": "bcadbfe", "is_release": true}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
features:
|
|
3
|
+
- |
|
|
4
|
+
The rbac.PromQLRbac.modify_query method now optionally allows
|
|
5
|
+
for providing a list of metric names thanks to a new parameter.
|
|
6
|
+
When the new parameter isn't used, the old behavior with sending
|
|
7
|
+
a Prometheus API request to retrieve the metric names is used.
|
|
8
|
+
When the metric names are provided, no Prometheus API request is
|
|
9
|
+
done, which greatly increases performance when using the
|
|
10
|
+
modify_query repeatedly, for example in loops.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
security:
|
|
3
|
+
- |
|
|
4
|
+
Modified the observabilityclient to send keystone token with each request
|
|
5
|
+
only when communicating with Aetos, instead of sending it everytime, which
|
|
6
|
+
could pose a security risk. This also restricts configuration
|
|
7
|
+
options for connecting to Aetos to keystone endpoints only. Configuration
|
|
8
|
+
for Prometheus is unchanged and can still be done through keystone
|
|
9
|
+
endpoint, through a configuration file or through environment variables.
|
|
@@ -6,8 +6,8 @@ long_description_content_type = text/markdown; charset=UTF-8
|
|
|
6
6
|
license = Apache License, Version 2.0
|
|
7
7
|
author = OpenStack
|
|
8
8
|
author_email = openstack-discuss@lists.openstack.org
|
|
9
|
-
home_page = https://
|
|
10
|
-
python_requires = >=3.
|
|
9
|
+
home_page = https://opendev.org/openstack/python-observabilityclient
|
|
10
|
+
python_requires = >=3.10
|
|
11
11
|
classifier =
|
|
12
12
|
Environment :: Console
|
|
13
13
|
Environment :: OpenStack
|
|
@@ -20,7 +20,6 @@ classifier =
|
|
|
20
20
|
Programming Language :: Python :: Implementation :: CPython
|
|
21
21
|
Programming Language :: Python :: 3 :: Only
|
|
22
22
|
Programming Language :: Python :: 3
|
|
23
|
-
Programming Language :: Python :: 3.9
|
|
24
23
|
Programming Language :: Python :: 3.10
|
|
25
24
|
Programming Language :: Python :: 3.11
|
|
26
25
|
Programming Language :: Python :: 3.12
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"git_version": "21e4885", "is_release": true}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/client.py
RENAMED
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/i18n.py
RENAMED
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/plugin.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/v1/base.py
RENAMED
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/observabilityclient/v1/cli.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/2025.1.rst
RENAMED
|
File without changes
|
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/conf.py
RENAMED
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/releasenotes/source/index.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_observabilityclient-1.0.0 → python_observabilityclient-1.2.0}/tools/fix_ca_bundle.sh
RENAMED
|
File without changes
|
|
File without changes
|