Skip to content

Commit 92155c2

Browse files
committed
api: add markers for metrics to api types
1 parent 31ea0af commit 92155c2

File tree

16 files changed

+179
-0
lines changed

16 files changed

+179
-0
lines changed

api/addons/v1beta1/clusterresourceset_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ type ClusterResourceSetV1Beta2Status struct {
135135
// +listType=map
136136
// +listMapKey=type
137137
// +kubebuilder:validation:MaxItems=32
138+
// +Metrics:stateset:name="status_condition",help="The condition of a clusterresourceset.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
139+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a clusterresourceset.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
138140
Conditions []metav1.Condition `json:"conditions,omitempty"`
139141
}
140142

@@ -172,6 +174,10 @@ func (m *ClusterResourceSet) SetV1Beta2Conditions(conditions []metav1.Condition)
172174

173175
// ClusterResourceSet is the Schema for the clusterresourcesets API.
174176
// For advanced use cases an add-on provider should be used instead.
177+
// +Metrics:gvk:namePrefix="capi_clusterresourceset"
178+
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
179+
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
180+
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
175181
type ClusterResourceSet struct {
176182
metav1.TypeMeta `json:",inline"`
177183
// metadata is the standard object's metadata.

api/bootstrap/kubeadm/v1beta1/kubeadmconfig_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ type KubeadmConfigV1Beta2Status struct {
502502
// +listType=map
503503
// +listMapKey=type
504504
// +kubebuilder:validation:MaxItems=32
505+
// +Metrics:stateset:name="status_condition",help="The condition of a kubeadmconfig.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
506+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a kubeadmconfig.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
505507
Conditions []metav1.Condition `json:"conditions,omitempty"`
506508
}
507509

@@ -513,11 +515,20 @@ type KubeadmConfigV1Beta2Status struct {
513515
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of KubeadmConfig"
514516

515517
// KubeadmConfig is the Schema for the kubeadmconfigs API.
518+
// +Metrics:gvk:namePrefix="capi_kubeadmconfig"
519+
// +Metrics:labelFromPath:name="name",JSONPath=.metadata.name
520+
// +Metrics:labelFromPath:name="namespace",JSONPath=.metadata.namespace
521+
// +Metrics:labelFromPath:name="uid",JSONPath=.metadata.uid
522+
// +Metrics:labelFromPath:name="cluster_name",JSONPath=.metadata.labels.cluster\.x-k8s\.io/cluster-name
523+
// +Metrics:info:name="info",help="Information about a kubeadmconfig.",labelsFromPath={name:.metadata.name}
516524
type KubeadmConfig struct {
517525
metav1.TypeMeta `json:",inline"`
518526
// metadata is the standard object's metadata.
519527
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
520528
// +optional
529+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
530+
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the kubeadmconfig is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
531+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
521532
metav1.ObjectMeta `json:"metadata,omitempty"`
522533

523534
// spec is the desired state of KubeadmConfig.

api/controlplane/kubeadm/v1beta1/kubeadm_control_plane_types.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type KubeadmControlPlaneSpec struct {
8383
// odd numbers are permitted, as per [etcd best practice](https://etcd.io/docs/v3.3.12/faq/#why-an-odd-number-of-cluster-members).
8484
// This is a pointer to distinguish between explicit zero and not specified.
8585
// +optional
86+
// +Metrics:gauge:name="spec_replicas",help="The number of desired machines for a kubeadmcontrolplane."
8687
Replicas *int32 `json:"replicas,omitempty"`
8788

8889
// version defines the desired Kubernetes version.
@@ -214,6 +215,7 @@ type RollingUpdate struct {
214215
// Example: when this is set to 1, the control plane can be scaled
215216
// up immediately when the rolling update starts.
216217
// +optional
218+
// +Metrics:gauge:name="spec_strategy_rollingupdate_max_surge",help="Maximum number of replicas that can be scheduled above the desired number of replicas during a rolling update of a kubeadmcontrolplane."
217219
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
218220
}
219221

@@ -295,6 +297,7 @@ type KubeadmControlPlaneStatus struct {
295297
// replicas is the total number of non-terminated machines targeted by this control plane
296298
// (their labels match the selector).
297299
// +optional
300+
// +Metrics:gauge:name="status_replicas",help="The number of replicas per kubeadmcontrolplane.",nilIsZero=true
298301
Replicas int32 `json:"replicas"`
299302

300303
// version represents the minimum Kubernetes version for the control plane machines
@@ -307,10 +310,12 @@ type KubeadmControlPlaneStatus struct {
307310
// updatedReplicas is the total number of non-terminated machines targeted by this control plane
308311
// that have the desired template spec.
309312
// +optional
313+
// +Metrics:gauge:name="status_replicas_updated",help="The number of updated replicas per kubeadmcontrolplane.",nilIsZero=true
310314
UpdatedReplicas int32 `json:"updatedReplicas"`
311315

312316
// readyReplicas is the total number of fully running and ready control plane machines.
313317
// +optional
318+
// +Metrics:gauge:name="status_replicas_ready",help="The number of ready replicas per kubeadmcontrolplane.",nilIsZero=true
314319
ReadyReplicas int32 `json:"readyReplicas"`
315320

316321
// unavailableReplicas is the total number of unavailable machines targeted by this control plane.
@@ -322,6 +327,7 @@ type KubeadmControlPlaneStatus struct {
322327
// Deprecated: This field is deprecated and is going to be removed when support for v1beta1 will be dropped. Please see https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20240916-improve-status-in-CAPI-resources.md for more details.
323328
//
324329
// +optional
330+
// +Metrics:gauge:name="status_replicas_unavailable",help="The number of unavailable replicas per kubeadmcontrolplane.",nilIsZero=true
325331
UnavailableReplicas int32 `json:"unavailableReplicas"`
326332

327333
// initialized denotes that the KubeadmControlPlane API Server is initialized and thus
@@ -386,6 +392,8 @@ type KubeadmControlPlaneV1Beta2Status struct {
386392
// +listType=map
387393
// +listMapKey=type
388394
// +kubebuilder:validation:MaxItems=32
395+
// +Metrics:stateset:name="status_condition",help="The condition of a kubeadmcontrolplane.",labelName="status",JSONPath=".status",list={"True","False","Unknown"},labelsFromPath={"type":".type"}
396+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a kubeadmcontrolplane.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
389397
Conditions []metav1.Condition `json:"conditions,omitempty"`
390398

391399
// readyReplicas is the number of ready replicas for this KubeadmControlPlane. A machine is considered ready when Machine's Ready condition is true.
@@ -438,11 +446,20 @@ type LastRemediationStatus struct {
438446
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=".spec.version",description="Kubernetes version associated with this control plane"
439447

440448
// KubeadmControlPlane is the Schema for the KubeadmControlPlane API.
449+
// +Metrics:gvk:namePrefix="capi_kubeadmcontrolplane"
450+
// +Metrics:labelFromPath:name="cluster_name",JSONPath=.metadata.ownerReferences.\[kind=Cluster\].name
451+
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
452+
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
453+
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
454+
// +Metrics:info:name="info",help="Information about a kubeadmcontrolplane.",labelsFromPath={version:".spec.version"}
441455
type KubeadmControlPlane struct {
442456
metav1.TypeMeta `json:",inline"`
443457
// metadata is the standard object's metadata.
444458
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
445459
// +optional
460+
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the kubeadmcontrolplane is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
461+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
462+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
446463
metav1.ObjectMeta `json:"metadata,omitempty"`
447464

448465
// spec is the desired state of KubeadmControlPlane.

api/core/v1beta1/cluster_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ const (
462462
type ClusterSpec struct {
463463
// paused can be used to prevent controllers from processing the Cluster and all its associated objects.
464464
// +optional
465+
// +Metrics:gauge:name="spec_paused",help="Whether the cluster is paused and any of its resources will not be processed by the controllers.",nilIsZero=true
465466
Paused bool `json:"paused,omitempty"`
466467

467468
// clusterNetwork represents the cluster network configuration.
@@ -970,6 +971,7 @@ type ClusterStatus struct {
970971
// phase represents the current phase of cluster actuation.
971972
// +optional
972973
// +kubebuilder:validation:Enum=Pending;Provisioning;Provisioned;Deleting;Failed;Unknown
974+
// +Metrics:stateset:name="status_phase",help="The clusters current phase.",labelName="phase",list={"Pending","Provisioning","Provisioned","Deleting","Failed","Unknown"}
973975
Phase string `json:"phase,omitempty"`
974976

975977
// infrastructureReady is the state of the infrastructure provider.
@@ -1008,6 +1010,8 @@ type ClusterV1Beta2Status struct {
10081010
// +listType=map
10091011
// +listMapKey=type
10101012
// +kubebuilder:validation:MaxItems=32
1013+
// +Metrics:stateset:name="status_condition",help="The condition of a cluster.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
1014+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a cluster.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
10111015
Conditions []metav1.Condition `json:"conditions,omitempty"`
10121016

10131017
// controlPlane groups all the observations about Cluster's ControlPlane current state.
@@ -1126,11 +1130,18 @@ func (v APIEndpoint) String() string {
11261130
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.topology.version",description="Kubernetes version associated with this Cluster"
11271131

11281132
// Cluster is the Schema for the clusters API.
1133+
// +Metrics:gvk:namePrefix="capi_cluster"
1134+
// +Metrics:labelFromPath:name="name",JSONPath=.metadata.name
1135+
// +Metrics:labelFromPath:name="namespace",JSONPath=.metadata.namespace
1136+
// +Metrics:labelFromPath:name="uid",JSONPath=.metadata.uid
1137+
// +Metrics:info:name="info",help="Information about a cluster.",labelsFromPath={topology_version:".spec.topology.version",topology_class:".spec.topology.class",control_plane_endpoint_host:".spec.controlPlaneEndpoint.host",control_plane_endpoint_port:".spec.controlPlaneEndpoint.port",control_plane_reference_kind:".spec.controlPlaneRef.kind",control_plane_reference_name:".spec.controlPlaneRef.name",infrastructure_reference_kind:".spec.infrastructureRef.kind",infrastructure_reference_name:".spec.infrastructureRef.name"}
11291138
type Cluster struct {
11301139
metav1.TypeMeta `json:",inline"`
11311140
// metadata is the standard object's metadata.
11321141
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
11331142
// +optional
1143+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
1144+
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the cluster is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
11341145
metav1.ObjectMeta `json:"metadata,omitempty"`
11351146

11361147
// spec is the desired state of Cluster.

api/core/v1beta1/clusterclass_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,19 @@ const (
7171
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ClusterClass"
7272

7373
// ClusterClass is a template which can be used to create managed topologies.
74+
// +Metrics:gvk:namePrefix="capi_clusterclass"
75+
// +Metrics:labelFromPath:name="name",JSONPath=.metadata.name
76+
// +Metrics:labelFromPath:name="namespace",JSONPath=.metadata.namespace
77+
// +Metrics:labelFromPath:name="uid",JSONPath=.metadata.uid
78+
// +Metrics:info:name="info",help="Information about a clusterclass.",labelsFromPath={name:.metadata.name}
7479
type ClusterClass struct {
7580
metav1.TypeMeta `json:",inline"`
7681
// metadata is the standard object's metadata.
7782
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
7883
// +optional
84+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
85+
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the clusterclass is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
86+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
7987
metav1.ObjectMeta `json:"metadata,omitempty"`
8088

8189
// spec is the desired state of ClusterClass.
@@ -1165,6 +1173,8 @@ type ClusterClassV1Beta2Status struct {
11651173
// +listType=map
11661174
// +listMapKey=type
11671175
// +kubebuilder:validation:MaxItems=32
1176+
// +Metrics:stateset:name="status_condition",help="The condition of a clusterclass.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
1177+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a clusterclass.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
11681178
Conditions []metav1.Condition `json:"conditions,omitempty"`
11691179
}
11701180

api/core/v1beta1/machine_types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ type MachineReadinessGate struct {
485485
type MachineStatus struct {
486486
// nodeRef will point to the corresponding Node if it exists.
487487
// +optional
488+
// +Metrics:info:name="status_noderef",help="Information about the node reference of a machine.",labelsFromPath={node_name:".name",node_uid:".uid"}
488489
NodeRef *corev1.ObjectReference `json:"nodeRef,omitempty"`
489490

490491
// nodeInfo is a set of ids/uuids to uniquely identify the node.
@@ -545,16 +546,19 @@ type MachineStatus struct {
545546
// addresses is a list of addresses assigned to the machine.
546547
// This field is copied from the infrastructure provider reference.
547548
// +optional
549+
// +Metrics:info:name="addresses",help="Address information about a machine.",labelsFromPath={address:".address",type:".type"}
548550
Addresses MachineAddresses `json:"addresses,omitempty"`
549551

550552
// phase represents the current phase of machine actuation.
551553
// +optional
552554
// +kubebuilder:validation:Enum=Pending;Provisioning;Provisioned;Running;Deleting;Deleted;Failed;Unknown
555+
// +Metrics:stateset:name="status_phase",help="The machines current phase.",labelName="phase",list={"Pending","Provisioning","Provisioned","Running","Deleting","Deleted","Failed","Unknown"}
553556
Phase string `json:"phase,omitempty"`
554557

555558
// certificatesExpiryDate is the expiry date of the machine certificates.
556559
// This value is only set for control plane machines.
557560
// +optional
561+
// +Metrics:gauge:name="status_certificatesexpirydate",help="Information about certificate expiration date of a control plane node.",nilIsZero=true
558562
CertificatesExpiryDate *metav1.Time `json:"certificatesExpiryDate,omitempty"`
559563

560564
// bootstrapReady is the state of the bootstrap provider.
@@ -596,6 +600,8 @@ type MachineV1Beta2Status struct {
596600
// +listType=map
597601
// +listMapKey=type
598602
// +kubebuilder:validation:MaxItems=32
603+
// +Metrics:stateset:name="status_condition",help="The condition of a machine.",labelName="status",JSONPath=".status",list={"True","False","Unknown"},labelsFromPath={"type":".type"}
604+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a machine.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
599605
Conditions []metav1.Condition `json:"conditions,omitempty"`
600606
}
601607

@@ -668,11 +674,20 @@ type Bootstrap struct {
668674
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version",description="Kubernetes version associated with this Machine"
669675

670676
// Machine is the Schema for the machines API.
677+
// +Metrics:gvk:namePrefix="capi_machine"
678+
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
679+
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
680+
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
681+
// +Metrics:labelFromPath:name="cluster_name",JSONPath=".spec.clusterName"
682+
// +Metrics:info:name="info",help="Information about a machine.",labelsFromPath={bootstrap_reference_kind:.spec.bootstrap.configRef.kind,bootstrap_reference_name:.spec.bootstrap.configRef.name,container_runtime_version:.status.nodeInfo.containerRuntimeVersion,control_plane_name:.metadata.labels.cluster\.x-k8s\.io/control-plane-name,failure_domain:.spec.failureDomain,infrastructure_reference_kind:.spec.infrastructureRef.kind,infrastructure_reference_name:.spec.infrastructureRef.name,kernel_version:.status.nodeInfo.kernelVersion,kube_proxy_version:.status.nodeInfo.kubeProxyVersion,kubelet_version:.status.nodeInfo.kubeletVersion,os_image:.status.nodeInfo.osImage,provider_id:.spec.providerID,version:.spec.version}
671683
type Machine struct {
672684
metav1.TypeMeta `json:",inline"`
673685
// metadata is the standard object's metadata.
674686
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
675687
// +optional
688+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
689+
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the machine is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
690+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
676691
metav1.ObjectMeta `json:"metadata,omitempty"`
677692

678693
// spec is the desired state of Machine.

0 commit comments

Comments
 (0)