python-observabilityclient 0.1.1__py3-none-any.whl → 0.2.0__py3-none-any.whl

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.
@@ -15,6 +15,7 @@
15
15
  import logging
16
16
 
17
17
  import requests
18
+ import simplejson
18
19
 
19
20
 
20
21
  LOG = logging.getLogger(__name__)
@@ -27,9 +28,15 @@ class PrometheusAPIClientError(Exception):
27
28
  def __str__(self) -> str:
28
29
  if self.resp.status_code != requests.codes.ok:
29
30
  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"]}'
31
+ try:
32
+ decoded = self.resp.json()
33
+ if 'error' in decoded:
34
+ return f'[{self.resp.status_code}] {decoded["error"]}'
35
+ except simplejson.errors.JSONDecodeError:
36
+ # If an https endpoint is accessed as http,
37
+ # we get 400 status with plain text instead of
38
+ # json and decoding it raises exception.
39
+ return f'[{self.resp.status_code}] {self.resp.text}'
33
40
  return f'[{self.resp.status_code}] {self.resp.reason}'
34
41
  else:
35
42
  decoded = self.resp.json()
@@ -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
@@ -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,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-observabilityclient
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: OpenStack Observability Client
5
5
  Home-page: https://infrawatch.github.io/documentation/
6
6
  Author: OpenStack
@@ -2,7 +2,7 @@ observabilityclient/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
2
2
  observabilityclient/client.py,sha256=cfRb816p6Ips9t2cdWvmSJ1uGrtTEHXQnctoExrLA5A,828
3
3
  observabilityclient/i18n.py,sha256=PFo6BaOfyGQD5q7L3FunYJ8d4mwbRszG8wOrJIjki_4,790
4
4
  observabilityclient/plugin.py,sha256=hyxENjNO6NLrH6G4muyAeEEtFTBa9d5OozjwpzNpJVA,2262
5
- observabilityclient/prometheus_client.py,sha256=Ba9lWCWytbHHNG8R_UJc7kd-287h0G2k9kwa2hdgBSc,7093
5
+ observabilityclient/prometheus_client.py,sha256=iVylMmgSDwBXuuGQjkixwrcfsHiS5NqEYrMB57R2pyQ,7467
6
6
  observabilityclient/tests/functional/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  observabilityclient/tests/functional/base.py,sha256=SXbPiksFH7aER-zZjIWxz5nwCqq5f1MYWth1tlFLwcs,6523
8
8
  observabilityclient/tests/functional/test_cli.py,sha256=QqU8BCGUnh4IlwnGr6hdDHjHp7TIM0jasDjReyZpz-Y,4856
@@ -12,20 +12,20 @@ observabilityclient/tests/unit/test_cli.py,sha256=TMKjb0IXwbMkm6frvfTqClOa5ZGGWK
12
12
  observabilityclient/tests/unit/test_prometheus_client.py,sha256=oPD5AALoyR0haQ8u0RYEasFSicKjT1RW9g_sFYCtLNM,18801
13
13
  observabilityclient/tests/unit/test_python_api.py,sha256=xOKCdLH52AF9Vf7tu4ja-O6zsC-FEH7Y-DJQ7x8jzy4,4760
14
14
  observabilityclient/tests/unit/test_rbac.py,sha256=PxBlvSGqGVFBSjQB1MGcyuBX5qcv6peQKSL5R_Aid9c,5692
15
- observabilityclient/tests/unit/test_utils.py,sha256=NA6aKTvZUNRbl6PYbx3o1EdRWiX8ylceixVMonxe01c,5370
15
+ observabilityclient/tests/unit/test_utils.py,sha256=-sYsiYTuvcb71SX2KewrxkPinMEGLzUi0wnfBHsOIOA,7387
16
16
  observabilityclient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- observabilityclient/utils/metric_utils.py,sha256=JnA_GoV8iJpzUaT-XkkEGcZ_R3UvjF5wrj6cNwqdOwQ,3153
17
+ observabilityclient/utils/metric_utils.py,sha256=K_G23krVIENNSPNsj2w9AkmCk2MDum9K3DkWNQl3Bro,3425
18
18
  observabilityclient/v1/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  observabilityclient/v1/base.py,sha256=g7r0GrtbUR6BDWPPvTRL1pF0hZbcq1evYQTeXqlI7X8,2556
20
20
  observabilityclient/v1/cli.py,sha256=ln7GsnbW95n90oFGw4zLiwHDjY0YHBxkRBzID-j6ZmA,4028
21
21
  observabilityclient/v1/client.py,sha256=q5bH-N9uCWi9boVVYhLv6M7NYLxMnmgGBupg2uqvgRo,1643
22
22
  observabilityclient/v1/python_api.py,sha256=nTsaasNBMVNrGW5CNSf7-o2oOKsea_u38GEbs2-8Gkw,3916
23
23
  observabilityclient/v1/rbac.py,sha256=cnscaSzcbY7AEcLHcjpXBeHHZ12k5-hYmVwXsMTBSjQ,6115
24
- python_observabilityclient-0.1.1.dist-info/AUTHORS,sha256=nRzPk_Mt_D1LGGqE81WuI_uDQxxuqGXPe5wwLC2i4cg,348
25
- python_observabilityclient-0.1.1.dist-info/LICENSE,sha256=qyh9xnj_IPtYWzClm5mZxCWRKTr2eUP_iLcU28DIvCw,11343
26
- python_observabilityclient-0.1.1.dist-info/METADATA,sha256=NEeKYk2LDFwLK1hLMQW3ZadlMZZhIs-Y6aJRiYFizOM,3440
27
- python_observabilityclient-0.1.1.dist-info/WHEEL,sha256=g4nMs7d-Xl9-xC9XovUrsDHGXt-FT0E17Yqo92DEfvY,92
28
- python_observabilityclient-0.1.1.dist-info/entry_points.txt,sha256=KVIgt6aQmLXBvbWakAMnBATcmYAd4U99I6UOyYpWD2c,425
29
- python_observabilityclient-0.1.1.dist-info/pbr.json,sha256=77GunQAO3MQ-naiPzkoamsm4PR0emHXMAu3izEj1aFw,46
30
- python_observabilityclient-0.1.1.dist-info/top_level.txt,sha256=Lf7Fwm3hfK-X1JNRy19rVlrMUOyQShBBPwsCU3pz6yw,20
31
- python_observabilityclient-0.1.1.dist-info/RECORD,,
24
+ python_observabilityclient-0.2.0.dist-info/AUTHORS,sha256=BVS3DtpzGMTE2D4RpV_lVctcBfQHGK5G1yWrNcrI1hI,393
25
+ python_observabilityclient-0.2.0.dist-info/LICENSE,sha256=qyh9xnj_IPtYWzClm5mZxCWRKTr2eUP_iLcU28DIvCw,11343
26
+ python_observabilityclient-0.2.0.dist-info/METADATA,sha256=R4cRUoo7LAdA-Cp09cE_jK8yQx6EhAZnaPSjAMoOu4g,3440
27
+ python_observabilityclient-0.2.0.dist-info/WHEEL,sha256=g4nMs7d-Xl9-xC9XovUrsDHGXt-FT0E17Yqo92DEfvY,92
28
+ python_observabilityclient-0.2.0.dist-info/entry_points.txt,sha256=KVIgt6aQmLXBvbWakAMnBATcmYAd4U99I6UOyYpWD2c,425
29
+ python_observabilityclient-0.2.0.dist-info/pbr.json,sha256=WS-7Hx84xzfqmQFMjGB5pTZKhFjhExgXQNhl-drJCAg,46
30
+ python_observabilityclient-0.2.0.dist-info/top_level.txt,sha256=Lf7Fwm3hfK-X1JNRy19rVlrMUOyQShBBPwsCU3pz6yw,20
31
+ python_observabilityclient-0.2.0.dist-info/RECORD,,
@@ -0,0 +1 @@
1
+ {"git_version": "0dea42c", "is_release": true}
@@ -1 +0,0 @@
1
- {"git_version": "9607ee2", "is_release": true}