metrics

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation ΒΆ

Overview ΒΆ

Package metrics implements common prometheus metric collectors.

For any resource that implements the standard `metav1.Conditions` array in its status, `ConditionStatusCollector` will report metrics on how many objects have been in certain conditions, and for how long.

Index ΒΆ

Examples ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

This section is empty.

Functions ΒΆ

This section is empty.

Types ΒΆ

type ConditionStatusCollector ΒΆ

type ConditionStatusCollector[K pause.HasStatusConditions] struct {
	metrics.BaseStableCollector

	ObjectCount           *metrics.Desc
	ObjectConditionCount  *metrics.Desc
	ObjectTimeInCondition *metrics.Desc
	CollectorTime         *metrics.Desc
	CollectorErrors       *metrics.Desc
	// contains filtered or unexported fields
}

ConditionStatusCollector reports condition metrics for any type that implements a metav1.Condition list in the status.

func NewConditionStatusCollector ΒΆ

func NewConditionStatusCollector[K pause.HasStatusConditions](namespace string, subsystem string, resourceName string) *ConditionStatusCollector[K]

NewConditionStatusCollector creates a new ConditionStatusCollector, with flags for specifying how to generate the names of the metrics.

Example ΒΆ
package main

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/component-base/metrics/legacyregistry"

	"github.com/authzed/controller-idioms/conditions"
)

type MyObject struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	// this implements the conditions interface for MyObject, but note that
	// this is not supported by kube codegen at the moment (don't try to use
	// this in a real controller)
	conditions.StatusWithConditions[*MyObjectStatus] `json:"-"`
}
type MyObjectStatus struct {
	ObservedGeneration          int64 `json:"observedGeneration,omitempty" protobuf:"varint,3,opt,name=observedGeneration"`
	conditions.StatusConditions `json:"conditions,omitempty"         patchMergeKey:"type"                            patchStrategy:"merge" protobuf:"bytes,1,rep,name=conditions"`
}

func main() {
	databaseMetrics := NewConditionStatusCollector[*MyObject]("my_controller", "owned_objects", "myobjecttype")
	// register a listerbuilder for the object with:
	// databaseMetrics.AddListerBuilder()
	legacyregistry.CustomMustRegister(databaseMetrics)
}

func (*ConditionStatusCollector[K]) AddListerBuilder ΒΆ

func (c *ConditionStatusCollector[K]) AddListerBuilder(lb func() ([]K, error))

func (*ConditionStatusCollector[K]) CollectWithStability ΒΆ

func (c *ConditionStatusCollector[K]) CollectWithStability(ch chan<- metrics.Metric)

func (*ConditionStatusCollector[K]) DescribeWithStability ΒΆ

func (c *ConditionStatusCollector[K]) DescribeWithStability(ch chan<- *metrics.Desc)

Jump to

Keyboard shortcuts

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