Skip to content

Difference in parser behaviour compared to prometheus/common/expfmt  #461

@zegelin

Description

@zegelin

The behaviour of the Python client's built-in text format parser differs to that of the parser found inside Prometheus itself.

Given the following (poorly formed, but apparently still valid) exposition output:

test_metric_a {hello="world"} 0 0
test_metric_b {hello="world"} 0 0
test_metric_a {hello="universe"} 0 0
test_metric_b {hello="universe"} 0 0

The Go expfmt TextParser.TextToMetricFamilies(...) function produces:

(map[string]*io_prometheus_client.MetricFamily) (len=2) {
 (string) (len=13) "test_metric_a": (*io_prometheus_client.MetricFamily)(0xc0000c4320)(name:"test_metric_a" type:UNTYPED metric:<label:<name:"hello" value:"world" > untyped:<value:0 > timestamp_ms:0 > metric:<label:<name:"hello" value:"universe" > untyped:<value:0 > timestamp_ms:0 > ),
 (string) (len=13) "test_metric_b": (*io_prometheus_client.MetricFamily)(0xc0000c4370)(name:"test_metric_b" type:UNTYPED metric:<label:<name:"hello" value:"world" > untyped:<value:0 > timestamp_ms:0 > metric:<label:<name:"hello" value:"universe" > untyped:<value:0 > timestamp_ms:0 > )
}

whereas the Python client's parser.text_fd_to_metric_families(...) function produces:

[
    Metric(test_metric_a, , unknown, , [Sample(name='test_metric_a', labels={'hello': 'world'}, value=0.0, timestamp=None, exemplar=None)]),
    Metric(test_metric_b, , unknown, , [Sample(name='test_metric_b', labels={'hello': 'world'}, value=0.0, timestamp=None, exemplar=None)]),
    Metric(test_metric_a, , unknown, , [Sample(name='test_metric_a', labels={'hello': 'universe'}, value=0.0, timestamp=None, exemplar=None)]),
    Metric(test_metric_b, , unknown, , [Sample(name='test_metric_b', labels={'hello': 'universe'}, value=0.0, timestamp=None, exemplar=None)])
]

As you can see the Go parser groups the samples into two untyped metric families with two samples each whereas the Python parser creates a new metric family for each sample.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions