...

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

Documentation: k8s.io/kubernetes/pkg/controller/endpointslicemirroring/metrics

     1  /*
     2  Copyright 2020 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  package metrics
    18  
    19  import (
    20  	"sync"
    21  
    22  	"k8s.io/component-base/metrics"
    23  	"k8s.io/component-base/metrics/legacyregistry"
    24  )
    25  
    26  // EndpointSliceMirroringSubsystem is the name of the subsystem used for
    27  // EndpointSliceMirroring controller.
    28  const EndpointSliceMirroringSubsystem = "endpoint_slice_mirroring_controller"
    29  
    30  var (
    31  	// EndpointsAddedPerSync tracks the number of endpoints added on each
    32  	// Endpoints sync.
    33  	EndpointsAddedPerSync = metrics.NewHistogramVec(
    34  		&metrics.HistogramOpts{
    35  			Subsystem:      EndpointSliceMirroringSubsystem,
    36  			Name:           "endpoints_added_per_sync",
    37  			Help:           "Number of endpoints added on each Endpoints sync",
    38  			StabilityLevel: metrics.ALPHA,
    39  			Buckets:        metrics.ExponentialBuckets(2, 2, 15),
    40  		},
    41  		[]string{},
    42  	)
    43  	// EndpointsUpdatedPerSync tracks the number of endpoints updated on each
    44  	// Endpoints sync.
    45  	EndpointsUpdatedPerSync = metrics.NewHistogramVec(
    46  		&metrics.HistogramOpts{
    47  			Subsystem:      EndpointSliceMirroringSubsystem,
    48  			Name:           "endpoints_updated_per_sync",
    49  			Help:           "Number of endpoints updated on each Endpoints sync",
    50  			StabilityLevel: metrics.ALPHA,
    51  			Buckets:        metrics.ExponentialBuckets(2, 2, 15),
    52  		},
    53  		[]string{},
    54  	)
    55  	// EndpointsRemovedPerSync tracks the number of endpoints removed on each
    56  	// Endpoints sync.
    57  	EndpointsRemovedPerSync = metrics.NewHistogramVec(
    58  		&metrics.HistogramOpts{
    59  			Subsystem:      EndpointSliceMirroringSubsystem,
    60  			Name:           "endpoints_removed_per_sync",
    61  			Help:           "Number of endpoints removed on each Endpoints sync",
    62  			StabilityLevel: metrics.ALPHA,
    63  			Buckets:        metrics.ExponentialBuckets(2, 2, 15),
    64  		},
    65  		[]string{},
    66  	)
    67  	// AddressesSkippedPerSync tracks the number of addresses skipped on each
    68  	// Endpoints sync due to being invalid or exceeding MaxEndpointsPerSubset.
    69  	AddressesSkippedPerSync = metrics.NewHistogramVec(
    70  		&metrics.HistogramOpts{
    71  			Subsystem:      EndpointSliceMirroringSubsystem,
    72  			Name:           "addresses_skipped_per_sync",
    73  			Help:           "Number of addresses skipped on each Endpoints sync due to being invalid or exceeding MaxEndpointsPerSubset",
    74  			StabilityLevel: metrics.ALPHA,
    75  			Buckets:        metrics.ExponentialBuckets(2, 2, 15),
    76  		},
    77  		[]string{},
    78  	)
    79  	// EndpointsSyncDuration tracks how long syncEndpoints() takes in a number
    80  	// of Seconds.
    81  	EndpointsSyncDuration = metrics.NewHistogramVec(
    82  		&metrics.HistogramOpts{
    83  			Subsystem:      EndpointSliceMirroringSubsystem,
    84  			Name:           "endpoints_sync_duration",
    85  			Help:           "Duration of syncEndpoints() in seconds",
    86  			StabilityLevel: metrics.ALPHA,
    87  			Buckets:        metrics.ExponentialBuckets(0.001, 2, 15),
    88  		},
    89  		[]string{},
    90  	)
    91  	// EndpointsDesired tracks the total number of desired endpoints.
    92  	EndpointsDesired = metrics.NewGaugeVec(
    93  		&metrics.GaugeOpts{
    94  			Subsystem:      EndpointSliceMirroringSubsystem,
    95  			Name:           "endpoints_desired",
    96  			Help:           "Number of endpoints desired",
    97  			StabilityLevel: metrics.ALPHA,
    98  		},
    99  		[]string{},
   100  	)
   101  	// NumEndpointSlices tracks the number of EndpointSlices in a cluster.
   102  	NumEndpointSlices = metrics.NewGaugeVec(
   103  		&metrics.GaugeOpts{
   104  			Subsystem:      EndpointSliceMirroringSubsystem,
   105  			Name:           "num_endpoint_slices",
   106  			Help:           "Number of EndpointSlices",
   107  			StabilityLevel: metrics.ALPHA,
   108  		},
   109  		[]string{},
   110  	)
   111  	// DesiredEndpointSlices tracks the number of EndpointSlices that would
   112  	// exist with perfect endpoint allocation.
   113  	DesiredEndpointSlices = metrics.NewGaugeVec(
   114  		&metrics.GaugeOpts{
   115  			Subsystem:      EndpointSliceMirroringSubsystem,
   116  			Name:           "desired_endpoint_slices",
   117  			Help:           "Number of EndpointSlices that would exist with perfect endpoint allocation",
   118  			StabilityLevel: metrics.ALPHA,
   119  		},
   120  		[]string{},
   121  	)
   122  	// EndpointSliceChanges tracks the number of changes to Endpoint Slices.
   123  	EndpointSliceChanges = metrics.NewCounterVec(
   124  		&metrics.CounterOpts{
   125  			Subsystem:      EndpointSliceMirroringSubsystem,
   126  			Name:           "changes",
   127  			Help:           "Number of EndpointSlice changes",
   128  			StabilityLevel: metrics.ALPHA,
   129  		},
   130  		[]string{"operation"},
   131  	)
   132  )
   133  
   134  var registerMetrics sync.Once
   135  
   136  // RegisterMetrics registers EndpointSlice metrics.
   137  func RegisterMetrics() {
   138  	registerMetrics.Do(func() {
   139  		legacyregistry.MustRegister(EndpointsAddedPerSync)
   140  		legacyregistry.MustRegister(EndpointsUpdatedPerSync)
   141  		legacyregistry.MustRegister(EndpointsRemovedPerSync)
   142  		legacyregistry.MustRegister(AddressesSkippedPerSync)
   143  		legacyregistry.MustRegister(EndpointsSyncDuration)
   144  		legacyregistry.MustRegister(EndpointsDesired)
   145  		legacyregistry.MustRegister(NumEndpointSlices)
   146  		legacyregistry.MustRegister(DesiredEndpointSlices)
   147  		legacyregistry.MustRegister(EndpointSliceChanges)
   148  	})
   149  }
   150  

View as plain text