-
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: dump config for metrics #22083
Conversation
@lightclient @MysticRyuujin could you take a look if that works for you? |
Was able to test this with the metrics configuration I am using and it works great. Thanks @MariusVanDerWijden! |
@MariusVanDerWijden is this still WIP, or is it ready for merge? If the latter, please change the title |
I don't get it. This does dump out the metrics config to toml ... but it doesn't read the metrics config from the toml... ? |
I would expect these two commands to give the exact same output:
|
@holiman It did read the configs from toml, but it did overwrite them every time^^ It works now |
Almost there now, but CLI should take precedence, so this should spit out
|
Hmm it takes precedence if you enable
But I'll change it |
So the code is quite a bit worse now but I think I need it to convey the whole logic.
|
I don't quite understand why you give special treatment to the So Am I missing something? |
No you're right, I thought that we wouldn't want things like influxdbpassword written in the config if it was disabled, but you're right that it should be written out anyway. changed now. |
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.
One minor comment, but generally looks ok. Will test it a bit
cmd/geth/config.go
Outdated
@@ -115,12 +129,28 @@ func defaultNodeConfig() node.Config { | |||
return cfg | |||
} | |||
|
|||
func defaultMetricConfig(ctx *cli.Context) metricConfig { |
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.
Perhaps this should be metricsFromCliArgs
.. When I saw defaultMetricConfig
being used before, I intuitively though that it just initialized some defaults, and didn't grokk that it actually read the cli arguments
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.
Yeah, that's the thing with this strange logic, we need to read the metrics twice.
First we need to read the "default" metrics and apply them s.th. if we don't override them in the load config, they are set to the default values.
Then, after reading the config, we need to read the metrics again (this time only the specially set metrics) to overwrite the config file configs with the configs from cli.
So basically we do:
- read config from cli regardless of whether they are set (reads defaults)
- read config from file (overwrites the default configs if applicable)
- read only the set configs from cli (overwrites the file configs)
I'll change the naming!
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.
Works for me!
cmd/geth/config.go
Outdated
Node: defaultNodeConfig(), | ||
Eth: eth.DefaultConfig, | ||
Node: defaultNodeConfig(), | ||
Metrics: metricsFromCliArgs(ctx), |
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.
I don't understand why you need this function (metricsFromCliArgs
) if you also have applyMetricConfig
. The idea behind the config file loading is:
The config is always created using the Go code defaults.
Then, the TOML file is loaded to override some things.
Finally, the flags are applied to override more things.
In this PR, for metrics, it takes the defaults from flags, then overrides with config file, then applies the flags again. I think we should remove metricsFromCliArgs and just define the defaults for metrics directly in the code.
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.
Yeah, the problem with this approach is that we have now two different places where the default value of the flags is defined.
Once here and once in the cli.Flags.
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.
The way we usually solve this is by taking the flag default from the Go struct default.
https://github.com/ethereum/go-ethereum/blob/master/cmd/utils/flags.go#L136
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.
I created a new default var in the metrics
package
* cmd/geth: dump config * cmd/geth: dump config * cmd/geth: properly read config again * cmd/geth: override metrics if flags are set * cmd/geth: write metrics regardless if enabled * cmd/geth: renamed to metricsfromcliargs * metrics: add default configuration
closes #22007