Skip to content

Commit 08257fa

Browse files
committed
api: add markers for metrics to api types
1 parent be86b82 commit 08257fa

File tree

9 files changed

+141
-9
lines changed

9 files changed

+141
-9
lines changed

api/v1beta1/cluster_types.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
type ClusterSpec struct {
4747
// Paused can be used to prevent controllers from processing the Cluster and all its associated objects.
4848
// +optional
49+
// +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
4950
Paused bool `json:"paused,omitempty"`
5051

5152
// Cluster network configuration.
@@ -430,6 +431,7 @@ type ClusterStatus struct {
430431
// Phase represents the current phase of cluster actuation.
431432
// E.g. Pending, Running, Terminating, Failed etc.
432433
// +optional
434+
// +Metrics:stateset:name="status_phase",help="The clusters current phase.",labelName="phase",list={"Pending","Provisioning","Provisioned","Deleting","Failed","Unknown"}
433435
Phase string `json:"phase,omitempty"`
434436

435437
// InfrastructureReady is the state of the infrastructure provider.
@@ -446,6 +448,8 @@ type ClusterStatus struct {
446448

447449
// Conditions defines current service state of the cluster.
448450
// +optional
451+
// +Metrics:stateset:name="status_condition",help="The condition of a cluster.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
452+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition last transition time of a cluster.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
449453
Conditions Conditions `json:"conditions,omitempty"`
450454

451455
// ObservedGeneration is the latest generation observed by the controller.
@@ -514,8 +518,15 @@ func (v APIEndpoint) String() string {
514518
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.topology.version",description="Kubernetes version associated with this Cluster"
515519

516520
// Cluster is the Schema for the clusters API.
521+
// +Metrics:gvk:namePrefix="capi_cluster"
522+
// +Metrics:labelFromPath:name="name",JSONPath=.metadata.name
523+
// +Metrics:labelFromPath:name="namespace",JSONPath=.metadata.namespace
524+
// +Metrics:labelFromPath:name="uid",JSONPath=.metadata.uid
525+
// +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"}
517526
type Cluster struct {
518-
metav1.TypeMeta `json:",inline"`
527+
metav1.TypeMeta `json:",inline"`
528+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
529+
// +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:"."}
519530
metav1.ObjectMeta `json:"metadata,omitempty"`
520531

521532
Spec ClusterSpec `json:"spec,omitempty"`

api/v1beta1/clusterclass_types.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,16 @@ const ClusterClassKind = "ClusterClass"
3535
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ClusterClass"
3636

3737
// ClusterClass is a template which can be used to create managed topologies.
38+
// +Metrics:gvk:namePrefix="capi_clusterclass"
39+
// +Metrics:labelFromPath:name="name",JSONPath=.metadata.name
40+
// +Metrics:labelFromPath:name="namespace",JSONPath=.metadata.namespace
41+
// +Metrics:labelFromPath:name="uid",JSONPath=.metadata.uid
42+
// +Metrics:info:name="info",help="Information about a clusterclass.",labelsFromPath={name:.metadata.name}
3843
type ClusterClass struct {
39-
metav1.TypeMeta `json:",inline"`
44+
metav1.TypeMeta `json:",inline"`
45+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
46+
// +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:"."}
47+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
4048
metav1.ObjectMeta `json:"metadata,omitempty"`
4149

4250
Spec ClusterClassSpec `json:"spec,omitempty"`
@@ -890,6 +898,8 @@ type ClusterClassStatus struct {
890898

891899
// Conditions defines current observed state of the ClusterClass.
892900
// +optional
901+
// +Metrics:stateset:name="status_condition",help="The condition of a clusterclass.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
902+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition last transition time of a clusterclass.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
893903
Conditions Conditions `json:"conditions,omitempty"`
894904

895905
// ObservedGeneration is the latest generation observed by the controller.

api/v1beta1/machine_types.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ type MachineSpec struct {
142142
type MachineStatus struct {
143143
// NodeRef will point to the corresponding Node if it exists.
144144
// +optional
145+
// +Metrics:info:name="status_noderef",help="Information about the node reference of a machine.",labelsFromPath={node_name:".name",node_uid:".uid"}
145146
NodeRef *corev1.ObjectReference `json:"nodeRef,omitempty"`
146147

147148
// NodeInfo is a set of ids/uuids to uniquely identify the node.
@@ -194,16 +195,19 @@ type MachineStatus struct {
194195
// Addresses is a list of addresses assigned to the machine.
195196
// This field is copied from the infrastructure provider reference.
196197
// +optional
198+
// +Metrics:info:name="addresses",help="Address information about a machine.",labelsFromPath={address:".address",type:".type"}
197199
Addresses MachineAddresses `json:"addresses,omitempty"`
198200

199201
// Phase represents the current phase of machine actuation.
200202
// E.g. Pending, Running, Terminating, Failed etc.
201203
// +optional
204+
// +Metrics:stateset:name="status_phase",help="The machines current phase.",labelName="phase",list={"Pending","Provisioning","Provisioned","Running","Deleting","Deleted","Failed","Unknown"}
202205
Phase string `json:"phase,omitempty"`
203206

204207
// CertificatesExpiryDate is the expiry date of the machine certificates.
205208
// This value is only set for control plane machines.
206209
// +optional
210+
// +Metrics:gauge:name="status_certificatesexpirydate",help="Information about certificate expiration date of a control plane node.",nilIsZero=true
207211
CertificatesExpiryDate *metav1.Time `json:"certificatesExpiryDate,omitempty"`
208212

209213
// BootstrapReady is the state of the bootstrap provider.
@@ -220,6 +224,8 @@ type MachineStatus struct {
220224

221225
// Conditions defines current service state of the Machine.
222226
// +optional
227+
// +Metrics:stateset:name="status_condition",help="The condition of a machine.",labelName="status",JSONPath=".status",list={"True","False","Unknown"},labelsFromPath={"type":".type"}
228+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition last transition time of a machine.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
223229
Conditions Conditions `json:"conditions,omitempty"`
224230
}
225231

@@ -279,8 +285,17 @@ type Bootstrap struct {
279285
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version",description="Kubernetes version associated with this Machine"
280286

281287
// Machine is the Schema for the machines API.
288+
// +Metrics:gvk:namePrefix="capi_machine"
289+
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
290+
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
291+
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
292+
// +Metrics:labelFromPath:name="cluster_name",JSONPath=".spec.clusterName"
293+
// +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}
282294
type Machine struct {
283-
metav1.TypeMeta `json:",inline"`
295+
metav1.TypeMeta `json:",inline"`
296+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
297+
// +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:"."}
298+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
284299
metav1.ObjectMeta `json:"metadata,omitempty"`
285300

286301
Spec MachineSpec `json:"spec,omitempty"`

api/v1beta1/machinedeployment_types.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type MachineDeploymentSpec struct {
9999
// * An existing MachineDeployment which initially wasn't controlled by the autoscaler
100100
// should be later controlled by the autoscaler
101101
// +optional
102+
// +Metrics:gauge:name="spec_replicas",help="The number of desired machines for a machinedeployment."
102103
Replicas *int32 `json:"replicas,omitempty"`
103104

104105
// RolloutAfter is a field to indicate a rollout should be performed
@@ -139,6 +140,7 @@ type MachineDeploymentSpec struct {
139140

140141
// Indicates that the deployment is paused.
141142
// +optional
143+
// +Metrics:gauge:name="spec_paused",help="Whether the machinedeployment is paused and any of its resources will not be processed by the controllers.",nilIsZero=true
142144
Paused bool `json:"paused,omitempty"`
143145

144146
// The maximum time in seconds for a deployment to make progress before it
@@ -193,6 +195,7 @@ type MachineRollingUpdateDeployment struct {
193195
// that the total number of machines available at all times
194196
// during the update is at least 70% of desired machines.
195197
// +optional
198+
// +Metrics:gauge:name="spec_strategy_rollingupdate_max_unavailable",help="Maximum number of unavailable replicas during a rolling update of a machinedeployment."
196199
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
197200

198201
// The maximum number of machines that can be scheduled above the
@@ -209,6 +212,7 @@ type MachineRollingUpdateDeployment struct {
209212
// be scaled up further, ensuring that total number of machines running
210213
// at any time during the update is at most 130% of desired machines.
211214
// +optional
215+
// +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 machinedeployment."
212216
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
213217

214218
// DeletePolicy defines the policy used by the MachineDeployment to identify nodes to delete when downscaling.
@@ -263,20 +267,24 @@ type MachineDeploymentStatus struct {
263267
// Total number of non-terminated machines targeted by this deployment
264268
// (their labels match the selector).
265269
// +optional
270+
// +Metrics:gauge:name="status_replicas",help="The number of replicas per machinedeployment.",nilIsZero=true
266271
Replicas int32 `json:"replicas"`
267272

268273
// Total number of non-terminated machines targeted by this deployment
269274
// that have the desired template spec.
270275
// +optional
276+
// +Metrics:gauge:name="status_replicas_updated",help="The number of updated replicas per machinedeployment.",nilIsZero=true
271277
UpdatedReplicas int32 `json:"updatedReplicas"`
272278

273279
// Total number of ready machines targeted by this deployment.
274280
// +optional
281+
// +Metrics:gauge:name="status_replicas_ready",help="The number of ready replicas per machinedeployment.",nilIsZero=true
275282
ReadyReplicas int32 `json:"readyReplicas"`
276283

277284
// Total number of available machines (ready for at least minReadySeconds)
278285
// targeted by this deployment.
279286
// +optional
287+
// +Metrics:gauge:name="status_replicas_available",help="The number of available replicas per machinedeployment.",nilIsZero=true
280288
AvailableReplicas int32 `json:"availableReplicas"`
281289

282290
// Total number of unavailable machines targeted by this deployment.
@@ -285,14 +293,18 @@ type MachineDeploymentStatus struct {
285293
// be machines that are running but not yet available or machines
286294
// that still have not been created.
287295
// +optional
296+
// +Metrics:gauge:name="status_replicas_unavailable",help="The number of unavailable replicas per machinedeployment.",nilIsZero=true
288297
UnavailableReplicas int32 `json:"unavailableReplicas"`
289298

290299
// Phase represents the current phase of a MachineDeployment (ScalingUp, ScalingDown, Running, Failed, or Unknown).
291300
// +optional
301+
// +Metrics:stateset:name="status_phase",help="The machinedeployments current phase.",labelName="phase",list={"ScalingUp","ScalingDown","Running","Failed","Unknown"}
292302
Phase string `json:"phase,omitempty"`
293303

294304
// Conditions defines current service state of the MachineDeployment.
295305
// +optional
306+
// +Metrics:stateset:name="status_condition",help="The condition of a machinedeployment.",labelName="status",JSONPath=".status",list={"True","False","Unknown"},labelsFromPath={"type":".type"}
307+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition last transition time of a machinedeployment.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
296308
Conditions Conditions `json:"conditions,omitempty"`
297309
}
298310

@@ -354,8 +366,17 @@ func (md *MachineDeploymentStatus) GetTypedPhase() MachineDeploymentPhase {
354366
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.template.spec.version",description="Kubernetes version associated with this MachineDeployment"
355367

356368
// MachineDeployment is the Schema for the machinedeployments API.
369+
// +Metrics:gvk:namePrefix="capi_machinedeployment"
370+
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
371+
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
372+
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
373+
// +Metrics:labelFromPath:name="cluster_name",JSONPath=".spec.clusterName"
374+
// +Metrics:info:name="info",help="Information about a machinedeployment.",labelsFromPath={bootstrap_reference_kind:.spec.template.spec.bootstrap.configRef.kind,bootstrap_reference_name:.spec.template.spec.bootstrap.configRef.name,infrastructure_reference_kind:.spec.template.spec.infrastructureRef.kind,infrastructure_reference_name:.spec.template.spec.infrastructureRef.name,version:.spec.template.spec.version}
357375
type MachineDeployment struct {
358-
metav1.TypeMeta `json:",inline"`
376+
metav1.TypeMeta `json:",inline"`
377+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
378+
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the machinedeployment is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
379+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
359380
metav1.ObjectMeta `json:"metadata,omitempty"`
360381

361382
Spec MachineDeploymentSpec `json:"spec,omitempty"`

api/v1beta1/machinehealthcheck_types.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,20 @@ type MachineHealthCheckStatus struct {
123123
// total number of machines counted by this machine health check
124124
// +kubebuilder:validation:Minimum=0
125125
// +optional
126+
// +Metrics:gauge:name="status_expected_machines",help="Total number of machines counted by this machinehealthcheck.",nilIsZero=true
126127
ExpectedMachines int32 `json:"expectedMachines"`
127128

128129
// total number of healthy machines counted by this machine health check
129130
// +kubebuilder:validation:Minimum=0
130131
// +optional
132+
// +Metrics:gauge:name="status_current_healthy",help="Current number of healthy machines.",nilIsZero=true
131133
CurrentHealthy int32 `json:"currentHealthy"`
132134

133135
// RemediationsAllowed is the number of further remediations allowed by this machine health check before
134136
// maxUnhealthy short circuiting will be applied
135137
// +kubebuilder:validation:Minimum=0
136138
// +optional
139+
// +Metrics:gauge:name="status_remediations_allowed",help="Number of machine remediations that are currently allowed.",nilIsZero=true
137140
RemediationsAllowed int32 `json:"remediationsAllowed"`
138141

139142
// ObservedGeneration is the latest generation observed by the controller.
@@ -146,6 +149,8 @@ type MachineHealthCheckStatus struct {
146149

147150
// Conditions defines current service state of the MachineHealthCheck.
148151
// +optional
152+
// +Metrics:stateset:name="status_condition",help="The condition of a machinehealthcheck.",labelName="status",JSONPath=".status",list={"True","False","Unknown"},labelsFromPath={"type":".type"}
153+
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition last transition time of a machinehealthcheck.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
149154
Conditions Conditions `json:"conditions,omitempty"`
150155
}
151156

@@ -162,8 +167,17 @@ type MachineHealthCheckStatus struct {
162167
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of MachineHealthCheck"
163168

164169
// MachineHealthCheck is the Schema for the machinehealthchecks API.
170+
// +Metrics:gvk:namePrefix="capi_machinehealthcheck"
171+
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
172+
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
173+
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
174+
// +Metrics:labelFromPath:name="cluster_name",JSONPath=".spec.clusterName"
175+
// +Metrics:info:name="info",help="Information about a machinehealthcheck.",labelsFromPath={maxUnhealthy:.spec.maxUnhealthy}
165176
type MachineHealthCheck struct {
166-
metav1.TypeMeta `json:",inline"`
177+
metav1.TypeMeta `json:",inline"`
178+
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
179+
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the machinehealthcheck is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
180+
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
167181
metav1.ObjectMeta `json:"metadata,omitempty"`
168182

169183
// Specification of machine health check policy

0 commit comments

Comments
 (0)