Skip to content

Commit 2406a1b

Browse files
vtorc: add flag to set collection metric retention/ttl
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
1 parent 7dd3c6b commit 2406a1b

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

go/flags/endtoend/vtorc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Flags:
3535
--config-persistence-min-interval duration minimum interval between persisting dynamic config changes back to disk (if no change has occurred, nothing is done). (default 1s)
3636
--config-type string Config file type (omit to infer config type from file extension).
3737
--consul-auth-static-file string JSON File to read the topos/tokens from.
38+
--discovery-collection-metrics-ttl duration The time-to-live for discovery collection metrics (default 2m0s)
3839
--discovery-workers int Number of workers used for tablet discovery (default 300)
3940
--emit-stats If set, emit stats to push-based monitoring and stats backends
4041
--enable-primary-disk-stalled-recovery Whether VTOrc should detect a stalled disk on the primary and failover

go/vt/vtorc/collection/collection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ data which is suitable for easy collection by monitoring systems.
4545
4646
Expiry is triggered by default if the collection is created via
4747
CreateOrReturnCollection() and uses an expiry period of
48-
DiscoveryCollectionRetentionSeconds. It can also be enabled by
48+
config.GetDiscoveryCollectionMetricsTTL(). It can also be enabled by
4949
calling StartAutoExpiration() after setting the required expire
5050
period with SetExpirePeriod().
5151
@@ -54,7 +54,7 @@ of metrics which have passed the time specified. Not enabling expiry
5454
will mean data is collected but never freed which will make
5555
vtorc run out of memory eventually.
5656
57-
Current code uses DiscoveryCollectionRetentionSeconds as the
57+
Current code uses config.GetDiscoveryCollectionMetricsTTL() as the
5858
time to keep metric data.
5959
*/
6060
package collection
@@ -111,7 +111,7 @@ func CreateOrReturnCollection(name string) *Collection {
111111
collection: nil,
112112
done: make(chan struct{}),
113113
// WARNING: use a different configuration name
114-
expirePeriod: time.Duration(config.DiscoveryCollectionRetentionSeconds) * time.Second,
114+
expirePeriod: config.GetDiscoveryCollectionMetricsTTL(),
115115
}
116116
go qmc.StartAutoExpiration()
117117

go/vt/vtorc/config/config.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const (
3434
StaleInstanceCoordinatesExpireSeconds = 60
3535
DiscoveryQueueCapacity = 100000
3636
DiscoveryQueueMaxStatisticsSize = 120
37-
DiscoveryCollectionRetentionSeconds = 120
3837
UnseenInstanceForgetHours = 240 // Number of hours after which an unseen instance is forgotten
3938
)
4039

@@ -218,6 +217,15 @@ var (
218217
Dynamic: true,
219218
},
220219
)
220+
221+
discoveryCollectionMetricsTTL = viperutil.Configure(
222+
"discovery-collection-metrics-ttl",
223+
viperutil.Options[time.Duration]{
224+
FlagName: "discovery-collection-metrics-ttl",
225+
Default: 120 * time.Second,
226+
Dynamic: true,
227+
},
228+
)
221229
)
222230

223231
func init() {
@@ -246,6 +254,7 @@ func registerFlags(fs *pflag.FlagSet) {
246254
fs.Bool("allow-recovery", allowRecovery.Default(), "Whether VTOrc should be allowed to run recovery actions")
247255
fs.Bool("change-tablets-with-errant-gtid-to-drained", convertTabletsWithErrantGTIDs.Default(), "Whether VTOrc should be changing the type of tablets with errant GTIDs to DRAINED")
248256
fs.Bool("enable-primary-disk-stalled-recovery", enablePrimaryDiskStalledRecovery.Default(), "Whether VTOrc should detect a stalled disk on the primary and failover")
257+
fs.Duration("discovery-collection-metrics-ttl", discoveryCollectionMetricsTTL.Default(), "The time-to-live for discovery collection metrics")
249258

250259
viperutil.BindFlags(fs,
251260
instancePollTime,
@@ -268,6 +277,7 @@ func registerFlags(fs *pflag.FlagSet) {
268277
allowRecovery,
269278
convertTabletsWithErrantGTIDs,
270279
enablePrimaryDiskStalledRecovery,
280+
discoveryCollectionMetricsTTL,
271281
)
272282
}
273283

@@ -381,6 +391,11 @@ func GetRecoveryPollDuration() time.Duration {
381391
return recoveryPollDuration.Get()
382392
}
383393

394+
// GetDiscoveryCollectionMetricsTTL is a getter function.
395+
func GetDiscoveryCollectionMetricsTTL() time.Duration {
396+
return discoveryCollectionMetricsTTL.Get()
397+
}
398+
384399
// ERSEnabled reports whether VTOrc is allowed to run ERS or not.
385400
func ERSEnabled() bool {
386401
return ersEnabled.Get()

0 commit comments

Comments
 (0)