stats

package
v3.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 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 stats defines the self-describing statistics payload a service can expose through its `stats` invocation, and the Reporter capability a driver implements to produce it.

A service whose manager implements Reporter registers the "stats" invocation; the stats prometheus collector (pkg/prom/stats) discovers those services through the registry and turns their payloads into metrics. The payload fully describes its metrics (names, kinds, labels), so new services need no collector changes.

Counters derived from creation-time row counts are monotonic as long as rows are soft-deleted; a hard-delete cleanup shows up in Prometheus as a counter reset.

Index

Constants

View Source
const (
	KindGauge   = "gauge"
	KindCounter = "counter"
)

Metric kinds.

View Source
const Invocation = "stats"

Invocation is the conventional invocation name under which services expose their statistics.

Variables

This section is empty.

Functions

func NewInvokeSet

func NewInvokeSet(manager any) *invoke.Set

NewInvokeSet returns an invocation set exposing the "stats" invocation when the manager implements Reporter, and an empty set otherwise. A service embeds the returned set to become invokable, so the capability of its driver decides whether it advertises statistics.

Types

type Metric

type Metric struct {
	Name string `json:"name"`
	Help string `json:"help,omitempty"`
	// Kind is KindGauge or KindCounter.
	Kind string `json:"kind"`
	// Samples are plain samples.
	Samples []Sample `json:"samples,omitempty"`
	// OwnerSamples are per-owner aggregates. The collector folds them by
	// the owner attributes available at the site (or into plain totals);
	// they are never exposed as per-owner series.
	OwnerSamples []OwnerSample `json:"owner_samples,omitempty"`
}

Metric is one metric family. Name carries the subject only — the collector prefixes the configured namespace and appends the Prometheus-conventional `_total` suffix to counters.

type OwnerSample

type OwnerSample struct {
	Owner  string            `json:"owner"`
	Labels map[string]string `json:"labels,omitempty"`
	Value  float64           `json:"value"`
}

OwnerSample is one per-owner value with an optional label set.

type Payload

type Payload struct {
	// Metrics are the self-described metric families.
	Metrics []Metric `json:"metrics"`
}

Payload is the return value of a "stats" invocation.

func FromJSON

func FromJSON(data []byte) (*Payload, error)

FromJSON parses a payload from an invocation's JSON result and validates it.

func (*Payload) Result

func (p *Payload) Result() (invoke.Result, error)

Result validates the payload and converts it to an invoke.Result (the JSON-friendly map an invocation returns).

func (*Payload) Validate

func (p *Payload) Validate() error

Validate checks the payload is well formed: legal metric and label names and known kinds.

type Reporter

type Reporter interface {
	Stats(ctx context.Context) (*Payload, error)
}

Reporter is the capability a manager (driver) implements to expose statistics. Services detect it by type assertion and register the "stats" invocation only when it holds.

type Sample

type Sample struct {
	Labels map[string]string `json:"labels,omitempty"`
	Value  float64           `json:"value"`
}

Sample is one value with its label set.

Jump to

Keyboard shortcuts

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