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
10
11
12
13
14
15
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