From eb5ef4bc8341162eb53e80d1c464c45132783457 Mon Sep 17 00:00:00 2001 From: Guo Peng <370090914@qq.com> Date: Fri, 8 Dec 2023 23:40:24 +0800 Subject: [PATCH] feat: add metrics to show target size of every node group --- cluster-autoscaler/clusterstate/clusterstate.go | 1 + cluster-autoscaler/metrics/metrics.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cluster-autoscaler/clusterstate/clusterstate.go b/cluster-autoscaler/clusterstate/clusterstate.go index 57444a6536e6..202ec8765d2c 100644 --- a/cluster-autoscaler/clusterstate/clusterstate.go +++ b/cluster-autoscaler/clusterstate/clusterstate.go @@ -319,6 +319,7 @@ func (csr *ClusterStateRegistry) UpdateNodes(nodes []*apiv1.Node, nodeInfosForGr if err != nil { return err } + metrics.UpdateNodeGroupTargetSize(targetSizes) cloudProviderNodeInstances, err := csr.getCloudProviderNodeInstances() if err != nil { diff --git a/cluster-autoscaler/metrics/metrics.go b/cluster-autoscaler/metrics/metrics.go index dfa1d4f7daa7..d7d8246ef9e1 100644 --- a/cluster-autoscaler/metrics/metrics.go +++ b/cluster-autoscaler/metrics/metrics.go @@ -200,6 +200,14 @@ var ( }, []string{"node_group"}, ) + nodesGroupTargetSize = k8smetrics.NewGaugeVec( + &k8smetrics.GaugeOpts{ + Namespace: caNamespace, + Name: "node_group_target_count", + Help: "Target number of nodes in the node group by CA.", + }, []string{"node_group"}, + ) + /**** Metrics related to autoscaler execution ****/ lastActivity = k8smetrics.NewGaugeVec( &k8smetrics.GaugeOpts{ @@ -422,6 +430,7 @@ func RegisterAll(emitPerNodeGroupMetrics bool) { if emitPerNodeGroupMetrics { legacyregistry.MustRegister(nodesGroupMinNodes) legacyregistry.MustRegister(nodesGroupMaxNodes) + legacyregistry.MustRegister(nodesGroupTargetSize) } } @@ -520,6 +529,13 @@ func UpdateNodeGroupMax(nodeGroup string, maxNodes int) { nodesGroupMaxNodes.WithLabelValues(nodeGroup).Set(float64(maxNodes)) } +// UpdateNodeGroupTargetSize records the node group target size +func UpdateNodeGroupTargetSize(targetSizes map[string]int) { + for nodeGroup, targetSize := range targetSizes { + nodesGroupTargetSize.WithLabelValues(nodeGroup).Set(float64(targetSize)) + } +} + // RegisterError records any errors preventing Cluster Autoscaler from working. // No more than one error should be recorded per loop. func RegisterError(err errors.AutoscalerError) {