Merge "Add the NOTNUMBOOL mutator"

This commit is contained in:
Zuul 2021-04-19 16:19:03 +00:00 committed by Gerrit Code Review
commit 65f1591e31
4 changed files with 30 additions and 2 deletions

View File

@ -89,10 +89,11 @@ METRIC_BASE_SCHEMA = {
Required('metadata', default=list): [ Required('metadata', default=list): [
All(str, Length(min=1)) 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 # Defaults to NONE
Required('mutate', default='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 # Collector-specific args. Should be overriden by schema provided for
# the given collector # the given collector
Optional('extra_args'): dict, Optional('extra_args'): dict,

View File

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

View File

@ -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. * ``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:: .. warning::
Quantity mutation is done **after** conversion. Example:: Quantity mutation is done **after** conversion. Example::
@ -214,6 +217,21 @@ then defined based on the instance metadata. Example:
metadata: metadata:
- flavor_id - 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 Display name
~~~~~~~~~~~~ ~~~~~~~~~~~~

View File

@ -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.