-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
variables.go
198 lines (174 loc) · 8.33 KB
/
variables.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
189
190
191
192
193
194
195
196
197
198
/*
Copyright 2019 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package buffer
import (
"vitess.io/vitess/go/stats"
)
// This file contains all status variables which can be used to monitor the
// buffer.
var (
// starts counts how often we started buffering (including dry-run bufferings).
starts = stats.NewCountersWithMultiLabels(
"BufferStarts",
"Buffering operation starts, including dry-run",
[]string{"Keyspace", "ShardName"})
// stops counts how often we triggered the stop of a buffering, including
// dry-run bufferings.
// See the type "stopReason" below for all possible values of "Reason".
stops = stats.NewCountersWithMultiLabels(
"BufferStops",
"Buffering operation stops, including dry-runs",
[]string{"Keyspace", "ShardName", "Reason"})
// failoverDurationSumMs is the cumulative sum of all failover durations.
// In connection with "starts" it can be used to calculate a moving average.
failoverDurationSumMs = stats.NewCountersWithMultiLabels(
"BufferFailoverDurationSumMs",
"Total buffering failover duration",
[]string{"Keyspace", "ShardName"})
// utilizationSum is the cumulative sum of the maximum buffer utilization
// (in percentage) during each failover.
// Utilization = maximum number of requests buffered / buffer size.
// In connection with "starts" it can be used to calculate a moving average.
// TODO(mberlin): Replace this with a MultiHistogram once it's available.
utilizationSum = stats.NewGaugesWithMultiLabels(
"BufferUtilizationSum",
"Cumulative buffer utilization (in %) during failover",
[]string{"Keyspace", "ShardName"})
// utilizationDryRunSum is the cumulative sum of the maximum *theoretical*
// buffer utilization (in percentage) during each failover.
// Utilization = maximum number of requests buffered seen / buffer size.
// In connection with "starts" it can be used to calculate a moving average.
// Example: Buffer size = 10. Two consecutive failovers with maximum values of
// 15 and 5 seen requests each add up to a value of 200% (150% + 50%
// utilization). The moving average would be 100% because there were two
// failovers in that period.
// TODO(mberlin): Replace this with a MultiHistogram once it's available.
utilizationDryRunSum = stats.NewCountersWithMultiLabels(
"BufferUtilizationDryRunSum",
"Cumulative buffer utilization % during failover (dry-run)",
[]string{"Keyspace", "ShardName"})
// requestsBuffered tracks how many requests were added to the buffer.
// NOTE: The two counters "Buffered" and "Skipped" should cover all requests
// which passed through the buffer.
requestsBuffered = stats.NewCountersWithMultiLabels(
"BufferRequestsBuffered",
"Buffered requests",
[]string{"Keyspace", "ShardName"})
// requestsBufferedDryRun tracks how many requests would have been added to
// the buffer (dry-run mode).
requestsBufferedDryRun = stats.NewCountersWithMultiLabels(
"BufferRequestsBufferedDryRun",
"Buffered requests (dry-run)",
[]string{"Keyspace", "ShardName"})
// requestsBuffered tracks how many requests were drained from the buffer.
// NOTE: The sum of the two counters "Drained" and "Evicted" should be
// identical to the "Buffered" counter value.
requestsDrained = stats.NewCountersWithMultiLabels(
"BufferRequestsDrained",
"Drained buffered requests",
[]string{"Keyspace", "ShardName"})
// requestsEvicted tracks how many requests were evicted early from the buffer.
// See the type "evictedReason" below for all possible values of "Reason".
requestsEvicted = stats.NewCountersWithMultiLabels(
"BufferRequestsEvicted",
"Evicted buffered requests",
[]string{"Keyspace", "ShardName", "Reason"})
// requestsSkipped tracks how many requests would have been buffered but
// eventually were not (includes dry-run bufferings).
// See the type "skippedReason" below for all possible values of "Reason".
requestsSkipped = stats.NewCountersWithMultiLabels(
"BufferRequestsSkipped",
"Skipped buffering requests (incl. dry-run)",
[]string{"Keyspace", "ShardName", "Reason"})
)
// stopReason is used in "stopsByReason" as "Reason" label.
type stopReason string
var stopReasons = []stopReason{stopShardMissing, stopFailoverEndDetected, stopMaxFailoverDurationExceeded, stopShutdown}
const (
stopShardMissing stopReason = "ReshardingComplete"
stopFailoverEndDetected stopReason = "NewPrimarySeen"
stopMaxFailoverDurationExceeded stopReason = "MaxDurationExceeded"
stopShutdown stopReason = "Shutdown"
)
// evictedReason is used in "requestsEvicted" as "Reason" label.
type evictedReason string
var evictReasons = []evictedReason{evictedContextDone, evictedBufferFull, evictedWindowExceeded}
const (
evictedContextDone evictedReason = "ContextDone"
//lint: ignore SA9004 ok not to use explicit type here because implicit type string is correct
evictedBufferFull = "BufferFull"
evictedWindowExceeded = "WindowExceeded"
)
// skippedReason is used in "requestsSkipped" as "Reason" label.
type skippedReason string
var skippedReasons = []skippedReason{skippedBufferFull, skippedDisabled, skippedShutdown, skippedLastReparentTooRecent, skippedLastFailoverTooRecent}
const (
// skippedBufferFull occurs when all slots in the buffer are occupied by one
// or more concurrent failovers. Unlike "evictedBufferFull", no request could
// be evicted and therefore we had to skip this request.
skippedBufferFull skippedReason = "BufferFull"
// skippedDisabled is used when the buffer was disabled for that particular
// keyspace/shard.
skippedDisabled = "Disabled"
skippedShutdown = "Shutdown"
skippedLastReparentTooRecent = "LastReparentTooRecent"
skippedLastFailoverTooRecent = "LastFailoverTooRecent"
)
// initVariablesForShard is used to initialize all shard variables to 0.
// If we don't do this, monitoring frameworks may not correctly calculate rates
// for the first failover of the shard because they see a transition from
// "no value for this label set (NaN)" to "a value".
// "statsKey" should have two members for keyspace and shard.
func initVariablesForShard(statsKey []string) {
starts.Reset(statsKey)
for _, reason := range stopReasons {
key := append(statsKey, string(reason))
stops.Reset(key)
}
failoverDurationSumMs.Reset(statsKey)
utilizationSum.Set(statsKey, 0)
utilizationDryRunSum.Reset(statsKey)
requestsBuffered.Reset(statsKey)
requestsBufferedDryRun.Reset(statsKey)
requestsDrained.Reset(statsKey)
for _, reason := range evictReasons {
key := append(statsKey, string(reason))
requestsEvicted.Reset(key)
}
for _, reason := range skippedReasons {
key := append(statsKey, string(reason))
requestsSkipped.Reset(key)
}
}
// TODO(mberlin): Remove the gauge values below once we store them
// internally and have a /bufferz page where we can show this.
var (
// bufferSizeStat publishes the configured per vtgate buffer size. It can be used
// to calculate the utilization of the buffer.
bufferSizeStat = stats.NewGauge("BufferSize", "The configured per vtgate buffer size")
lastFailoverDurationMs = stats.NewGaugesWithMultiLabels(
"BufferLastFailoverDurationMs",
"Buffered requests during the last failover. The value for a given shard will be reset at the next failover.",
[]string{"Keyspace", "ShardName"})
lastRequestsInFlightMax = stats.NewGaugesWithMultiLabels(
"BufferLastRequestsInFlightMax",
"The max value of buffered requests in flight of the last failover. The value for a given shard will be reset at the next failover.",
[]string{"Keyspace", "ShardName"})
// lastRequestsDryRunMax has the maximum number of requests which were seen during
// a dry-run buffering of the last failover.
// The value for a given shard will be reset at the next failover.
lastRequestsDryRunMax = stats.NewGaugesWithMultiLabels(
"BufferLastRequestsDryRunMax",
"Max # of requests which were seen during a dry-run buffering of the last failover",
[]string{"Keyspace", "ShardName"})
)