metrics

package
v0.0.0-...-7040d0c Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 37

Documentation

Index

Constants

View Source
const (
	Namespace   = "operator"
	LabelGroup  = "group"
	LabelKind   = "kind"
	LabelType   = "type"
	LabelReason = "reason"
)

Variables

View Source
var (
	Group = Label{
		Name: LabelGroup,
		Help: "The API group of the object the metric describes, e.g. `karpenter.sh`.",
	}
	Kind = Label{
		Name: LabelKind,
		Help: "The Kind of the object the metric describes, e.g. `NodeClaim`.",
	}
	Type = Label{
		Name: LabelType,

		Help: "The type dimension. For status-condition metrics it is the status " +
			"condition type (e.g. `Ready`); for event metrics it is the Kubernetes " +
			"event type (`Normal` or `Warning`).",
	}
	Reason = Label{
		Name: LabelReason,
		Help: "The reason dimension. For status-condition metrics it is the condition " +
			"reason; for event metrics it is the Kubernetes event reason.",
	}
)

Shared operator metric dimensions. The label-name consts (LabelGroup, etc.) remain the values used in metric label-names slices so existing declarations compile unchanged; these Label vars carry the documentation keyed by the same name.

Functions

func RegisterClientMetrics

func RegisterClientMetrics(r prometheus.Registerer)

RegisterClientMetrics sets up the client latency and result metrics from client-go.

Types

type CounterMetric

type CounterMetric interface {
	Add(v float64, labels map[string]string)
	Inc(labels map[string]string)
	Delete(labels map[string]string)
	DeletePartialMatch(labels map[string]string)
	Reset()
	// Labels returns the dimensions the metric was declared with.
	Labels() []Label
	// Stage returns the metric's API stability.
	Stage() Stage
}

func NewMultiCounter

func NewMultiCounter(counters ...CounterMetric) CounterMetric

func NewPrometheusCounter

func NewPrometheusCounter(registry prometheus.Registerer, opts prometheus.CounterOpts, labels []Label, stage Stage) CounterMetric

type GaugeMetric

type GaugeMetric interface {
	Set(v float64, labels map[string]string)
	Delete(labels map[string]string)
	DeletePartialMatch(labels map[string]string)
	Reset()
	// Labels returns the dimensions the metric was declared with.
	Labels() []Label
	// Stage returns the metric's API stability.
	Stage() Stage
}

func NewMultiGauge

func NewMultiGauge(gauges ...GaugeMetric) GaugeMetric

func NewPrometheusGauge

func NewPrometheusGauge(registry prometheus.Registerer, opts prometheus.GaugeOpts, labels []Label, stage Stage) GaugeMetric

type Label

type Label struct {
	// Name is the Prometheus label name (the dimension key), e.g. "kind".
	Name string
	// Help is human-readable documentation for the dimension.
	Help string
	// Values, when non-empty, enumerates the stable set of values the dimension
	// can take, each with its own documentation. Every value's Name MUST be
	// sourced from a const, never a magic string.
	Values []Value
}

Label is the source-of-truth description of a Prometheus metric label (a "dimension"). Declaring dimensions as Labels lets a metrics documentation generator emit per-dimension help text and, where the set of possible values is known and stable, the list of values.

operatorpkg exports the type (and shared operator dimensions) so that both operatorpkg's own metrics and downstream projects (e.g. Karpenter) can describe their dimensions with a single, consistent type.

Conventions:

  • Describe a metric dimension with a Label; avoid a bare string literal in the metric's label-names slice where a documented Label already exists.
  • Values, when set, MUST be a list of consts, never magic strings.
  • Before adding a new Label, check whether an existing one already describes the dimension you need and reference it instead.

type LatencyAdapter

type LatencyAdapter struct {
	Metric ObservationMetric
}

LatencyAdapter implements LatencyMetric.

func (*LatencyAdapter) Observe

func (l *LatencyAdapter) Observe(_ context.Context, verb string, u url.URL, latency time.Duration)

Observe increments the request latency metric for the given verb/group/version/kind/subresource.

type MultiCounter

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

func (*MultiCounter) Add

func (mc *MultiCounter) Add(v float64, labels map[string]string)

func (*MultiCounter) Delete

func (mc *MultiCounter) Delete(labels map[string]string)

func (*MultiCounter) DeletePartialMatch

func (mc *MultiCounter) DeletePartialMatch(labels map[string]string)

func (*MultiCounter) Inc

func (mc *MultiCounter) Inc(labels map[string]string)

func (*MultiCounter) Labels

func (mc *MultiCounter) Labels() []Label

func (*MultiCounter) Reset

func (mc *MultiCounter) Reset()

func (*MultiCounter) Stage

func (mc *MultiCounter) Stage() Stage

type MultiGauge

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

func (*MultiGauge) Delete

func (mg *MultiGauge) Delete(labels map[string]string)

func (*MultiGauge) DeletePartialMatch

func (mg *MultiGauge) DeletePartialMatch(labels map[string]string)

func (*MultiGauge) Labels

func (mg *MultiGauge) Labels() []Label

func (*MultiGauge) Reset

func (mg *MultiGauge) Reset()

func (*MultiGauge) Set

func (mg *MultiGauge) Set(v float64, labels map[string]string)

func (*MultiGauge) Stage

func (mg *MultiGauge) Stage() Stage

type MultiObservation

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

func (*MultiObservation) Delete

func (mo *MultiObservation) Delete(labels map[string]string)

func (*MultiObservation) DeletePartialMatch

func (mo *MultiObservation) DeletePartialMatch(labels map[string]string)

func (*MultiObservation) Labels

func (mo *MultiObservation) Labels() []Label

func (*MultiObservation) Observe

func (mo *MultiObservation) Observe(v float64, labels map[string]string)

func (*MultiObservation) Reset

func (mo *MultiObservation) Reset()

func (*MultiObservation) Stage

func (mo *MultiObservation) Stage() Stage

type ObservationMetric

type ObservationMetric interface {
	Observe(v float64, labels map[string]string)
	Delete(labels map[string]string)
	DeletePartialMatch(labels map[string]string)
	Reset()
	// Labels returns the dimensions the metric was declared with.
	Labels() []Label
	// Stage returns the metric's API stability.
	Stage() Stage
}

func NewMultiObservation

func NewMultiObservation(observations ...ObservationMetric) ObservationMetric

func NewPrometheusHistogram

func NewPrometheusHistogram(registry prometheus.Registerer, opts prometheus.HistogramOpts, labels []Label, stage Stage) ObservationMetric

func NewPrometheusSummary

func NewPrometheusSummary(registry prometheus.Registerer, opts prometheus.SummaryOpts, labels []Label, stage Stage) ObservationMetric

type PrometheusCounter

type PrometheusCounter struct {
	*prometheus.CounterVec
	// contains filtered or unexported fields
}

func (*PrometheusCounter) Add

func (pc *PrometheusCounter) Add(v float64, labels map[string]string)

func (*PrometheusCounter) Delete

func (pc *PrometheusCounter) Delete(labels map[string]string)

func (*PrometheusCounter) DeletePartialMatch

func (pc *PrometheusCounter) DeletePartialMatch(labels map[string]string)

func (*PrometheusCounter) Inc

func (pc *PrometheusCounter) Inc(labels map[string]string)

func (*PrometheusCounter) Labels

func (pc *PrometheusCounter) Labels() []Label

func (*PrometheusCounter) Reset

func (pc *PrometheusCounter) Reset()

func (*PrometheusCounter) Stage

func (pc *PrometheusCounter) Stage() Stage

type PrometheusGauge

type PrometheusGauge struct {
	*prometheus.GaugeVec
	// contains filtered or unexported fields
}

func (*PrometheusGauge) Delete

func (pg *PrometheusGauge) Delete(labels map[string]string)

func (*PrometheusGauge) DeletePartialMatch

func (pg *PrometheusGauge) DeletePartialMatch(labels map[string]string)

func (*PrometheusGauge) Labels

func (pg *PrometheusGauge) Labels() []Label

func (*PrometheusGauge) Reset

func (pg *PrometheusGauge) Reset()

func (*PrometheusGauge) Set

func (pg *PrometheusGauge) Set(v float64, labels map[string]string)

func (*PrometheusGauge) Stage

func (pg *PrometheusGauge) Stage() Stage

type PrometheusHistogram

type PrometheusHistogram struct {
	*prometheus.HistogramVec
	// contains filtered or unexported fields
}

func (*PrometheusHistogram) Delete

func (ph *PrometheusHistogram) Delete(labels map[string]string)

func (*PrometheusHistogram) DeletePartialMatch

func (ph *PrometheusHistogram) DeletePartialMatch(labels map[string]string)

func (*PrometheusHistogram) Labels

func (ph *PrometheusHistogram) Labels() []Label

func (*PrometheusHistogram) Observe

func (ph *PrometheusHistogram) Observe(v float64, labels map[string]string)

func (*PrometheusHistogram) Reset

func (ph *PrometheusHistogram) Reset()

func (*PrometheusHistogram) Stage

func (ph *PrometheusHistogram) Stage() Stage

type PrometheusSummary

type PrometheusSummary struct {
	*prometheus.SummaryVec
	// contains filtered or unexported fields
}

func (*PrometheusSummary) Delete

func (ps *PrometheusSummary) Delete(labels map[string]string)

func (*PrometheusSummary) DeletePartialMatch

func (ps *PrometheusSummary) DeletePartialMatch(labels map[string]string)

func (*PrometheusSummary) Labels

func (ps *PrometheusSummary) Labels() []Label

func (*PrometheusSummary) Observe

func (ps *PrometheusSummary) Observe(v float64, labels map[string]string)

func (*PrometheusSummary) Reset

func (ps *PrometheusSummary) Reset()

func (*PrometheusSummary) Stage

func (ps *PrometheusSummary) Stage() Stage

type ResultAdapter

type ResultAdapter struct {
	Metric CounterMetric
}

func (*ResultAdapter) Increment

func (r *ResultAdapter) Increment(_ context.Context, code, method, _ string)

type Stage

type Stage string

Stage describes the API stability of a metric, mirroring the Kubernetes metric stability levels. Declaring it lets a metrics documentation generator surface which metrics are safe to depend on and which may still change.

const (
	// Alpha marks an experimental metric. Any aspect — its name, dimensions,
	// values, or the metric itself — may change or be removed without notice.
	Alpha Stage = "alpha"
	// Beta marks a metric that is fairly stable but not yet guaranteed. Additive
	// changes are expected, and breaking changes to its dimensions (renaming or
	// removing a dimension) are still permitted before it is promoted to GA.
	Beta Stage = "beta"
	// GA marks a stable metric that is safe to depend on. Only additive changes
	// are allowed: new dimensions may still be added, but existing dimensions are
	// not renamed or removed except through the usual deprecation process.
	GA Stage = "ga"
)

type Value

type Value struct {
	// Name is the dimension value. It MUST be sourced from a const, never a magic
	// string.
	Name string
	// Help is human-readable documentation for this value: what it means and,
	// where useful, why the dimension takes it.
	Help string
}

Value documents one of the stable values a metric dimension (Label) can take.

Jump to

Keyboard shortcuts

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