github.com/cilium/cilium@v1.16.2/operator/pkg/ciliumendpointslice/metrics.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package ciliumendpointslice
     5  
     6  import (
     7  	"github.com/prometheus/client_golang/prometheus"
     8  
     9  	"github.com/cilium/cilium/pkg/metrics"
    10  	"github.com/cilium/cilium/pkg/metrics/metric"
    11  )
    12  
    13  const (
    14  	// LabelOutcome indicates whether the outcome of the operation was successful or not
    15  	LabelOutcome = "outcome"
    16  
    17  	// LabelOpcode indicates the kind of CES metric, could be CEP insert or remove
    18  	LabelOpcode = "opcode"
    19  
    20  	// Label values
    21  
    22  	// LabelValueOutcomeSuccess is used as a successful outcome of an operation
    23  	LabelValueOutcomeSuccess = "success"
    24  
    25  	// LabelValueOutcomeFail is used as an unsuccessful outcome of an operation
    26  	LabelValueOutcomeFail = "fail"
    27  
    28  	// LabelValueCEPInsert is used to indicate the number of CEPs inserted in a CES
    29  	LabelValueCEPInsert = "cepinserted"
    30  
    31  	// LabelValueCEPRemove is used to indicate the number of CEPs removed from a CES
    32  	LabelValueCEPRemove = "cepremoved"
    33  )
    34  
    35  func NewMetrics() *Metrics {
    36  	return &Metrics{
    37  		CiliumEndpointSliceDensity: metric.NewHistogram(metric.HistogramOpts{
    38  			Namespace: metrics.CiliumOperatorNamespace,
    39  			Name:      "number_of_ceps_per_ces",
    40  			Help:      "The number of CEPs batched in a CES",
    41  			Buckets:   []float64{1, 10, 25, 50, 100, 200, 500, 1000},
    42  		}),
    43  
    44  		CiliumEndpointsChangeCount: metric.NewHistogramVec(metric.HistogramOpts{
    45  			Namespace: metrics.CiliumOperatorNamespace,
    46  			Name:      "number_of_cep_changes_per_ces",
    47  			Help:      "The number of changed CEPs in each CES update",
    48  		}, []string{LabelOpcode}),
    49  
    50  		CiliumEndpointSliceSyncTotal: metric.NewCounterVec(metric.CounterOpts{
    51  			Namespace: metrics.CiliumOperatorNamespace,
    52  			Name:      "ces_sync_total",
    53  			Help:      "The number of completed CES syncs by outcome",
    54  		}, []string{LabelOutcome}),
    55  
    56  		CiliumEndpointSliceQueueDelay: metric.NewHistogram(metric.HistogramOpts{
    57  			Namespace: metrics.CiliumOperatorNamespace,
    58  			Name:      "ces_queueing_delay_seconds",
    59  			Help:      "CiliumEndpointSlice queueing delay in seconds",
    60  			Buckets:   append(prometheus.DefBuckets, 60, 300, 900, 1800, 3600),
    61  		}),
    62  	}
    63  }
    64  
    65  type Metrics struct {
    66  	// CiliumEndpointSliceDensity indicates the number of CEPs batched in a CES and it used to
    67  	// collect the number of CEPs in CES at various buckets.
    68  	CiliumEndpointSliceDensity metric.Histogram
    69  
    70  	// CiliumEndpointsChangeCount indicates the total number of CEPs changed for every CES request sent to k8s-apiserver.
    71  	// This metric is used to collect number of CEP changes happening at various buckets.
    72  	CiliumEndpointsChangeCount metric.Vec[metric.Observer]
    73  
    74  	// CiliumEndpointSliceSyncTotal indicates the total number of completed CES syncs with k8s-apiserver by success/fail outcome.
    75  	CiliumEndpointSliceSyncTotal metric.Vec[metric.Counter]
    76  
    77  	// CiliumEndpointSliceQueueDelay measures the time spent by CES's in the workqueue. This measures time difference between
    78  	// CES insert in the workqueue and removal from workqueue.
    79  	CiliumEndpointSliceQueueDelay metric.Histogram
    80  }