python-observabilityclient 0.1.1__tar.gz → 0.3.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.
Files changed (47) hide show
  1. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/AUTHORS +1 -0
  2. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/ChangeLog +16 -0
  3. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/PKG-INFO +2 -1
  4. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/prometheus_client.py +10 -12
  5. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/unit/test_utils.py +67 -0
  6. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/utils/metric_utils.py +16 -11
  7. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/v1/base.py +0 -11
  8. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/python_observabilityclient.egg-info/PKG-INFO +2 -1
  9. python-observabilityclient-0.3.0/python_observabilityclient.egg-info/pbr.json +1 -0
  10. python-observabilityclient-0.3.0/python_observabilityclient.egg-info/requires.txt +10 -0
  11. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/setup.cfg +2 -7
  12. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/tox.ini +2 -3
  13. python-observabilityclient-0.1.1/python_observabilityclient.egg-info/pbr.json +0 -1
  14. python-observabilityclient-0.1.1/python_observabilityclient.egg-info/requires.txt +0 -14
  15. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/.zuul.yaml +0 -0
  16. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/LICENSE +0 -0
  17. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/README.md +0 -0
  18. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/__init__.py +0 -0
  19. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/client.py +0 -0
  20. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/i18n.py +0 -0
  21. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/plugin.py +0 -0
  22. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/functional/__init__.py +0 -0
  23. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/functional/base.py +0 -0
  24. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/functional/test_cli.py +0 -0
  25. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/functional/test_python_api.py +0 -0
  26. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/unit/__init__.py +0 -0
  27. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/unit/test_cli.py +0 -0
  28. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/unit/test_prometheus_client.py +0 -0
  29. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/unit/test_python_api.py +0 -0
  30. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/tests/unit/test_rbac.py +0 -0
  31. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/utils/__init__.py +0 -0
  32. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/v1/__init__.py +0 -0
  33. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/v1/cli.py +0 -0
  34. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/v1/client.py +0 -0
  35. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/v1/python_api.py +0 -0
  36. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/observabilityclient/v1/rbac.py +0 -0
  37. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/pyproject.toml +0 -0
  38. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/python_observabilityclient.egg-info/SOURCES.txt +0 -0
  39. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/python_observabilityclient.egg-info/dependency_links.txt +0 -0
  40. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/python_observabilityclient.egg-info/entry_points.txt +0 -0
  41. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/python_observabilityclient.egg-info/not-zip-safe +0 -0
  42. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/python_observabilityclient.egg-info/top_level.txt +0 -0
  43. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/requirements.txt +0 -0
  44. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/setup.py +0 -0
  45. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/test-requirements.txt +0 -0
  46. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/tools/fix_ca_bundle.sh +0 -0
  47. {python-observabilityclient-0.1.1 → python-observabilityclient-0.3.0}/tools/install_deps.sh +0 -0
@@ -8,3 +8,4 @@ Leif Madsen <lmadsen@redhat.com>
8
8
  Marihan Girgis mgirgisf@redhat.com
9
9
  Martin Magr <mmagr@redhat.com>
10
10
  Martin Mágr <mmagr@redhat.com>
11
+ Takashi Kajinami <kajinamit@oss.nttdata.com>
@@ -1,6 +1,22 @@
1
1
  CHANGES
2
2
  =======
3
3
 
4
+ 0.3.0
5
+ -----
6
+
7
+ * Drop direct usage of simplejson
8
+ * Use stestr for testing
9
+
10
+ 0.2.0
11
+ -----
12
+
13
+ * Sort column order in cli output
14
+ * Fix table formatter
15
+ * Remove unused test dependencies
16
+ * Remove AUTHORS file
17
+ * Add TLS support
18
+ * Drop unused --dev and --messy
19
+
4
20
  0.1.1
5
21
  -----
6
22
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-observabilityclient
3
- Version: 0.1.1
3
+ Version: 0.3.0
4
4
  Summary: OpenStack Observability Client
5
5
  Home-page: https://infrawatch.github.io/documentation/
6
6
  Author: OpenStack
@@ -77,4 +77,5 @@ Classifier: Programming Language :: Python :: 3.10
77
77
  Classifier: Programming Language :: Python :: 3.11
78
78
  Requires-Python: >=3.8
79
79
  Description-Content-Type: text/markdown; charset=UTF-8
80
+ Provides-Extra: doc
80
81
  Provides-Extra: test
@@ -27,24 +27,22 @@ class PrometheusAPIClientError(Exception):
27
27
  def __str__(self) -> str:
28
28
  if self.resp.status_code != requests.codes.ok:
29
29
  if self.resp.status_code != 204:
30
- decoded = self.resp.json()
31
- if 'error' in decoded:
32
- return f'[{self.resp.status_code}] {decoded["error"]}'
30
+ try:
31
+ decoded = self.resp.json()
32
+ if 'error' in decoded:
33
+ return f'[{self.resp.status_code}] {decoded["error"]}'
34
+ except requests.JSONDecodeError:
35
+ # If an https endpoint is accessed as http,
36
+ # we get 400 status with plain text instead of
37
+ # json and decoding it raises exception.
38
+ return f'[{self.resp.status_code}] {self.resp.text}'
33
39
  return f'[{self.resp.status_code}] {self.resp.reason}'
34
40
  else:
35
41
  decoded = self.resp.json()
36
42
  return f'[{decoded.status}]'
37
43
 
38
44
  def __repr__(self) -> str:
39
- if self.resp.status_code != requests.codes.ok:
40
- if self.resp.status_code != 204:
41
- decoded = self.resp.json()
42
- if 'error' in decoded:
43
- return f'[{self.resp.status_code}] {decoded["error"]}'
44
- return f'[{self.resp.status_code}] {self.resp.reason}'
45
- else:
46
- decoded = self.resp.json()
47
- return f'[{decoded.status}]'
45
+ return self.__str__()
48
46
 
49
47
 
50
48
  class PrometheusMetric(object):
@@ -128,3 +128,70 @@ class Metrics2ColsTest(testtools.TestCase):
128
128
 
129
129
  ret = metric_utils.metrics2cols(input_metrics)
130
130
  self.assertEqual(expected, ret)
131
+
132
+ def test_metrics2cols_column_ordering(self):
133
+ metric = {
134
+ 'value': [
135
+ 1234567,
136
+ 5
137
+ ],
138
+ 'metric': {
139
+ 'a_label1': 'value1',
140
+ 'b_label2': 'value2',
141
+ }
142
+ }
143
+ input_metrics = [prometheus_client.PrometheusMetric(metric)]
144
+ expected = (['a_label1', 'b_label2', 'value'],
145
+ [['value1', 'value2', 5]])
146
+
147
+ ret = metric_utils.metrics2cols(input_metrics)
148
+ self.assertEqual(expected, ret)
149
+
150
+ metric = {
151
+ 'value': [
152
+ 1234567,
153
+ 5
154
+ ],
155
+ 'metric': {
156
+ 'b_label1': 'value1',
157
+ 'a_label2': 'value2',
158
+ }
159
+ }
160
+ input_metrics = [prometheus_client.PrometheusMetric(metric)]
161
+ expected = (['a_label2', 'b_label1', 'value'],
162
+ [['value2', 'value1', 5]])
163
+
164
+ ret = metric_utils.metrics2cols(input_metrics)
165
+ self.assertEqual(expected, ret)
166
+
167
+ metric1 = {
168
+ 'value': [
169
+ 1234567,
170
+ 5
171
+ ],
172
+ 'metric': {
173
+ 'b_label1': 'value1',
174
+ 'a_label2': 'value2',
175
+ }
176
+ }
177
+ metric2 = {
178
+ 'value': [
179
+ 1234567,
180
+ 5
181
+ ],
182
+ 'metric': {
183
+ 'b_label1': 'value1',
184
+ 'a_label2': 'value2',
185
+ 'd_label3': 'value3',
186
+ 'c_label4': 'value4',
187
+ }
188
+ }
189
+ input_metrics = [prometheus_client.PrometheusMetric(metric1),
190
+ prometheus_client.PrometheusMetric(metric2)]
191
+ expected = (['a_label2', 'b_label1', 'c_label4', 'd_label3', 'value'],
192
+ [['value2', 'value1', '', '', 5],
193
+ ['value2', 'value1', 'value4', 'value3', 5]]
194
+ )
195
+
196
+ ret = metric_utils.metrics2cols(input_metrics)
197
+ self.assertEqual(expected, ret)
@@ -45,6 +45,7 @@ def get_config_file():
45
45
  def get_prometheus_client():
46
46
  host = None
47
47
  port = None
48
+ ca_cert = None
48
49
  conf_file = get_config_file()
49
50
  if conf_file is not None:
50
51
  conf = yaml.safe_load(conf_file)
@@ -52,6 +53,8 @@ def get_prometheus_client():
52
53
  host = conf['host']
53
54
  if 'port' in conf:
54
55
  port = conf['port']
56
+ if 'ca_cert' in conf:
57
+ ca_cert = conf['ca_cert']
55
58
  conf_file.close()
56
59
 
57
60
  # NOTE(jwysogla): We allow to overide the prometheus.yaml by
@@ -60,10 +63,15 @@ def get_prometheus_client():
60
63
  host = os.environ['PROMETHEUS_HOST']
61
64
  if 'PROMETHEUS_PORT' in os.environ:
62
65
  port = os.environ['PROMETHEUS_PORT']
66
+ if 'PROMETHEUS_CA_CERT' in os.environ:
67
+ ca_cert = os.environ['PROMETHEUS_CA_CERT']
63
68
  if host is None or port is None:
64
69
  raise ConfigurationError("Can't find prometheus host and "
65
70
  "port configuration.")
66
- return PrometheusAPIClient(f"{host}:{port}")
71
+ client = PrometheusAPIClient(f"{host}:{port}")
72
+ if ca_cert is not None:
73
+ client.set_ca_cert(ca_cert)
74
+ return client
67
75
 
68
76
 
69
77
  def get_client(obj):
@@ -90,18 +98,15 @@ def format_labels(d: dict) -> str:
90
98
 
91
99
 
92
100
  def metrics2cols(m):
93
- cols = []
101
+ # get all label keys
102
+ cols = list(set().union(*(d.labels.keys() for d in m)))
103
+ cols.sort()
104
+ cols.append("value")
94
105
  fields = []
95
- first = True
96
106
  for metric in m:
97
- row = []
107
+ row = [""] * len(cols)
98
108
  for key, value in metric.labels.items():
99
- if first:
100
- cols.append(key)
101
- row.append(value)
102
- if first:
103
- cols.append("value")
104
- row.append(metric.value)
109
+ row[cols.index(key)] = value
110
+ row[cols.index("value")] = metric.value
105
111
  fields.append(row)
106
- first = False
107
112
  return cols, fields
@@ -23,17 +23,6 @@ class ObservabilityBaseCommand(command.Command):
23
23
 
24
24
  def get_parser(self, prog_name):
25
25
  parser = super().get_parser(prog_name)
26
- parser.add_argument(
27
- '--dev',
28
- action='store_true',
29
- help=_("Enable development output.")
30
- )
31
- parser.add_argument(
32
- '--messy',
33
- action='store_true',
34
- help=_("Disable cleanup of temporary files.")
35
- )
36
-
37
26
  # TODO(jwysogla): Should this be restricted somehow?
38
27
  parser.add_argument(
39
28
  '--disable-rbac',
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-observabilityclient
3
- Version: 0.1.1
3
+ Version: 0.3.0
4
4
  Summary: OpenStack Observability Client
5
5
  Home-page: https://infrawatch.github.io/documentation/
6
6
  Author: OpenStack
@@ -77,4 +77,5 @@ Classifier: Programming Language :: Python :: 3.10
77
77
  Classifier: Programming Language :: Python :: 3.11
78
78
  Requires-Python: >=3.8
79
79
  Description-Content-Type: text/markdown; charset=UTF-8
80
+ Provides-Extra: doc
80
81
  Provides-Extra: test
@@ -0,0 +1 @@
1
+ {"git_version": "e64b943", "is_release": true}
@@ -0,0 +1,10 @@
1
+ cliff>=1.14.0
2
+ keystoneauth1>=1.0.0
3
+ osc-lib>=1.0.1
4
+
5
+ [doc]
6
+ reno>=1.6.2
7
+
8
+ [test]
9
+ tempest>=10
10
+ testtools>=1.4.0
@@ -35,16 +35,11 @@ packages =
35
35
  observabilityclient
36
36
 
37
37
  [options.extras_require]
38
- test =
39
- coverage>=3.6
40
- oslotest>=1.10.0 # Apache-2.0
38
+ doc =
41
39
  reno>=1.6.2 # Apache2
40
+ test =
42
41
  tempest>=10
43
- stestr>=2.0.0 # Apache-2.0
44
42
  testtools>=1.4.0
45
- pifpaf[gnocchi]>=0.23
46
- SQLAlchemy<=1.4.41
47
- oslo.db<=12.3.1
48
43
 
49
44
  [entry_points]
50
45
  openstack.cli.extension =
@@ -14,9 +14,8 @@ passenv =
14
14
  PROMETHEUS_*
15
15
  OBSERVABILITY_*
16
16
  deps = .[test]
17
- pytest
18
17
 
19
- commands = pytest {posargs} {env:OS_TEST_PATH}
18
+ commands = stestr run --slowest {posargs} --test-path {env:OS_TEST_PATH}
20
19
 
21
20
  [testenv:pep8]
22
21
  basepython = python3
@@ -44,7 +43,7 @@ deps = .[test]
44
43
  -r{toxinidir}/test-requirements.txt
45
44
  commands =
46
45
  bash tools/fix_ca_bundle.sh
47
- pytest {posargs} {env:OS_TEST_PATH}
46
+ stestr run --slowest {posargs} --test-path {env:OS_TEST_PATH}
48
47
 
49
48
 
50
49
  [flake8]
@@ -1 +0,0 @@
1
- {"git_version": "9607ee2", "is_release": true}
@@ -1,14 +0,0 @@
1
- cliff>=1.14.0
2
- keystoneauth1>=1.0.0
3
- osc-lib>=1.0.1
4
-
5
- [test]
6
- SQLAlchemy<=1.4.41
7
- coverage>=3.6
8
- oslo.db<=12.3.1
9
- oslotest>=1.10.0
10
- pifpaf[gnocchi]>=0.23
11
- reno>=1.6.2
12
- stestr>=2.0.0
13
- tempest>=10
14
- testtools>=1.4.0