Skip to content

Commit be475c9

Browse files
authored
Merge branch 'stackhpc/victoria' into upstream/victoria-2022-09-26
2 parents 54386c2 + 86b5092 commit be475c9

File tree

11 files changed

+83
-3
lines changed

11 files changed

+83
-3
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @stackhpc/openstack
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
name: Tag & Release
3+
'on':
4+
push:
5+
branches:
6+
- stackhpc/victoria
7+
permissions:
8+
contents: write
9+
jobs:
10+
tag-and-release:
11+
uses: stackhpc/.github/.github/workflows/tag-and-release.yml@main

.github/workflows/tox.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
name: Tox Continuous Integration
3+
'on':
4+
pull_request:
5+
jobs:
6+
tox:
7+
uses: stackhpc/.github/.github/workflows/tox.yml@main

cloudkitty/api/v1/controllers/rating.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from oslo_log import log
1818
import pecan
1919
from pecan import rest
20+
2021
from stevedore import extension
2122
from wsme import types as wtypes
2223
import wsmeext.pecan as wsme_pecan

cloudkitty/collector/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,11 @@ def MetricDict(value):
9090
Required('metadata', default=list): [
9191
All(str, Length(min=1))
9292
],
93-
# Mutate collected value. May be any of (NONE, NUMBOOL, FLOOR, CEIL).
93+
# Mutate collected value. May be any of:
94+
# (NONE, NUMBOOL, NOTNUMBOOL, FLOOR, CEIL).
9495
# Defaults to NONE
9596
Required('mutate', default='NONE'):
96-
In(['NONE', 'NUMBOOL', 'FLOOR', 'CEIL']),
97+
In(['NONE', 'NUMBOOL', 'NOTNUMBOOL', 'FLOOR', 'CEIL']),
9798
# Collector-specific args. Should be overriden by schema provided for
9899
# the given collector
99100
Optional('extra_args'): dict,

cloudkitty/collector/prometheus.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from oslo_config import cfg
2020
from oslo_log import log
21+
from voluptuous import All
2122
from voluptuous import In
2223
from voluptuous import Optional
2324
from voluptuous import Required
@@ -83,7 +84,9 @@
8384
'changes', 'delta', 'deriv',
8485
'idelta', 'irange', 'irate',
8586
'rate'
86-
])
87+
]),
88+
Optional('query_prefix', default=''): All(str),
89+
Optional('query_suffix', default=''): All(str),
8790
}
8891
}
8992

@@ -159,6 +162,8 @@ def fetch_all(self, metric_name, start, end, scope_id, q_filter=None):
159162
'range_function')
160163
groupby = self.conf[metric_name].get('groupby', [])
161164
metadata = self.conf[metric_name].get('metadata', [])
165+
query_prefix = self.conf[metric_name]['extra_args']['query_prefix']
166+
query_suffix = self.conf[metric_name]['extra_args']['query_suffix']
162167
period = tzutils.diff_seconds(end, start)
163168
time = end
164169

@@ -198,6 +203,14 @@ def fetch_all(self, metric_name, start, end, scope_id, q_filter=None):
198203
', '.join(groupby + metadata)
199204
)
200205

206+
# Add custom query prefix
207+
if query_prefix:
208+
query = "{0} {1}".format(query_prefix, query)
209+
210+
# Add custom query suffix
211+
if query_suffix:
212+
query = "{0} {1}".format(query, query_suffix)
213+
201214
try:
202215
res = self._conn.get_instant(
203216
query,

cloudkitty/tests/collectors/test_validation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ def test_prometheus_minimal_config_empty_extra_args(self):
131131
expected_output['metric_one']['groupby'].append('project_id')
132132
expected_output['metric_one']['extra_args'] = {
133133
'aggregation_method': 'max',
134+
'query_prefix': '',
135+
'query_suffix': '',
134136
}
135137
self.assertEqual(
136138
collector.prometheus.PrometheusCollector.check_configuration(data),
@@ -143,6 +145,8 @@ def test_prometheus_minimal_config_no_extra_args(self):
143145
expected_output['metric_one']['groupby'].append('project_id')
144146
expected_output['metric_one']['extra_args'] = {
145147
'aggregation_method': 'max',
148+
'query_prefix': '',
149+
'query_suffix': '',
146150
}
147151
self.assertEqual(
148152
collector.prometheus.PrometheusCollector.check_configuration(data),
@@ -154,13 +158,17 @@ def test_prometheus_minimal_config_minimal_extra_args(self):
154158
data['metrics']['metric_one']['extra_args'] = {
155159
'aggregation_method': 'max',
156160
'query_function': 'abs',
161+
'query_prefix': 'custom_prefix',
162+
'query_suffix': 'custom_suffix',
157163
'range_function': 'delta',
158164
}
159165
expected_output = copy.deepcopy(self.base_output)
160166
expected_output['metric_one']['groupby'].append('project_id')
161167
expected_output['metric_one']['extra_args'] = {
162168
'aggregation_method': 'max',
163169
'query_function': 'abs',
170+
'query_prefix': 'custom_prefix',
171+
'query_suffix': 'custom_suffix',
164172
'range_function': 'delta',
165173
}
166174

cloudkitty/utils/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def mutate(value, mode='NONE'):
259259
if mode == 'NUMBOOL':
260260
return float(value != 0.0)
261261

262+
if mode == 'NOTNUMBOOL':
263+
return float(value == 0.0)
264+
262265
if mode == 'FLOOR':
263266
return math.floor(value)
264267

doc/source/admin/configuration/collector.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ Four values are accepted for this parameter:
186186

187187
* ``NUMBOOL``: If the collected qty equals 0, leave it at 0. Else, set it to 1.
188188

189+
* ``NOTNUMBOOL``: If the collected qty equals 0, set it to 1. Else, set it to
190+
0.
191+
189192
.. warning::
190193

191194
Quantity mutation is done **after** conversion. Example::
@@ -214,6 +217,21 @@ then defined based on the instance metadata. Example:
214217
metadata:
215218
- flavor_id
216219
220+
The ``NOTNUMBOOL`` mutator is useful for status-like metrics where 0 denotes
221+
the billable state. For example the following Prometheus metric has value of 0
222+
when the instance is in ACTIVE state but 4 if the instance is in ERROR state:
223+
224+
.. code-block:: yaml
225+
226+
metrics:
227+
openstack_nova_server_status:
228+
unit: instance
229+
mutate: NOTNUMBOOL
230+
groupby:
231+
- id
232+
metadata:
233+
- flavor_id
234+
217235
Display name
218236
~~~~~~~~~~~~
219237

@@ -311,6 +329,12 @@ Prometheus
311329
``log10``, ``round``, ``sqrt``. For more information on these functions,
312330
you can check `this page`_
313331

332+
* ``query_prefix``: Optional argument. An arbitrary prefix to add to the
333+
Prometheus query generated by CloudKitty, separated by a space.
334+
335+
* ``query_suffix``: Optional argument. An arbitrary suffix to add to the
336+
Prometheus query generated by CloudKitty, separated by a space.
337+
314338
* ``range_function``: Optional argument. The function to apply instead of the
315339
implicit ``{aggregation_method}_over_time``. Must be one of ``changes``,
316340
``delta``, ``deriv``, ``idelta``, ``irange``, ``irate``, ``rate``. For more
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
The new "NOTNUMBOOL" mutator has been added. This mutator is, essentially,
5+
an opposite of the "NUMBOOL" mutator as it returns 1.0 when quantity is 0
6+
and 0.0 otherwise.

0 commit comments

Comments
 (0)