diff --git a/cluster-autoscaler/main.go b/cluster-autoscaler/main.go index d50cc0cebde4..c8146eed8104 100644 --- a/cluster-autoscaler/main.go +++ b/cluster-autoscaler/main.go @@ -608,6 +608,9 @@ func buildAutoscaler(context ctx.Context, debuggingSnapshotter debuggingsnapshot metrics.UpdateCPULimitsCores(autoscalingOptions.MinCoresTotal, autoscalingOptions.MaxCoresTotal) metrics.UpdateMemoryLimitsBytes(autoscalingOptions.MinMemoryTotal, autoscalingOptions.MaxMemoryTotal) + // Initialize metrics. + metrics.InitMetrics() + // Create autoscaler. autoscaler, err := core.NewAutoscaler(opts, informerFactory) if err != nil { diff --git a/cluster-autoscaler/metrics/metrics.go b/cluster-autoscaler/metrics/metrics.go index a7be79e2bae5..fe209087f673 100644 --- a/cluster-autoscaler/metrics/metrics.go +++ b/cluster-autoscaler/metrics/metrics.go @@ -473,6 +473,28 @@ func RegisterAll(emitPerNodeGroupMetrics bool) { } } +// InitMetrics initializes all metrics +func InitMetrics() { + for _, errorType := range []errors.AutoscalerErrorType{errors.CloudProviderError, errors.ApiCallError, errors.InternalError, errors.TransientError, errors.ConfigurationError, errors.NodeGroupDoesNotExistError, errors.UnexpectedScaleDownStateError} { + errorsCount.WithLabelValues(string(errorType)).Add(0) + } + + for _, reason := range []FailedScaleUpReason{CloudProviderError, APIError, Timeout} { + scaleDownCount.WithLabelValues(string(reason)).Add(0) + failedScaleUpCount.WithLabelValues(string(reason)).Add(0) + } + + for _, result := range []PodEvictionResult{PodEvictionSucceed, PodEvictionFailed} { + evictionsCount.WithLabelValues(string(result)).Add(0) + } + + skippedScaleEventsCount.WithLabelValues(DirectionScaleDown, CpuResourceLimit).Add(0) + skippedScaleEventsCount.WithLabelValues(DirectionScaleDown, MemoryResourceLimit).Add(0) + skippedScaleEventsCount.WithLabelValues(DirectionScaleUp, CpuResourceLimit).Add(0) + skippedScaleEventsCount.WithLabelValues(DirectionScaleUp, MemoryResourceLimit).Add(0) + +} + // UpdateDurationFromStart records the duration of the step identified by the // label using start time func UpdateDurationFromStart(label FunctionLabel, start time.Time) {