Emit the node group metrics behind a flag

This commit is contained in:
Amr Hanafi (MAHDI)) 2021-05-20 16:49:39 -07:00
parent 2bd7f0efa3
commit f5c2ab7328
4 changed files with 52 additions and 5 deletions

View File

@ -978,7 +978,7 @@ func TestCheckScaleUpDeltaWithinLimits(t *testing.T) {
}
func TestAuthError(t *testing.T) {
metrics.RegisterAll()
metrics.RegisterAll(false)
context, err := NewScaleTestAutoscalingContext(config.AutoscalingOptions{}, &fake.Clientset{}, nil, nil, nil)
assert.NoError(t, err)

View File

@ -179,6 +179,8 @@ var (
cordonNodeBeforeTerminate = flag.Bool("cordon-node-before-terminating", false, "Should CA cordon nodes before terminating during downscale process")
daemonSetEvictionForEmptyNodes = flag.Bool("daemonset-eviction-for-empty-nodes", false, "DaemonSet pods will be gracefully terminated from empty nodes")
userAgent = flag.String("user-agent", "cluster-autoscaler", "User agent used for HTTP calls.")
emitPerNodeGroupMetrics = flag.Bool("emit-per-nodegroup-metrics", false, "If true, emit per node group metrics.")
)
func createAutoscalingOptions() config.AutoscalingOptions {
@ -340,7 +342,7 @@ func buildAutoscaler() (core.Autoscaler, error) {
}
func run(healthCheck *metrics.HealthCheck) {
metrics.RegisterAll()
metrics.RegisterAll(*emitPerNodeGroupMetrics)
autoscaler, err := buildAutoscaler()
if err != nil {

View File

@ -330,7 +330,7 @@ var (
)
// RegisterAll registers all metrics.
func RegisterAll() {
func RegisterAll(emitPerNodeGroupMetrics bool) {
legacyregistry.MustRegister(clusterSafeToAutoscale)
legacyregistry.MustRegister(nodesCount)
legacyregistry.MustRegister(nodeGroupsCount)
@ -340,8 +340,6 @@ func RegisterAll() {
legacyregistry.MustRegister(cpuLimitsCores)
legacyregistry.MustRegister(memoryCurrentBytes)
legacyregistry.MustRegister(memoryLimitsBytes)
legacyregistry.MustRegister(nodesGroupMinNodes)
legacyregistry.MustRegister(nodesGroupMaxNodes)
legacyregistry.MustRegister(lastActivity)
legacyregistry.MustRegister(functionDuration)
legacyregistry.MustRegister(functionDurationSummary)
@ -359,6 +357,11 @@ func RegisterAll() {
legacyregistry.MustRegister(napEnabled)
legacyregistry.MustRegister(nodeGroupCreationCount)
legacyregistry.MustRegister(nodeGroupDeletionCount)
if emitPerNodeGroupMetrics {
legacyregistry.MustRegister(nodesGroupMinNodes)
legacyregistry.MustRegister(nodesGroupMaxNodes)
}
}
// UpdateDurationFromStart records the duration of the step identified by the

View File

@ -0,0 +1,42 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package metrics
import (
"testing"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)
func TestDisabledPerNodeGroupMetrics(t *testing.T) {
RegisterAll(false)
assert.False(t, nodesGroupMinNodes.IsCreated())
assert.False(t, nodesGroupMaxNodes.IsCreated())
}
func TestEnabledPerNodeGroupMetrics(t *testing.T) {
RegisterAll(true)
assert.True(t, nodesGroupMinNodes.IsCreated())
assert.True(t, nodesGroupMaxNodes.IsCreated())
UpdateNodeGroupMin("foo", 2)
UpdateNodeGroupMax("foo", 100)
assert.Equal(t, 2, int(testutil.ToFloat64(nodesGroupMinNodes.GaugeVec.WithLabelValues("foo"))))
assert.Equal(t, 100, int(testutil.ToFloat64(nodesGroupMaxNodes.GaugeVec.WithLabelValues("foo"))))
}