prometheus / prometheus/client_python

TypeError in floatToGoString in utils.py

Open
#907 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.4k
Forks
876
Avg merge
8d 4h
Merged PRs (30d)
1

Description

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),

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in utils.py at floatToGoString and reproduce the failure with a None value. Review the existing tests around this utility, then add regression coverage showing that None is handled as zero while normal numeric inputs still work. Done means the reported metric can be serialized without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.