prometheus/client_golang

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

samsondav opened this issue · 4 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.

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

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 ?

stale commented

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 commented

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