-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/geth: actually enable metrics when passed via toml #30781
Conversation
Some additional tests
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Actually, this doesn't quite work, as is. Check this: diff --git a/metrics/metrics.go b/metrics/metrics.go
index c7fe5c7333..dae5217653 100644
--- a/metrics/metrics.go
+++ b/metrics/metrics.go
@@ -129,6 +129,7 @@ func readRuntimeStats(v *runtimeStats) {
func CollectProcessMetrics(refresh time.Duration) {
// Short circuit if the metrics system is disabled
if !Enabled {
+ log.Info("Nah I don't wanna do metrics")
return
}
The |
So, as things work now, the So, this PR does work in that it can set the metrics-parameters (creds, ports etc), but it cannot override the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, computer says no
Nice catch. What do you think about 3fe6879? You can curl to see it is really putting out data:
Same hack that we already have except now we peek into the toml. This code path will execute very rarely and the toml lib is already a dependency. So seems reasonable? |
3fe6879
to
71d7b3b
Compare
1359296
to
0e775b7
Compare
Hm. Yeah.. It's dirty but it works. I guess it's just another little slide, in the slope ;-) |
0e775b7
to
dde11d6
Compare
dde11d6
to
1635da8
Compare
// using the flags package in the first place! So instead, let's chop off the | ||
// first element in the args list each time a parse fails. This way we will | ||
// eventually parse every arg and get the ones we care about. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks flaky...?
Let's assume metrics
is enabled in toml config. Won't these two behave differently:
geth --metrics=false --conf=conf.toml
will correctly setEnabled=false
.geth --conf=conf.toml --metrics=false
will incorrectly setEnabled=true
.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in this case, the order of precedence is always flags first, config second. However, the way init()
is written in metrics/metrics.go
, Enabled
is always set to true in case either a flag or config specifies it should be. This is also how it was previously.
So for both 1) and 2) Enabled will be set to true
, but we will not actually serve the metrics because that occurs later in the geth command start up. That is where the precedence comes in.
How would you prefer to deal with this? I could change the parsing in init()
so that when the flag metrics is set, it always uses that value, regardless of config value. Otherwise could detect a mismatch (enabled in config, disabled explicitly by flag) during client startup and fail there instead.
Otherwise, we can leave as-is. Explicitly setting --metrics=false
while actually passing a config with metrics enabled is pretty unlikely and we will not serve the metrics as expected. It will just cause geth to record the metrics internally.
I think my pref is to just fail when metrics are enabled in config, but explicitly disabled by the flag. It is simple to deal with:
diff --git a/cmd/geth/config.go b/cmd/geth/config.go
index 5f252ebf1..200b24109 100644
--- a/cmd/geth/config.go
+++ b/cmd/geth/config.go
@@ -289,6 +289,10 @@ func dumpConfig(ctx *cli.Context) error {
func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) {
if ctx.IsSet(utils.MetricsEnabledFlag.Name) {
+ enabled := ctx.Bool(utils.MetricsEnabledFlag.Name)
+ if cfg.Metrics.Enabled && !enabled {
+ utils.Fatalf("Flag --metrics mismatch with provided config.")
+ }
cfg.Metrics.Enabled = ctx.Bool(utils.MetricsEnabledFlag.Name)
}
if ctx.IsSet(utils.MetricsEnabledExpensiveFlag.Name) {
What do you think?
@holiman will refactor package metrics to allow enabling at runtime. |
closes #28303, replaces #28101
--
When we added metrics to the config toml back in #22083, they didn't actually seem to get enabled when you start the client with the toml. That is fixed here by only starting the metrics after we have parsed the config for it.
You can verify it's working by running this snippet: