Skip to content

Commit eb46e37

Browse files
mkarpiarzWasaac
authored andcommitted
Add the NOTNUMBOOL mutator
The "NOTNUMBOOL" mutator returns 1.0 when quantity is 0 and 0.0 otherwise. Change-Id: I16f2b05dcd089b214e18762e1f87d0dbcc2cb7cc (cherry picked from commit bf43a11)
1 parent 6c61ea7 commit eb46e37

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

cloudkitty/collector/__init__.py

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

cloudkitty/utils/__init__.py

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

260+
if mode == 'NOTNUMBOOL':
261+
return float(value == 0.0)
262+
260263
if mode == 'FLOOR':
261264
return math.floor(value)
262265

doc/source/admin/configuration/collector.rst

Lines changed: 18 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

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)