Skip to content

can generate malformed data by creating a duplicate Counter #97

Closed

Description

@bubaflub

I accidentally generated malformed data by creating two Counters on the same Registry that had the same name, help text.

Example code:

import prometheus_client

reg = prometheus_client.CollectorRegistry()
c1 = prometheus_client.Counter("foo", "bar", labelnames=["baz", "stuff"], registry=reg)
c1.labels({"baz": 1, "stuff": 2}).inc(1)
c2 = prometheus_client.Counter("foo", "bar", labelnames=["baz", "stuff"], registry=reg)
c2.labels({"baz": 3, "stuff": 4}).inc(2)
prometheus_client.push_to_gateway('localhost:8000', job='example', registry=reg)

Data sent in request to push gateway:

# HELP foo bar
# TYPE foo counter
foo{baz="1",stuff="2"} 1.0
# HELP foo bar
# TYPE foo counter
foo{baz="3",stuff="4"} 2.0

Response sent from the push gateway:

text format parsing error in line 4: second HELP line for metric name "foo"

I'd prefer either getting an error from prometheus_client telling me that I can't add two identical metrics. Alternatively, I'd like for prometheus_client to merge the two metrics and not send two identical HELP lines.

Activity

  1. grobie commented on Aug 26, 2016

    @grobie
    Member

    At least client_golang and client_ruby do check for metric uniqueness during registration.

  2. rud commented on Sep 27, 2016

    @rud

    I think a small merge-request would be appreciated here - any takers?

  3. brian-brazil commented on Sep 27, 2016

    @brian-brazil
    Contributor

    This is more complicated than it might seem at a first glance.

  4. rud commented on Sep 27, 2016

    @rud

    It wasn't an attempt to sound glib, I do not know the architecture, and am unable to guess at the complexity involved. This was more of an attempt to encourage the reporter to maybe contribute a patch for the specific issue experienced.

  5. mad01 commented on Oct 28, 2016

    @mad01

    can you do something to merge it in the generate_latest function maybe?

  6. brian-brazil commented on Oct 28, 2016

    @brian-brazil
    Contributor

    It is an error state, it should be handled at registration time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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