metrics

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package metrics is Atlas's Prometheus exposition: an owned registry, the naming conventions every Atlas metric follows, and the HTTP handler that serves them (ADR-0142).

Why an owned registry

Nothing here touches prometheus.DefaultRegisterer. A package-level default is global mutable state shared with every library in the process: it makes what an operator scrapes depend on the import graph, and it makes tests order-dependent. An owned registry means the exported set is exactly what Atlas registered, and a test can scrape a server without reaching through a global. Go-runtime and process collectors are opt-in for the same reason — what appears at /metrics should be a decision.

The two rules

**Bounded cardinality.** A label's values must be fixed by the code, not by the data. Never label by instance key, job key, correlation key, process id, element id, URL, or any other value an operator or a model can invent: one such label turns a metric into unboundedly many time series. A per-definition breakdown is a query over the API, which can paginate; a scrape target can only fall over.

**No allocation on the hot path.** A labeled metric is resolved to its concrete child once, when the registry is built, and stored as a field; the engine's batch loop then touches a prometheus.Counter, never a *Vec — no map lookup, no label slice, no allocation (invariant I1). The proof is a benchmark, not a review.

Index

Constants

View Source
const Namespace = "atlas"

Namespace prefixes every Atlas metric name, so a scrape shared with other exporters stays unambiguous.

Variables

This section is empty.

Functions

func BuildInfo

func BuildInfo(version, revision string) prometheus.Collector

BuildInfo is the conventional single-series metric carrying the running build, so a dashboard can correlate a graph with the binary that produced it. The label values are fixed at construction — one series, forever.

Types

type Registry

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

Registry owns the Prometheus registry Atlas exports and the handler that serves it.

func NewRegistry

func NewRegistry() *Registry

NewRegistry builds an empty registry. It deliberately registers no Go-runtime or process collectors: a caller that wants them adds them explicitly.

func (*Registry) Gather

func (r *Registry) Gather() ([]*dto.MetricFamily, error)

Gather returns the current metric families, for tests and for callers that want the numbers without going through HTTP.

func (*Registry) Handler

func (r *Registry) Handler() http.Handler

Handler serves the exposition. Collection errors are reported to the scraper rather than silently dropped: a gauge that cannot be read should show up as a broken scrape, not as a plausible number.

func (*Registry) Register

func (r *Registry) Register(cs ...prometheus.Collector) error

Register adds collectors to the registry. A duplicate or inconsistent registration is a programming error caught at construction, not at scrape time, so it is returned rather than swallowed.

Jump to

Keyboard shortcuts

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