metrics

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 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" patchStrategy:"merge" patchMergeKey:"type" 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)
}
Output:

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