client_golang icon indicating copy to clipboard operation
client_golang copied to clipboard

`Gather` does not include CounterVec unless it has had `WithLabelValues` called

Open samsondav opened this issue 2 years ago • 2 comments

If I register as such:

var (
	simpleCounter = promauto.NewCounter(prometheus.CounterOpts{
		Name: "simple_counter",
		Help: "Some help message",
	})

	simpleCounterVec = promauto.NewCounterVec(prometheus.CounterOpts{
		Name: "simple_counter_vec",
		Help: "Some help message",
	}, []string{"label1", "label2"})
)

func init() {
	// prometheus.DefaultRegisterer.MustRegister(simpleCounterVec)

	metricsFamilies, err := prometheus.DefaultGatherer.Gather()
	if err != nil {
		panic(err)
	}
	for _, f := range metricsFamilies {
		fmt.Println(f)
	}
}

Then only simple_counter is included in the metrics. simpleCounterVec is ignored. I know it has been registered because calling MustRegister panics.

I would expect all prometheus metrics to be included in the result of Gather, both regular counters and vector counters.

samsondav avatar Mar 28 '22 20:03 samsondav

An empty vector on its own isn't producing any metric yet. Without any known label values, how should such a metric look like?

beorn7 avatar Mar 29 '22 17:03 beorn7

We want a way to export all metrics so that it could be easily seen by a consumer which metrics are available.

Perhaps we would need to implement a custom Register that wraps the DefaultRegisterer ?

samsondav avatar Mar 29 '22 20:03 samsondav

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 Oct 16 '22 05:10 stale[bot]

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

stale[bot] avatar Jan 21 '23 22:01 stale[bot]