forked from xmidt-org/caduceus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
188 lines (181 loc) · 6.89 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
"github.com/go-kit/kit/metrics"
// nolint:staticcheck
"github.com/xmidt-org/webpa-common/v2/xmetrics"
)
const (
ErrorRequestBodyCounter = "error_request_body_count"
EmptyRequestBodyCounter = "empty_request_body_count"
ModifiedWRPCounter = "modified_wrp_count"
DeliveryCounter = "delivery_count"
DeliveryRetryCounter = "delivery_retry_count"
DeliveryRetryMaxGauge = "delivery_retry_max"
SlowConsumerDroppedMsgCounter = "slow_consumer_dropped_message_count"
SlowConsumerCounter = "slow_consumer_cut_off_count"
IncomingQueueDepth = "incoming_queue_depth"
IncomingEventTypeCounter = "incoming_event_type_count"
DropsDueToInvalidPayload = "drops_due_to_invalid_payload"
OutgoingQueueDepth = "outgoing_queue_depths"
DropsDueToPanic = "drops_due_to_panic"
ConsumerRenewalTimeGauge = "consumer_renewal_time"
ConsumerDeliverUntilGauge = "consumer_deliver_until"
ConsumerDropUntilGauge = "consumer_drop_until"
ConsumerDeliveryWorkersGauge = "consumer_delivery_workers"
ConsumerMaxDeliveryWorkersGauge = "consumer_delivery_workers_max"
QueryDurationHistogram = "query_duration_histogram_seconds"
IncomingQueueLatencyHistogram = "incoming_queue_latency_histogram_seconds"
)
const (
emptyContentTypeReason = "empty_content_type"
emptyUUIDReason = "empty_uuid"
bothEmptyReason = "empty_uuid_and_content_type"
networkError = "network_err"
unknownEventType = "unknown"
)
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
{
Name: IncomingQueueDepth,
Help: "The depth of the queue behind the incoming handlers.",
Type: "gauge",
},
{
Name: ErrorRequestBodyCounter,
Help: "Count of the number of errors encountered reading the body.",
Type: "counter",
},
{
Name: EmptyRequestBodyCounter,
Help: "Count of the number of times the request is an empty body.",
Type: "counter",
},
{
Name: DropsDueToInvalidPayload,
Help: "Dropped messages due to invalid payloads.",
Type: "counter",
},
{
Name: ModifiedWRPCounter,
Help: "Number of times a WRP was modified by Caduceus",
Type: "counter",
LabelNames: []string{"reason"},
},
{
Name: DeliveryRetryCounter,
Help: "Number of delivery retries made",
Type: "counter",
LabelNames: []string{"url", "event"},
},
{
Name: DeliveryRetryMaxGauge,
Help: "Maximum number of delivery retries attempted",
Type: "gauge",
LabelNames: []string{"url"},
},
{
Name: DeliveryCounter,
Help: "Count of delivered messages to a url with a status code",
Type: "counter",
LabelNames: []string{"url", "code", "event"},
},
{
Name: SlowConsumerDroppedMsgCounter,
Help: "Count of dropped messages due to a slow consumer",
Type: "counter",
LabelNames: []string{"url", "reason"},
},
{
Name: SlowConsumerCounter,
Help: "Count of the number of times a consumer has been deemed too slow and is cut off.",
Type: "counter",
LabelNames: []string{"url"},
},
{
Name: OutgoingQueueDepth,
Help: "The depth of the queue per outgoing url.",
Type: "gauge",
LabelNames: []string{"url"},
},
{
Name: IncomingEventTypeCounter,
Help: "Incoming count of events by event type",
Type: "counter",
LabelNames: []string{"event"},
},
{
Name: DropsDueToPanic,
Help: "The outgoing message delivery pipeline panicked.",
Type: "counter",
LabelNames: []string{"url"},
},
{
Name: ConsumerRenewalTimeGauge,
Help: "Time when the consumer data was updated.",
Type: "gauge",
LabelNames: []string{"url"},
},
{
Name: ConsumerDeliverUntilGauge,
Help: "Time when the consumer's registration expires and events will be dropped.",
Type: "gauge",
LabelNames: []string{"url"},
},
{
Name: ConsumerDropUntilGauge,
Help: "The time after which events going to a customer will be delivered.",
Type: "gauge",
LabelNames: []string{"url"},
},
{
Name: ConsumerDeliveryWorkersGauge,
Help: "The number of active delivery workers for a particular customer.",
Type: "gauge",
LabelNames: []string{"url"},
},
{
Name: ConsumerMaxDeliveryWorkersGauge,
Help: "The maximum number of delivery workers available for a particular customer.",
Type: "gauge",
LabelNames: []string{"url"},
},
{
Name: QueryDurationHistogram,
Help: "A histogram of latencies for queries.",
Type: "histogram",
LabelNames: []string{"url", "code"},
Buckets: []float64{0.0625, 0.125, .25, .5, 1, 5, 10, 20, 40, 80, 160},
},
{
Name: IncomingQueueLatencyHistogram,
Help: "A histogram of latencies for the incoming queue.",
Type: "histogram",
LabelNames: []string{"event"},
Buckets: []float64{0.0625, 0.125, .25, .5, 1, 5, 10, 20, 40, 80, 160},
},
}
}
func CreateOutbounderMetrics(m CaduceusMetricsRegistry, c *CaduceusOutboundSender) {
c.deliveryCounter = m.NewCounter(DeliveryCounter)
c.deliveryRetryCounter = m.NewCounter(DeliveryRetryCounter)
c.deliveryRetryMaxGauge = m.NewGauge(DeliveryRetryMaxGauge).With("url", c.id)
c.cutOffCounter = m.NewCounter(SlowConsumerCounter).With("url", c.id)
c.droppedQueueFullCounter = m.NewCounter(SlowConsumerDroppedMsgCounter).With("url", c.id, "reason", "queue_full")
c.droppedExpiredCounter = m.NewCounter(SlowConsumerDroppedMsgCounter).With("url", c.id, "reason", "expired")
c.droppedExpiredBeforeQueueCounter = m.NewCounter(SlowConsumerDroppedMsgCounter).With("url", c.id, "reason", "expired_before_queueing")
c.droppedCutoffCounter = m.NewCounter(SlowConsumerDroppedMsgCounter).With("url", c.id, "reason", "cut_off")
c.droppedInvalidConfig = m.NewCounter(SlowConsumerDroppedMsgCounter).With("url", c.id, "reason", "invalid_config")
c.droppedNetworkErrCounter = m.NewCounter(SlowConsumerDroppedMsgCounter).With("url", c.id, "reason", networkError)
c.droppedPanic = m.NewCounter(DropsDueToPanic).With("url", c.id)
c.queueDepthGauge = m.NewGauge(OutgoingQueueDepth).With("url", c.id)
c.renewalTimeGauge = m.NewGauge(ConsumerRenewalTimeGauge).With("url", c.id)
c.deliverUntilGauge = m.NewGauge(ConsumerDeliverUntilGauge).With("url", c.id)
c.dropUntilGauge = m.NewGauge(ConsumerDropUntilGauge).With("url", c.id)
c.currentWorkersGauge = m.NewGauge(ConsumerDeliveryWorkersGauge).With("url", c.id)
c.maxWorkersGauge = m.NewGauge(ConsumerMaxDeliveryWorkersGauge).With("url", c.id)
}
func NewMetricWrapperMeasures(m CaduceusMetricsRegistry) metrics.Histogram {
return m.NewHistogram(QueryDurationHistogram, 11)
}