...

Source file src/k8s.io/kubernetes/pkg/controller/podautoscaler/monitor/metrics.go

Documentation: k8s.io/kubernetes/pkg/controller/podautoscaler/monitor

     1  /*
     2  Copyright 2023 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // metrics packages contains metrics which are exposed from the HPA controller.
    18  package monitor
    19  
    20  import (
    21  	"sync"
    22  
    23  	"k8s.io/component-base/metrics"
    24  	"k8s.io/component-base/metrics/legacyregistry"
    25  )
    26  
    27  const (
    28  	// hpaControllerSubsystem - subsystem name used by HPA controller
    29  	hpaControllerSubsystem = "horizontal_pod_autoscaler_controller"
    30  )
    31  
    32  var (
    33  	reconciliationsTotal = metrics.NewCounterVec(
    34  		&metrics.CounterOpts{
    35  			Subsystem:      hpaControllerSubsystem,
    36  			Name:           "reconciliations_total",
    37  			Help:           "Number of reconciliations of HPA controller. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. Also, the label 'error' should be either 'spec', 'internal', or 'none'. Note that if both spec and internal errors happen during a reconciliation, the first one to occur is reported in `error` label.",
    38  			StabilityLevel: metrics.ALPHA,
    39  		}, []string{"action", "error"})
    40  
    41  	reconciliationsDuration = metrics.NewHistogramVec(
    42  		&metrics.HistogramOpts{
    43  			Subsystem:      hpaControllerSubsystem,
    44  			Name:           "reconciliation_duration_seconds",
    45  			Help:           "The time(seconds) that the HPA controller takes to reconcile once. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. Also, the label 'error' should be either 'spec', 'internal', or 'none'. Note that if both spec and internal errors happen during a reconciliation, the first one to occur is reported in `error` label.",
    46  			Buckets:        metrics.ExponentialBuckets(0.001, 2, 15),
    47  			StabilityLevel: metrics.ALPHA,
    48  		}, []string{"action", "error"})
    49  	metricComputationTotal = metrics.NewCounterVec(
    50  		&metrics.CounterOpts{
    51  			Subsystem:      hpaControllerSubsystem,
    52  			Name:           "metric_computation_total",
    53  			Help:           "Number of metric computations. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. Also, the label 'error' should be either 'spec', 'internal', or 'none'. The label 'metric_type' corresponds to HPA.spec.metrics[*].type",
    54  			StabilityLevel: metrics.ALPHA,
    55  		}, []string{"action", "error", "metric_type"})
    56  	metricComputationDuration = metrics.NewHistogramVec(
    57  		&metrics.HistogramOpts{
    58  			Subsystem:      hpaControllerSubsystem,
    59  			Name:           "metric_computation_duration_seconds",
    60  			Help:           "The time(seconds) that the HPA controller takes to calculate one metric. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. The label 'error' should be either 'spec', 'internal', or 'none'. The label 'metric_type' corresponds to HPA.spec.metrics[*].type",
    61  			Buckets:        metrics.ExponentialBuckets(0.001, 2, 15),
    62  			StabilityLevel: metrics.ALPHA,
    63  		}, []string{"action", "error", "metric_type"})
    64  
    65  	metricsList = []metrics.Registerable{
    66  		reconciliationsTotal,
    67  		reconciliationsDuration,
    68  		metricComputationTotal,
    69  		metricComputationDuration,
    70  	}
    71  )
    72  
    73  var register sync.Once
    74  
    75  // Register all metrics.
    76  func Register() {
    77  	// Register the metrics.
    78  	register.Do(func() {
    79  		registerMetrics(metricsList...)
    80  	})
    81  }
    82  
    83  // RegisterMetrics registers a list of metrics.
    84  func registerMetrics(extraMetrics ...metrics.Registerable) {
    85  	for _, metric := range extraMetrics {
    86  		legacyregistry.MustRegister(metric)
    87  	}
    88  }
    89  

View as plain text