diff --git a/cluster-autoscaler/core/autoscaler.go b/cluster-autoscaler/core/autoscaler.go index 3735baaac083..bf243eaf8cab 100644 --- a/cluster-autoscaler/core/autoscaler.go +++ b/cluster-autoscaler/core/autoscaler.go @@ -27,6 +27,7 @@ import ( "k8s.io/autoscaler/cluster-autoscaler/estimator" "k8s.io/autoscaler/cluster-autoscaler/expander" "k8s.io/autoscaler/cluster-autoscaler/expander/factory" + "k8s.io/autoscaler/cluster-autoscaler/metrics" ca_processors "k8s.io/autoscaler/cluster-autoscaler/processors" "k8s.io/autoscaler/cluster-autoscaler/simulator" "k8s.io/autoscaler/cluster-autoscaler/utils/backoff" @@ -66,6 +67,13 @@ func NewAutoscaler(opts AutoscalerOptions) (Autoscaler, errors.AutoscalerError) if err != nil { return nil, errors.ToAutoscalerError(errors.InternalError, err) } + + // These metrics should be published only once. + for _, nodeGroup := range opts.CloudProvider.NodeGroups() { + metrics.UpdateNodeGroupMin(nodeGroup.Id(), nodeGroup.MinSize()) + metrics.UpdateNodeGroupMax(nodeGroup.Id(), nodeGroup.MaxSize()) + } + return NewStaticAutoscaler( opts.AutoscalingOptions, opts.PredicateChecker, diff --git a/cluster-autoscaler/metrics/metrics.go b/cluster-autoscaler/metrics/metrics.go index e3b5ed22edbd..a90a6a2c4a8a 100644 --- a/cluster-autoscaler/metrics/metrics.go +++ b/cluster-autoscaler/metrics/metrics.go @@ -138,6 +138,22 @@ var ( }, ) + nodesGroupMinNodes = k8smetrics.NewGaugeVec( + &k8smetrics.GaugeOpts{ + Namespace: caNamespace, + Name: "node_group_min_count", + Help: "Minimum number of nodes in the node group", + }, []string{"node_group"}, + ) + + nodesGroupMaxNodes = k8smetrics.NewGaugeVec( + &k8smetrics.GaugeOpts{ + Namespace: caNamespace, + Name: "node_group_max_count", + Help: "Maximum number of nodes in the node group", + }, []string{"node_group"}, + ) + /**** Metrics related to autoscaler execution ****/ lastActivity = k8smetrics.NewGaugeVec( &k8smetrics.GaugeOpts{ @@ -288,6 +304,8 @@ func RegisterAll() { legacyregistry.MustRegister(nodeGroupsCount) legacyregistry.MustRegister(unschedulablePodsCount) legacyregistry.MustRegister(maxNodesCount) + legacyregistry.MustRegister(nodesGroupMinNodes) + legacyregistry.MustRegister(nodesGroupMaxNodes) legacyregistry.MustRegister(lastActivity) legacyregistry.MustRegister(functionDuration) legacyregistry.MustRegister(functionDurationSummary) @@ -364,6 +382,16 @@ func UpdateMaxNodesCount(nodesCount int) { maxNodesCount.Set(float64(nodesCount)) } +// UpdateNodeGroupMin records the node group minimum allowed number of nodes +func UpdateNodeGroupMin(nodeGroup string, minNodes int) { + nodesGroupMinNodes.WithLabelValues(nodeGroup).Set(float64(minNodes)) +} + +// UpdateNodeGroupMax records the node group maximum allowed number of nodes +func UpdateNodeGroupMax(nodeGroup string, maxNodes int) { + nodesGroupMaxNodes.WithLabelValues(nodeGroup).Set(float64(maxNodes)) +} + // RegisterError records any errors preventing Cluster Autoscaler from working. // No more than one error should be recorded per loop. func RegisterError(err errors.AutoscalerError) {