prometheus / client_python

Prometheus instrumentation library for Python applications
Apache License 2.0
3.93k stars 794 forks source link

TypeError in floatToGoString in utils.py #907

Open klaska-lukas opened 1 year ago

klaska-lukas commented 1 year ago

When one PureStorage array controller is failed it reports None value for metric purefa_network_interface_performance. The function floatToGoString fails because it cannot handle None value.

I added two lines in my local copy of "utils.py" to make this function work, so it replaces None value with 0 (zero).

Instead of:

def floatToGoString(d):
    d = float(d)

I use:

def floatToGoString(d):
    if d is None:
        d = 0
    d = float(d)

Below is the error message:

File "/home/pure_exporter/venv/lib/python3.7/site-packages/prometheus_client/utils.py", line 9, in floatToGoString d = float(d) TypeError: ("float() argument must be a string or a number, not 'NoneType'", Metric(purefa_network_interface_performance, FlashArray network interface performance, gauge, , [Sample(name='purefa_network_interface_performance', labels={'interface': 'ct0.eth5', 'dimension': 'rx_bytes'}, value=None, timestamp=None, exemplar=None),

csmarchbanks commented 1 year ago

That may work for your case, but I am not sure it is behavior we want in the library. Do you know how a value of None was set in that metric? That seems like a bug in the collector, or maybe elsewhere in this library. If anything I would expect None to translate to NaN not 0.