github.com/nginxinc/kubernetes-ingress@v1.12.5/internal/metrics/collectors/workqueue.go (about) 1 package collectors 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 "k8s.io/client-go/util/workqueue" 6 ) 7 8 // WorkQueueMetricsCollector collects the metrics about the work queue, which the Ingress Controller uses to process changes to the resources in the cluster. 9 // implements the prometheus.Collector interface 10 type WorkQueueMetricsCollector struct { 11 depth *prometheus.GaugeVec 12 latency *prometheus.HistogramVec 13 workDuration *prometheus.HistogramVec 14 } 15 16 // NewWorkQueueMetricsCollector creates a new WorkQueueMetricsCollector 17 func NewWorkQueueMetricsCollector(constLabels map[string]string) *WorkQueueMetricsCollector { 18 const workqueueSubsystem = "workqueue" 19 var latencyBucketSeconds = []float64{0.1, 0.5, 1, 5, 10, 50} 20 21 return &WorkQueueMetricsCollector{ 22 depth: prometheus.NewGaugeVec( 23 prometheus.GaugeOpts{ 24 Namespace: metricsNamespace, 25 Subsystem: workqueueSubsystem, 26 Name: "depth", 27 Help: "Current depth of workqueue", 28 ConstLabels: constLabels, 29 }, 30 []string{"name"}, 31 ), 32 latency: prometheus.NewHistogramVec( 33 prometheus.HistogramOpts{ 34 Namespace: metricsNamespace, 35 Subsystem: workqueueSubsystem, 36 Name: "queue_duration_seconds", 37 Help: "How long in seconds an item stays in workqueue before being processed", 38 Buckets: latencyBucketSeconds, 39 ConstLabels: constLabels, 40 }, 41 []string{"name"}, 42 ), 43 workDuration: prometheus.NewHistogramVec( 44 prometheus.HistogramOpts{ 45 Namespace: metricsNamespace, 46 Subsystem: workqueueSubsystem, 47 Name: "work_duration_seconds", 48 Help: "How long in seconds processing an item from workqueue takes", 49 Buckets: latencyBucketSeconds, 50 ConstLabels: constLabels, 51 }, 52 []string{"name"}, 53 ), 54 } 55 } 56 57 // Collect implements the prometheus.Collector interface Collect method 58 func (wqc *WorkQueueMetricsCollector) Collect(ch chan<- prometheus.Metric) { 59 wqc.depth.Collect(ch) 60 wqc.latency.Collect(ch) 61 wqc.workDuration.Collect(ch) 62 } 63 64 // Describe implements the prometheus.Collector interface Describe method 65 func (wqc *WorkQueueMetricsCollector) Describe(ch chan<- *prometheus.Desc) { 66 wqc.depth.Describe(ch) 67 wqc.latency.Describe(ch) 68 wqc.workDuration.Describe(ch) 69 } 70 71 // Register registers all the metrics of the collector 72 func (wqc *WorkQueueMetricsCollector) Register(registry *prometheus.Registry) error { 73 workqueue.SetProvider(wqc) 74 return registry.Register(wqc) 75 } 76 77 // NewDepthMetric implements the workqueue.MetricsProvider interface NewDepthMetric method 78 func (wqc *WorkQueueMetricsCollector) NewDepthMetric(name string) workqueue.GaugeMetric { 79 return wqc.depth.WithLabelValues(name) 80 } 81 82 // NewLatencyMetric implements the workqueue.MetricsProvider interface NewLatencyMetric method 83 func (wqc *WorkQueueMetricsCollector) NewLatencyMetric(name string) workqueue.HistogramMetric { 84 return wqc.latency.WithLabelValues(name) 85 86 } 87 88 // NewWorkDurationMetric implements the workqueue.MetricsProvider interface NewWorkDurationMetric method 89 func (wqc *WorkQueueMetricsCollector) NewWorkDurationMetric(name string) workqueue.HistogramMetric { 90 return wqc.workDuration.WithLabelValues(name) 91 } 92 93 // noopMetric implements the workqueue.GaugeMetric and workqueue.HistogramMetric interfaces 94 type noopMetric struct{} 95 96 func (noopMetric) Inc() {} 97 func (noopMetric) Dec() {} 98 func (noopMetric) Set(float64) {} 99 func (noopMetric) Observe(float64) {} 100 101 // NewAddsMetric implements the workqueue.MetricsProvider interface NewAddsMetric method 102 func (*WorkQueueMetricsCollector) NewAddsMetric(string) workqueue.CounterMetric { 103 return noopMetric{} 104 } 105 106 // NewUnfinishedWorkSecondsMetric implements the workqueue.MetricsProvider interface NewUnfinishedWorkSecondsMetric method 107 func (*WorkQueueMetricsCollector) NewUnfinishedWorkSecondsMetric(string) workqueue.SettableGaugeMetric { 108 return noopMetric{} 109 } 110 111 // NewLongestRunningProcessorSecondsMetric implements the workqueue.MetricsProvider interface NewLongestRunningProcessorSecondsMetric method 112 func (*WorkQueueMetricsCollector) NewLongestRunningProcessorSecondsMetric(string) workqueue.SettableGaugeMetric { 113 return noopMetric{} 114 } 115 116 // NewRetriesMetric implements the workqueue.MetricsProvider interface NewRetriesMetric method 117 func (*WorkQueueMetricsCollector) NewRetriesMetric(string) workqueue.CounterMetric { 118 return noopMetric{} 119 }