metrics

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const Namespace = "controller_sharding"

Variables

View Source
var (
	// AssignmentsTotal is a prometheus counter metric which holds the total number of shard assignments by the sharder
	// webhook per ControllerRing and GroupResource.
	// It has a label which refers to the ControllerRing and two labels which refer to the object's GroupResource.
	AssignmentsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace,
		Name:      "assignments_total",
		Help:      "Total number of shard assignments by the sharder webhook per ControllerRing and GroupResource",
	}, []string{"controllerring", "group", "resource"})

	// MovementsTotal is a prometheus counter metric which holds the total number of shard movements triggered by the
	// sharder controller per ControllerRing and GroupResource.
	// It has a label which refers to the ControllerRing and two labels which refer to the object's GroupResource.
	MovementsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace,
		Name:      "movements_total",
		Help:      "Total number of shard movements triggered by the sharder controller per ControllerRing and GroupResource",
	}, []string{"controllerring", "group", "resource"})

	// DrainsTotal is a prometheus counter metric which holds the total number of shard drains triggered by the sharder
	// controller per ControllerRing and GroupResource.
	// It has a label which refers to the ControllerRing and two labels which refer to the object's GroupResource.
	DrainsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace,
		Name:      "drains_total",
		Help:      "Total number of shard drains triggered by the sharder controller per ControllerRing and GroupResource",
	}, []string{"controllerring", "group", "resource"})

	// RingCalculationsTotal is a prometheus counter metric which holds the total
	// number of hash ring calculations per ControllerRing.
	// It has a label which refers to the ControllerRing.
	RingCalculationsTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
		Namespace: Namespace,
		Name:      "ring_calculations_total",
		Help:      "Total number of hash ring calculations per ControllerRing",
	}, []string{"controllerring"})
)
View Source
var ControllerRingExporter = exporter.Exporter[*shardingv1alpha1.ControllerRing, *shardingv1alpha1.ControllerRingList]{
	Namespace: Namespace,
	Subsystem: "controllerring",

	StaticLabelKeys: []string{"controllerring", "uid"},
	GenerateStaticLabelValues: func(controllerRing *shardingv1alpha1.ControllerRing) []string {
		return []string{controllerRing.Name, string(controllerRing.UID)}
	},

	Metrics: []exporter.Metric[*shardingv1alpha1.ControllerRing]{
		{
			Name: "metadata_generation",
			Help: "The generation of a ControllerRing",

			Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) {
				ch <- prometheus.MustNewConstMetric(
					desc,
					prometheus.GaugeValue,
					float64(controllerRing.Generation),
					staticLabelValues...,
				)
			},
		},
		{
			Name: "observed_generation",
			Help: "The latest generation observed by the ControllerRing controller",

			Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) {
				ch <- prometheus.MustNewConstMetric(
					desc,
					prometheus.GaugeValue,
					float64(controllerRing.Status.ObservedGeneration),
					staticLabelValues...,
				)
			},
		},
		{
			Name: "status_shards",
			Help: "The ControllerRing's total number of shards observed by the ControllerRing controller",

			Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) {
				ch <- prometheus.MustNewConstMetric(
					desc,
					prometheus.GaugeValue,
					float64(controllerRing.Status.Shards),
					staticLabelValues...,
				)
			},
		},
		{
			Name: "status_available_shards",
			Help: "The ControllerRing's number of available shards observed by the ControllerRing controller",

			Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) {
				ch <- prometheus.MustNewConstMetric(
					desc,
					prometheus.GaugeValue,
					float64(controllerRing.Status.AvailableShards),
					staticLabelValues...,
				)
			},
		},
	},
}
View Source
var ShardExporter = exporter.Exporter[*coordinationv1.Lease, *coordinationv1.LeaseList]{
	Namespace: Namespace,
	Subsystem: "shard",

	ListOptions: []client.ListOption{client.HasLabels{shardingv1alpha1.LabelControllerRing}},

	StaticLabelKeys: []string{"namespace", "shard", "controllerring"},
	GenerateStaticLabelValues: func(lease *coordinationv1.Lease) []string {
		return []string{lease.Namespace, lease.Name, lease.Labels[shardingv1alpha1.LabelControllerRing]}
	},

	Metrics: []exporter.Metric[*coordinationv1.Lease]{
		{
			Name:      "info",
			Help:      "Information about a shard",
			LabelKeys: []string{"uid"},

			Generate: func(desc *prometheus.Desc, lease *coordinationv1.Lease, staticLabelValues []string, ch chan<- prometheus.Metric) {
				ch <- prometheus.MustNewConstMetric(
					desc,
					prometheus.GaugeValue,
					1,
					append(staticLabelValues, string(lease.UID))...,
				)
			},
		},
		{
			Name:      "state",
			Help:      "The shard's current state observed by the shardlease controller",
			LabelKeys: []string{"state"},

			Generate: exporter.GenerateStateSet[*coordinationv1.Lease](
				exporter.KnownStatesStringer(leases.KnownShardStates), ptr.To(leases.Unknown.String()),
				func(lease *coordinationv1.Lease) string {
					return lease.Labels[shardingv1alpha1.LabelState]
				},
			),
		},
	},
}

Functions

func AddToManager

func AddToManager(mgr manager.Manager) error

AddToManager adds all metrics exporters for sharding objects to the manager.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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