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
- type Label
- type Metrics
- type Recorder
- func (r *Recorder) Count(name string, delta int64, labels ...Label)
- func (r *Recorder) Counter(name string, labels ...Label) int64
- func (r *Recorder) Gauge(name string, value float64, labels ...Label)
- func (r *Recorder) GaugeValue(name string, labels ...Label) (float64, bool)
- func (r *Recorder) Names() []string
- func (r *Recorder) Observations(name string, labels ...Label) int
- func (r *Recorder) Observe(name string, d time.Duration, labels ...Label)
Constants ¶
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.
const ( OutcomeOK = "ok" 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 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 (*Recorder) Counter ¶
Counter returns a counter's value, with labels in the order they were reported. An unreported counter is zero.
func (*Recorder) GaugeValue ¶
GaugeValue returns a gauge's last value and whether it was ever set.
func (*Recorder) Names ¶
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 ¶
Observations returns how many durations were observed.