Documentation
¶
Overview ¶
Package lazy provides lazy-registering Prometheus metric wrappers.
Metrics are declared as package-level globals (like promauto) but don't register until first use. Each service calls SetRegistry at startup to control where metrics end up. Only metrics that are actually used by a service get registered to that service's registry.
Usage:
// Declare globally — same feel as promauto:
var RequestsTotal = lazy.NewCounterVec(prometheus.CounterOpts{
Namespace: "app",
Subsystem: "api",
Name: "requests_total",
}, []string{"method", "status"})
// In service startup (one line):
reg := prometheus.NewRegistry()
lazy.SetRegistry(reg)
// When code calls RequestsTotal.WithLabelValues("GET", "200").Inc(),
// it registers to the service's registry on first use. If the service
// never touches this metric, it never registers — zero pollution.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetRegistry ¶
func SetRegistry(reg *prometheus.Registry)
SetRegistry sets the registry that all lazy metrics will register to on first use. Must be called before any metric is used.
First call wins: subsequent calls are silent no-ops. Production binaries only call this once per process, so the idempotence is there to support in-process multi-node integration tests (e.g. svc/api/integration), where several api.Run goroutines share a single process and therefore a single lazy registry. Metric values from those nodes are aggregated rather than isolated, which is fine because those tests don't assert on metric state.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a lazy-registering prometheus.Counter.
func NewCounter ¶
func NewCounter(opts prometheus.CounterOpts) *Counter
type CounterVec ¶
type CounterVec struct {
// contains filtered or unexported fields
}
CounterVec is a lazy-registering prometheus.CounterVec.
func NewCounterVec ¶
func NewCounterVec(opts prometheus.CounterOpts, labels []string) *CounterVec
func (*CounterVec) With ¶
func (c *CounterVec) With(labels prometheus.Labels) prometheus.Counter
func (*CounterVec) WithLabelValues ¶
func (c *CounterVec) WithLabelValues(lvs ...string) prometheus.Counter
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a lazy-registering prometheus.Gauge.
func NewGauge ¶
func NewGauge(opts prometheus.GaugeOpts) *Gauge
type GaugeVec ¶
type GaugeVec struct {
// contains filtered or unexported fields
}
GaugeVec is a lazy-registering prometheus.GaugeVec.
func NewGaugeVec ¶
func NewGaugeVec(opts prometheus.GaugeOpts, labels []string) *GaugeVec
func (*GaugeVec) With ¶
func (g *GaugeVec) With(labels prometheus.Labels) prometheus.Gauge
func (*GaugeVec) WithLabelValues ¶
func (g *GaugeVec) WithLabelValues(lvs ...string) prometheus.Gauge
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
Histogram is a lazy-registering prometheus.Histogram.
func NewHistogram ¶
func NewHistogram(opts prometheus.HistogramOpts) *Histogram
type HistogramVec ¶
type HistogramVec struct {
// contains filtered or unexported fields
}
HistogramVec is a lazy-registering prometheus.HistogramVec.
func NewHistogramVec ¶
func NewHistogramVec(opts prometheus.HistogramOpts, labels []string) *HistogramVec
func (*HistogramVec) With ¶
func (h *HistogramVec) With(labels prometheus.Labels) prometheus.Observer
func (*HistogramVec) WithLabelValues ¶
func (h *HistogramVec) WithLabelValues(lvs ...string) prometheus.Observer