Skip to content

Using prometheus collector MustRegister in New{Counter,Gauge} and possible panic #937

Open

Description

@vadv

Thanks for the wonderful product!
I think it would be fair to point the limitations of calling New in the documentation, since calling New again calls panic.

Activity

  1. peterbourgon commented on Nov 14, 2019

    @peterbourgon
    Member

    A great point! :)

  2. tpdenk commented on Nov 22, 2019

    @tpdenk

    Is this a bug or a documentation issue? If it is a bug, I would like to have a look at it.

  3. peterbourgon commented on Nov 25, 2019

    @peterbourgon
    Member

    Hmm, it could be either. The easiest fix would be to update the docs to mention it can panic, but a better fix would probably be a new constructor with took an e.g. prometheus.Registerer into which the metrics would be registered, and refactoring the existing constructor (with updated doc comment) to call the new constructor with prometheus.DefaultRegisterer (or whatever it's called).

  4. AshleyDumaine commented on Feb 6, 2020

    @AshleyDumaine

    I also ran into this issue (the day this was filed interestingly) and implemented a Delete function for each of the metric types that calls Unregister: AshleyDumaine@5af0353
    Would this be an acceptable solution?

  5. peterbourgon commented on Feb 6, 2020

    @peterbourgon
    Member

    I don't think Delete is the answer — metrics generally should be singletons in your component graph. If we need something more it would probably be to take an explicit Registerer.

  6. added a commit that references this issue on Jun 16, 2020
  7. prasadghagare commented on Jun 16, 2020

    @prasadghagare

    Hi @TimSatke , are you still looking at this?
    If not I would like to have a go at it.

  8. tpdenk commented on Jun 16, 2020

    @tpdenk

    I didn’t look at it, since I didn’t consider any answer a clear „go“, so yes, take it

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions