client_golang icon indicating copy to clipboard operation
client_golang copied to clipboard

Interface for MetricVec (and subclasses)

Open 2uasimojo opened this issue 2 years ago • 3 comments

Having an interface for MetricVec funcs like [Must]CurryWith, With[LabelValues], etc. -- parallel to ObserverVec -- would make it possible to generate mocks and thus facilitate unit testing for CounterVec, GaugeVec, HistogramVec, and SummaryVec.

Possibly related to #223?

2uasimojo avatar Jan 09 '23 22:01 2uasimojo

Hello 👋 Looks like there was no activity on this issue for the last 3 months. Do you mind updating us on the status? Is this still reproducible or needed? If yes, just comment on this PR or push a commit. Thanks! 🤗 If there will be no activity in the next 4 weeks, this issue will be closed (we can always reopen an issue if we need!).

stale[bot] avatar Aug 13 '23 01:08 stale[bot]

This would still be lovely to have. Will we survive with out it? For sure. But we would include a lot more unit tests around our metrics code, which we don't do much of today because it's Hard™.

2uasimojo avatar Aug 13 '23 17:08 2uasimojo

The whole type structure could be improved indeed, but that would require an invasive change, which can only happen with a v2 major release.

In the meantime, you could make use of the fact that Go interfaces don't have to be defined in a particular package. You can define your own MetricVec interface and use it in your code as if they were defined in the client_golang/prometheus package itself.

beorn7 avatar Aug 15 '23 16:08 beorn7

Closing for now as promised, let us know if you need this to be reopened! 🤗

stale[bot] avatar Jul 19 '25 08:07 stale[bot]