Skip to content

Parser produces invalid metrics for no-space metrics #871

@MatthewScholefield

Description

@MatthewScholefield

The prometheus metrics endpoint for an IoT tutorial emits metrics with no space after the metric like this:

# HELP pm02 Particulate Matter PM2.5 value
# TYPE pm02 gauge
pm02{id="airgrad0",mac="FF:FF:FF:FF:FF:FF"}11
# HELP rco2 CO2 value, in ppm
# TYPE rco2 gauge
rco2{id="airgrad0",mac="FF:FF:FF:FF:FF:FF"}532
# HELP atmp Temperature, in degrees Celsius
# TYPE atmp gauge
atmp{id="airgrad0",mac="FF:FF:FF:FF:FF:FF"}22.10
# HELP rhum Relative humidity, in percent
# TYPE rhum gauge
rhum{id="airgrad0",mac="FF:FF:FF:FF:FF:FF"}40

Parsing this didn't error but instead produced metrics with incorrect values:

[Metric(pm02, Particulate Matter PM2.5 value, gauge, , [Sample(name='pm02', labels={'id': 'airgrad0', 'mac': 'FF:FF:FF:FF:FF:FF'}, value=1.0, timestamp=None, exemplar=None)]),
 Metric(rco2, CO2 value, in ppm, gauge, , [Sample(name='rco2', labels={'id': 'airgrad0', 'mac': 'FF:FF:FF:FF:FF:FF'}, value=32.0, timestamp=None, exemplar=None)]),
 Metric(atmp, Temperature, in degrees Celsius, gauge, , [Sample(name='atmp', labels={'id': 'airgrad0', 'mac': 'FF:FF:FF:FF:FF:FF'}, value=2.1, timestamp=None, exemplar=None)]),
 Metric(rhum, Relative humidity, in percent, gauge, , [Sample(name='rhum', labels={'id': 'airgrad0', 'mac': 'FF:FF:FF:FF:FF:FF'}, value=0.0, timestamp=None, exemplar=None)])]

I think ideally perhaps it should raise a ValueError in this circumstance (or alternatively support this if it's considered a valid metrics format; I didn't find a spec on what the exact format is).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions