metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package metrics defines the small interface through which keyforge reports rates, failures and overdue keys, and the names it reports them under.

The core knows nothing of any metrics system: it calls a Metrics, which defaults to discarding. An adapter to Prometheus or OpenTelemetry is a few lines over this interface and belongs in the host or in a separate module, so that the core takes no dependency on either.

Labels are bounded by construction: the purpose is a configured name, and an outcome or reason is one of a small fixed set. A subject, a key identifier or an error message is never a label.

Index

Constants

View Source
const (
	// Operations is the count of data-path operations, labelled op, purpose and
	// outcome.
	Operations = "keyforge_operations_total"
	// OperationDuration is how long they took, labelled op and purpose.
	OperationDuration = "keyforge_operation_duration"
	// CacheLookups counts unwrapped-key cache lookups, labelled cache and
	// result (hit or miss).
	CacheLookups = "keyforge_cache_lookups_total"
	// EpochAdvances counts new data key epochs, labelled purpose and reason
	// (first, cap, age, not_active, manual).
	EpochAdvances = "keyforge_epoch_advances_total"
	// Rotations counts KEK rotations, labelled purpose and outcome.
	Rotations = "keyforge_kek_rotations_total"
	// RewrappedKeys counts data keys moved to a new KEK version, labelled
	// outcome (moved, skipped, failed).
	RewrappedKeys = "keyforge_rewrapped_keys_total"
	// RotationOverdue is how many seconds a KEK rotation is past due, labelled
	// purpose. It is zero when nothing is overdue.
	RotationOverdue = "keyforge_kek_rotation_overdue_seconds"
	// JobsStarted counts jobs the scheduler started, labelled kind.
	JobsStarted = "keyforge_jobs_started_total"
	// JobsFailed counts jobs that failed, labelled kind.
	JobsFailed = "keyforge_jobs_failed_total"
	// JobsWaiting is how many due jobs a tick held back, a gauge.
	JobsWaiting = "keyforge_jobs_waiting"
	// JobsInFlight is how many due jobs already had a run, a gauge.
	JobsInFlight = "keyforge_jobs_in_flight"
)

Names of the metrics keyforge reports, in the Prometheus convention.

View Source
const (
	OutcomeOK             = "ok"
	OutcomeUnavailable    = "unavailable"
	OutcomeUnusable       = "unusable"
	OutcomeAuthentication = "authentication"
	OutcomeInvalid        = "invalid"
	OutcomeRefused        = "refused"
	OutcomeShredded       = "shredded"
	OutcomeError          = "error"
)

Outcomes of an operation.

Variables

This section is empty.

Functions

This section is empty.

Types

type Label

type Label struct {
	Key, Value string
}

Label is one dimension of a metric.

func L

func L(key, value string) Label

L returns a label.

type Metrics

type Metrics interface {
	// Count adds delta to a monotonically increasing counter.
	Count(name string, delta int64, labels ...Label)
	// Gauge sets a value that can go up and down.
	Gauge(name string, value float64, labels ...Label)
	// Observe records a duration, for a histogram or a summary.
	Observe(name string, d time.Duration, labels ...Label)
}

Metrics receives measurements. It must be safe for concurrent use and must not block: it is called on the data path.

var Discard Metrics = discard{}

Discard is a Metrics that drops every measurement.

type Recorder

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

Recorder is a Metrics that keeps what it was given, for tests and examples.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder returns an empty recorder.

func (*Recorder) Count

func (r *Recorder) Count(name string, delta int64, labels ...Label)

Count implements Metrics.

func (*Recorder) Counter

func (r *Recorder) Counter(name string, labels ...Label) int64

Counter returns a counter's value, with labels in the order they were reported. An unreported counter is zero.

func (*Recorder) Gauge

func (r *Recorder) Gauge(name string, value float64, labels ...Label)

Gauge implements Metrics.

func (*Recorder) GaugeValue

func (r *Recorder) GaugeValue(name string, labels ...Label) (float64, bool)

GaugeValue returns a gauge's last value and whether it was ever set.

func (*Recorder) Names

func (r *Recorder) Names() []string

Names returns every counter and gauge name and label set that was reported, so a test can check that no label carries something unbounded.

func (*Recorder) Observations

func (r *Recorder) Observations(name string, labels ...Label) int

Observations returns how many durations were observed.

func (*Recorder) Observe

func (r *Recorder) Observe(name string, d time.Duration, labels ...Label)

Observe implements Metrics.

Jump to

Keyboard shortcuts

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