Browse Source

Merge "Add the NOTNUMBOOL mutator"

changes/15/787015/1
Zuul 5 months ago
committed by Gerrit Code Review
parent
commit
65f1591e31
  1. 5
      cloudkitty/collector/__init__.py
  2. 3
      cloudkitty/utils/__init__.py
  3. 18
      doc/source/admin/configuration/collector.rst
  4. 6
      releasenotes/notes/notnumbool-mutator-ab056e86f2bc843d.yaml

5
cloudkitty/collector/__init__.py

@ -89,10 +89,11 @@ METRIC_BASE_SCHEMA = {
Required('metadata', default=list): [
All(str, Length(min=1))
],
# Mutate collected value. May be any of (NONE, NUMBOOL, FLOOR, CEIL).
# Mutate collected value. May be any of:
# (NONE, NUMBOOL, NOTNUMBOOL, FLOOR, CEIL).
# Defaults to NONE
Required('mutate', default='NONE'):
In(['NONE', 'NUMBOOL', 'FLOOR', 'CEIL']),
In(['NONE', 'NUMBOOL', 'NOTNUMBOOL', 'FLOOR', 'CEIL']),
# Collector-specific args. Should be overriden by schema provided for
# the given collector
Optional('extra_args'): dict,

3
cloudkitty/utils/__init__.py

@ -257,6 +257,9 @@ def mutate(value, mode='NONE'):
if mode == 'NUMBOOL':
return float(value != 0.0)
if mode == 'NOTNUMBOOL':
return float(value == 0.0)
if mode == 'FLOOR':
return math.floor(value)

18
doc/source/admin/configuration/collector.rst

@ -186,6 +186,9 @@ Four values are accepted for this parameter:
* ``NUMBOOL``: If the collected qty equals 0, leave it at 0. Else, set it to 1.
* ``NOTNUMBOOL``: If the collected qty equals 0, set it to 1. Else, set it to
0.
.. warning::
Quantity mutation is done **after** conversion. Example::
@ -214,6 +217,21 @@ then defined based on the instance metadata. Example:
metadata:
- flavor_id
The ``NOTNUMBOOL`` mutator is useful for status-like metrics where 0 denotes
the billable state. For example the following Prometheus metric has value of 0
when the instance is in ACTIVE state but 4 if the instance is in ERROR state:
.. code-block:: yaml
metrics:
openstack_nova_server_status:
unit: instance
mutate: NOTNUMBOOL
groupby:
- id
metadata:
- flavor_id
Display name
~~~~~~~~~~~~

6
releasenotes/notes/notnumbool-mutator-ab056e86f2bc843d.yaml

@ -0,0 +1,6 @@
---
features:
- |
The new "NOTNUMBOOL" mutator has been added. This mutator is, essentially,
an opposite of the "NUMBOOL" mutator as it returns 1.0 when quantity is 0
and 0.0 otherwise.
Loading…
Cancel
Save