...

Source file src/github.com/linkerd/linkerd2/controller/api/destination/external-workload/queue_metrics.go

Documentation: github.com/linkerd/linkerd2/controller/api/destination/external-workload

     1  package externalworkload
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  	"github.com/prometheus/client_golang/prometheus/promauto"
     6  	"k8s.io/client-go/util/workqueue"
     7  )
     8  
     9  // Code is functionally the same as usptream metrics provider. The difference is that
    10  // we rely on promauto instead of init() method for metrics registering as the logic
    11  // used to register the metrics in the upstream implementation uses k8s.io/component-base/metrics/legacyregistry
    12  // The latter does not work with our metrics registry and hence these metrics do not
    13  // end up exposed via our admin's server /metrics endpoint.
    14  //
    15  // https://github.com/kubernetes/component-base/blob/68f947b04ec3a353e63bbef2c1f935bb9ce0061d/metrics/prometheus/workqueue/metrics.go
    16  
    17  const (
    18  	WorkQueueSubsystem         = "workqueue"
    19  	DepthKey                   = "depth"
    20  	AddsKey                    = "adds_total"
    21  	QueueLatencyKey            = "queue_duration_seconds"
    22  	WorkDurationKey            = "work_duration_seconds"
    23  	UnfinishedWorkKey          = "unfinished_work_seconds"
    24  	LongestRunningProcessorKey = "longest_running_processor_seconds"
    25  	RetriesKey                 = "retries_total"
    26  	DropsTotalKey              = "drops_total"
    27  )
    28  
    29  type queueMetricsProvider struct {
    30  	depth                   *prometheus.GaugeVec
    31  	adds                    *prometheus.CounterVec
    32  	latency                 *prometheus.HistogramVec
    33  	workDuration            *prometheus.HistogramVec
    34  	unfinished              *prometheus.GaugeVec
    35  	longestRunningProcessor *prometheus.GaugeVec
    36  	retries                 *prometheus.CounterVec
    37  	drops                   *prometheus.CounterVec
    38  }
    39  
    40  func newWorkQueueMetricsProvider() *queueMetricsProvider {
    41  	return &queueMetricsProvider{
    42  		depth: promauto.NewGaugeVec(prometheus.GaugeOpts{
    43  			Subsystem: WorkQueueSubsystem,
    44  			Name:      DepthKey,
    45  			Help:      "Current depth of workqueue",
    46  		}, []string{"name"}),
    47  
    48  		adds: promauto.NewCounterVec(prometheus.CounterOpts{
    49  			Subsystem: WorkQueueSubsystem,
    50  			Name:      AddsKey,
    51  			Help:      "Total number of adds handled by workqueue",
    52  		}, []string{"name"}),
    53  
    54  		latency: promauto.NewHistogramVec(prometheus.HistogramOpts{
    55  			Subsystem: WorkQueueSubsystem,
    56  			Name:      QueueLatencyKey,
    57  			Help:      "How long in seconds an item stays in workqueue before being requested.",
    58  			Buckets:   prometheus.ExponentialBuckets(10e-9, 10, 10),
    59  		}, []string{"name"}),
    60  
    61  		workDuration: promauto.NewHistogramVec(prometheus.HistogramOpts{
    62  			Subsystem: WorkQueueSubsystem,
    63  			Name:      WorkDurationKey,
    64  			Help:      "How long in seconds processing an item from workqueue takes.",
    65  			Buckets:   prometheus.ExponentialBuckets(10e-9, 10, 10),
    66  		}, []string{"name"}),
    67  
    68  		unfinished: promauto.NewGaugeVec(prometheus.GaugeOpts{
    69  			Subsystem: WorkQueueSubsystem,
    70  			Name:      UnfinishedWorkKey,
    71  			Help: "How many seconds of work has done that " +
    72  				"is in progress and hasn't been observed by work_duration. Large " +
    73  				"values indicate stuck threads. One can deduce the number of stuck " +
    74  				"threads by observing the rate at which this increases.",
    75  		}, []string{"name"}),
    76  
    77  		longestRunningProcessor: promauto.NewGaugeVec(prometheus.GaugeOpts{
    78  			Subsystem: WorkQueueSubsystem,
    79  			Name:      LongestRunningProcessorKey,
    80  			Help: "How many seconds has the longest running " +
    81  				"processor for workqueue been running.",
    82  		}, []string{"name"}),
    83  
    84  		retries: promauto.NewCounterVec(prometheus.CounterOpts{
    85  			Subsystem: WorkQueueSubsystem,
    86  			Name:      RetriesKey,
    87  			Help:      "Total number of retries handled by workqueue",
    88  		}, []string{"name"}),
    89  		drops: promauto.NewCounterVec(prometheus.CounterOpts{
    90  			Subsystem: WorkQueueSubsystem,
    91  			Name:      DropsTotalKey,
    92  			Help:      "Total number of dropped items from the queue due to exceeding retry threshold",
    93  		}, []string{"name"}),
    94  	}
    95  }
    96  
    97  func (p queueMetricsProvider) NewDepthMetric(name string) workqueue.GaugeMetric {
    98  	return p.depth.WithLabelValues(name)
    99  }
   100  
   101  func (p queueMetricsProvider) NewAddsMetric(name string) workqueue.CounterMetric {
   102  	return p.adds.WithLabelValues(name)
   103  }
   104  
   105  func (p queueMetricsProvider) NewLatencyMetric(name string) workqueue.HistogramMetric {
   106  	return p.latency.WithLabelValues(name)
   107  }
   108  
   109  func (p queueMetricsProvider) NewWorkDurationMetric(name string) workqueue.HistogramMetric {
   110  	return p.workDuration.WithLabelValues(name)
   111  }
   112  
   113  func (p queueMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) workqueue.SettableGaugeMetric {
   114  	return p.unfinished.WithLabelValues(name)
   115  }
   116  
   117  func (p queueMetricsProvider) NewLongestRunningProcessorSecondsMetric(name string) workqueue.SettableGaugeMetric {
   118  	return p.longestRunningProcessor.WithLabelValues(name)
   119  }
   120  
   121  func (p queueMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
   122  	return p.retries.WithLabelValues(name)
   123  }
   124  
   125  func (p queueMetricsProvider) NewDropsMetric(name string) workqueue.CounterMetric {
   126  	return p.drops.WithLabelValues(name)
   127  }
   128  
   129  type noopCounterMetric struct{}
   130  
   131  func (noopCounterMetric) Inc() {}
   132  

View as plain text