lazy

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 4 Imported by: 0

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

func (*Counter) Add

func (c *Counter) Add(v float64)

func (*Counter) Inc

func (c *Counter) Inc()

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

func (*Gauge) Add

func (g *Gauge) Add(v float64)

func (*Gauge) Dec

func (g *Gauge) Dec()

func (*Gauge) Inc

func (g *Gauge) Inc()

func (*Gauge) Set

func (g *Gauge) Set(v float64)

func (*Gauge) Sub

func (g *Gauge) Sub(v float64)

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

func (*Histogram) Observe

func (h *Histogram) Observe(v float64)

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 (*HistogramVec) WithLabelValues

func (h *HistogramVec) WithLabelValues(lvs ...string) prometheus.Observer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL