metrics

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 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

Overview

Package metrics holds Dilion's Prometheus instruments: the HTTP surface, the database pools and the privacy workers.

Label cardinality is kept independent of the number of instances everywhere except the pool gauges. A multi-tenant deployment may serve thousands of instances (one per workspace), and an instance label on the request histograms would multiply every route by that number; a pool, on the other hand, is a per-instance resource whose exhaustion has to be traced to its instance. That label is `instance_id`, because Prometheus reserves `instance` for the scraped target and would rename ours.

Every method is safe on a nil *Metrics, so components built without metrics (tests, tools) need no guard.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

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

Metrics is the set of instruments one Server records into.

func New

func New(o Options) (*Metrics, error)

New registers the instruments. It fails only when the registry already holds collectors of the same names (two Servers sharing one registry).

func (*Metrics) Delivery

func (m *Metrics) Delivery(outcome string)

Delivery records the outcome of one delivery attempt: completed, retry or dead.

func (*Metrics) Handler

func (m *Metrics) Handler() http.Handler

Handler serves the registry in the Prometheus exposition format.

func (*Metrics) Middleware

func (m *Metrics) Middleware(next http.Handler) http.Handler

Middleware records every request. Install it on the chi router itself (r.Use), so the matched route pattern is known once next returns — the pattern, not the URL path, is the label, so user ids and tokens in paths never become series — and ahead of middleware.Recoverer, so a panic is counted as the 500 the recoverer writes.

func (*Metrics) Registry

func (m *Metrics) Registry() *prometheus.Registry

Registry is the registry the instruments live in.

func (*Metrics) WorkerTick

func (m *Metrics) WorkerTick(worker string, d time.Duration, err error)

WorkerTick records one privacy worker tick.

type Options

type Options struct {
	// Registry receives every collector. nil creates a private registry that
	// also carries the Go runtime and process collectors; a caller-supplied
	// registry is assumed to have those already.
	Registry *prometheus.Registry
	// Version is reported by dilion_build_info.
	Version string
	// Pools feeds the dilion_db_pool_* gauges; nil reports none.
	Pools PoolSource
}

Options configure New.

type PoolSource

type PoolSource func(ctx context.Context) (map[string]*pgxpool.Pool, error)

PoolSource lists the pools to report, keyed by instance id. It is called on every scrape with a bounded context.

Jump to

Keyboard shortcuts

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