Skip to content

Commit

Permalink
Merge pull request kubernetes#6361 from guopeng0/feature/metrics
Browse files Browse the repository at this point in the history
feat: add metrics to show target size of every node group
  • Loading branch information
k8s-ci-robot authored Dec 11, 2023
2 parents 37673fe + eb5ef4b commit 98a77a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions cluster-autoscaler/clusterstate/clusterstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions cluster-autoscaler/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -422,6 +430,7 @@ func RegisterAll(emitPerNodeGroupMetrics bool) {
if emitPerNodeGroupMetrics {
legacyregistry.MustRegister(nodesGroupMinNodes)
legacyregistry.MustRegister(nodesGroupMaxNodes)
legacyregistry.MustRegister(nodesGroupTargetSize)
}
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 98a77a8

Please sign in to comment.