core: split out detailed trie access metrics from insertion time (#19316)
* core: split out detailed trie access metrics from insertion time * cmd, core, metrics: support expensive optional metrics
This commit is contained in:
@ -15,24 +15,41 @@ import (
|
||||
)
|
||||
|
||||
// Enabled is checked by the constructor functions for all of the
|
||||
// standard metrics. If it is true, the metric returned is a stub.
|
||||
// standard metrics. If it is true, the metric returned is a stub.
|
||||
//
|
||||
// This global kill-switch helps quantify the observer effect and makes
|
||||
// for less cluttered pprof profiles.
|
||||
var Enabled = false
|
||||
|
||||
// MetricsEnabledFlag is the CLI flag name to use to enable metrics collections.
|
||||
const MetricsEnabledFlag = "metrics"
|
||||
const DashboardEnabledFlag = "dashboard"
|
||||
// EnabledExpensive is a soft-flag meant for external packages to check if costly
|
||||
// metrics gathering is allowed or not. The goal is to separate standard metrics
|
||||
// for health monitoring and debug metrics that might impact runtime performance.
|
||||
var EnabledExpensive = false
|
||||
|
||||
// enablerFlags is the CLI flag names to use to enable metrics collections.
|
||||
var enablerFlags = []string{"metrics", "dashboard"}
|
||||
|
||||
// expensiveEnablerFlags is the CLI flag names to use to enable metrics collections.
|
||||
var expensiveEnablerFlags = []string{"metrics.expensive"}
|
||||
|
||||
// Init enables or disables the metrics system. Since we need this to run before
|
||||
// any other code gets to create meters and timers, we'll actually do an ugly hack
|
||||
// and peek into the command line args for the metrics flag.
|
||||
func init() {
|
||||
for _, arg := range os.Args {
|
||||
if flag := strings.TrimLeft(arg, "-"); flag == MetricsEnabledFlag || flag == DashboardEnabledFlag {
|
||||
log.Info("Enabling metrics collection")
|
||||
Enabled = true
|
||||
flag := strings.TrimLeft(arg, "-")
|
||||
|
||||
for _, enabler := range enablerFlags {
|
||||
if !Enabled && flag == enabler {
|
||||
log.Info("Enabling metrics collection")
|
||||
Enabled = true
|
||||
}
|
||||
}
|
||||
for _, enabler := range expensiveEnablerFlags {
|
||||
if !Enabled && flag == enabler {
|
||||
log.Info("Enabling expensive metrics collection")
|
||||
EnabledExpensive = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user