metrics

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: AGPL-3.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultScrapeWaitTimeout = 60 * time.Second

DefaultScrapeWaitTimeout is the default upper bound for Provider.WaitForScrape when no explicit timeout is configured via WithScrapeWaitTimeout or METRICS_SCRAPE_WAIT_TIMEOUT.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*config)

Option configures Provider construction.

func WithMetricsAddr

func WithMetricsAddr(addr string) Option

WithMetricsAddr sets the TCP address for the Prometheus /metrics HTTP server (e.g. ":9090"). When not supplied, no HTTP server is started.

func WithScrapeWaitTimeout added in v0.0.6

func WithScrapeWaitTimeout(d time.Duration) Option

WithScrapeWaitTimeout sets the upper bound for Provider.WaitForScrape. When this option is not supplied at all, DefaultScrapeWaitTimeout is used. A non-positive value (e.g. 0) disables the gate: WaitForScrape returns nil immediately rather than blocking. Distinguishing "not provided" from "explicitly zero" lets operators short-circuit the wait via METRICS_SCRAPE_WAIT_TIMEOUT=0s without falling back to the default.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider exposes a Prometheus /metrics endpoint backed by a prometheus.Registry. Application code registers collectors against the registry via PrometheusRegisterer; the same registry serves /metrics. When the metrics address is empty, PrometheusRegisterer returns nil so downstream consumers (e.g. pkg/temporalclient) can detect "metrics off" and short-circuit to a noop, the HTTP server is not started, and Shutdown + WaitForScrape are safe no-ops.

func New

func New(opts ...Option) (*Provider, error)

New creates a Provider. When WithMetricsAddr is not supplied, the returned Provider has a nil registry, starts no HTTP server, and Shutdown + WaitForScrape are safe no-ops.

func NewFromEnv

func NewFromEnv(defaultAddr string) (*Provider, func(), error)

NewFromEnv creates a Provider using standard environment variables. METRICS_ADDR sets the Prometheus /metrics HTTP listen address; when unset, defaultAddr is used instead. Callers pick a default that does not collide with their peer binary on a shared host (the watcher and worker each pass their own value). Pass "" as defaultAddr to keep the endpoint disabled when METRICS_ADDR is unset. METRICS_SCRAPE_WAIT_TIMEOUT (Go duration string) bounds Provider.WaitForScrape.

The returned shutdown func must be deferred by the caller. It stops the metrics HTTP server with a 10-second deadline and writes any error to stderr.

func (*Provider) PrometheusRegisterer added in v0.0.6

func (p *Provider) PrometheusRegisterer() prometheus.Registerer

PrometheusRegisterer returns the Prometheus registry collectors should be registered against, or nil when the Provider is in no-op mode (no METRICS_ADDR). The same registry backs the /metrics endpoint when one is enabled. The nil return lets downstream consumers detect "metrics off" and short-circuit (e.g. pkg/temporalclient skips the tally→prom bridge).

The return type is the prometheus.Registerer interface; a nil *Registry is mapped to a nil interface so callers can use a plain `if reg == nil` check without falling into the typed-nil interface gotcha.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

Shutdown stops the metrics HTTP server, if one was started. It should be called before the process exits.

func (*Provider) WaitForScrape added in v0.0.6

func (p *Provider) WaitForScrape(ctx context.Context) error

WaitForScrape blocks until the /metrics HTTP handler serves a request after this call begins, the configured scrape-wait timeout elapses, or ctx is cancelled (whichever happens first). It returns nil immediately when no Prometheus HTTP server is configured or when the configured timeout is non-positive (gate explicitly disabled).

Intended use: invoke after process drain but before exporter shutdown so Prometheus has the opportunity to collect a final scrape covering end-of-lifecycle metrics. The HTTP server is left running for the duration of the wait. Callers should pass a non-cancelled parent context (typically context.Background()) — passing a SIGTERM-cancelled context defeats the gate.

Jump to

Keyboard shortcuts

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