From ece509389676d554124c6776fa22a140f9941fc7 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Mon, 5 Feb 2024 15:37:59 +0530 Subject: [PATCH] fix : metrics expensive --- metrics/metrics.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index 56cdfb01cd..c76f3e7489 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -45,6 +45,9 @@ var expensiveEnablerFlags = []string{"metrics.expensive"} // expensiveEnablerEnvVars is the env var names to use to enable metrics collections. var expensiveEnablerEnvVars = []string{"GETH_METRICS_EXPENSIVE"} +// configFlag is the CLI flag name to use to start node by providing a toml based config +var configFlag = "config" + // 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. @@ -65,9 +68,20 @@ func init() { } } } - for _, arg := range os.Args { + + var configFile string + + for i, arg := range os.Args { flag := strings.TrimLeft(arg, "-") + // check for existence of `config` flag + if flag == configFlag && i < len(os.Args)-1 { + configFile = strings.TrimLeft(os.Args[i+1], "-") // find the value of flag + } else if len(flag) > 6 && flag[:6] == configFlag { + // Checks for `=` separated flag (e.g. config=path) + configFile = strings.TrimLeft(flag[6:], "=") + } + for _, enabler := range enablerFlags { if !Enabled && flag == enabler { log.Info("Enabling metrics collection") @@ -81,9 +95,11 @@ func init() { } } } + + // Update the global metrics value, if they're provided in the config file + updateMetricsFromConfig(configFile) } -// nolint : unused func updateMetricsFromConfig(path string) { // Don't act upon any errors here. They're already taken into // consideration when the toml config file will be parsed in the cli.