Skip to content
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

Config rework #5070

Merged
merged 1 commit into from
Feb 7, 2023
Merged

Config rework #5070

merged 1 commit into from
Feb 7, 2023

Conversation

abukosek
Copy link
Contributor

@abukosek abukosek commented Nov 22, 2022

This is still in heavy WIP.

  • Pass 1: Convert configuration cmdline flags into structs, make a global config struct, use that everywhere, add loading from YAML config file.
  • Pass 2: Make the test runner and other non-node parts use the new config structs.
  • Pass 3: Make everything work.

Copy link
Member

@kostko kostko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a global config, can we pass it explicitly?

@abukosek
Copy link
Contributor Author

Instead of using a global config, can we pass it explicitly?

Hmm, that seems like a lot of extra work. I'll first finish the current design and then we can discuss changing it.

A lot of modules need access to config options outside of their module, so we'd have to pass the entire global config struct to all modules anyway. And currently, only a few modules have some kind of init function where we could pass the config in explicitly, so all the others would have to be refactored to include something like that. I think the current global struct design is cleaner (load once, use anywhere).

@abukosek abukosek force-pushed the andrej/feature/config branch 5 times, most recently from 1ce113b to 392f78b Compare November 29, 2022 12:15
@gw0
Copy link
Contributor

gw0 commented Nov 29, 2022

Idea: In order to still support "re-usable" config files (after the removal of cmdline flags) it would be great to support some variable substitution before the config file gets parsed. Could be as trivial as replacing e.g. ${EXTERNAL_IP} or {{ EXTERNAL_IP }} with value of env variable EXTERNAL_IP or the value read from a .env file. Or a bit more powerful, like in docker-compose (https://docs.docker.com/compose/environment-variables/).

@abukosek
Copy link
Contributor Author

Idea: In order to still support "re-usable" config files (after the removal of cmdline flags) it would be great to support some variable substitution before the config file gets parsed. Could be as trivial as replacing e.g. ${EXTERNAL_IP} or {{ EXTERNAL_IP }} with value of env variable EXTERNAL_IP or the value read from a .env file. Or a bit more powerful, like in docker-compose (https://docs.docker.com/compose/environment-variables/).

I don't think that the yaml package we're using to parse the config file supports this. This looks like something that should be done with external templating tools and not in oasis-core :)

@ptrus
Copy link
Member

ptrus commented Nov 30, 2022

I think being able to set/override config values via environment variables should be possible, unless there is some hard reasoning not to support it.

One option would be using something like koanf (we use it in https://github.com/oasisprotocol/emerald-web3-gateway). It makes it really easy to use a Config struct (as defined in this PR) and automatically support config fields to be overridden via env variables, see example: https://github.com/oasisprotocol/emerald-web3-gateway/blob/a60756a8f1fb05cecd1d95bf31940a32812c9d8a/conf/config.go#L226-L255 (this is technically also possible to do with viper, but it has some issues like: spf13/viper#368 so I'd suggest avoiding it).

Or what @gw0 posted below.

@gw0
Copy link
Contributor

gw0 commented Nov 30, 2022

I don't think that the yaml package we're using to parse the config file supports this. This looks like something that should be done with external templating tools and not in oasis-core :)

It does not, but setting env variables is convenient and adding support (https://github.com/a8m/envsubst) is as simple as:

import "github.com/a8m/envsubst"
data, err := envsubst.ReadFile("config.yaml")
err = yaml.Unmarshal(data, ...)

@abukosek
Copy link
Contributor Author

abukosek commented Nov 30, 2022

Alright, I'll add that once I'm done with the test runner :)

EDIT: I like the envsubst variant better, so I'll use that.

@abukosek abukosek force-pushed the andrej/feature/config branch 16 times, most recently from 1b17bf2 to a192b42 Compare January 10, 2023 12:57
@abukosek abukosek force-pushed the andrej/feature/config branch 3 times, most recently from aea2010 to 2fbba78 Compare January 26, 2023 15:32
go/config/config.go Outdated Show resolved Hide resolved
go/oasis-test-runner/oasis/oasis.go Show resolved Hide resolved
go/p2p/config/config.go Outdated Show resolved Hide resolved
go/runtime/registry/config/config.go Outdated Show resolved Hide resolved
go/runtime/registry/config/config.go Outdated Show resolved Hide resolved
go/runtime/registry/config/config.go Outdated Show resolved Hide resolved
go/runtime/registry/registry.go Outdated Show resolved Hide resolved
go/worker/common/config.go Outdated Show resolved Hide resolved
@abukosek abukosek force-pushed the andrej/feature/config branch 7 times, most recently from 77ade19 to adfd9c8 Compare January 31, 2023 15:06
.changelog/5070.cfg.md Show resolved Hide resolved
.changelog/5070.cfg.md Outdated Show resolved Hide resolved
.changelog/5070.cfg.md Outdated Show resolved Hide resolved
.changelog/5070.cfg.md Outdated Show resolved Hide resolved
go/runtime/txpool/txpool.go Outdated Show resolved Hide resolved
@abukosek abukosek force-pushed the andrej/feature/config branch 5 times, most recently from e2041b8 to ca60401 Compare February 7, 2023 09:59
@abukosek abukosek marked this pull request as ready for review February 7, 2023 10:15
.changelog/5070.cfg.md Outdated Show resolved Hide resolved
.changelog/5070.cfg.md Outdated Show resolved Hide resolved
.changelog/5070.cfg.md Outdated Show resolved Hide resolved
.changelog/5070.cfg.md Outdated Show resolved Hide resolved
w.storedDeregister = storedDeregister

if flags.ConsensusValidator() {
if config.GlobalConfig.Consensus.Validator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also work if you set the global mode to validator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was wrong, we should make sure that if you set the global mode to validator your node will actually become a validator :-)

SupplementarySanity SupplementarySanityConfig `yaml:"supplementary_sanity,omitempty"`

// Enable tendermint debug logs (very verbose).
LogDebug bool `yaml:"log_debug,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go under the debug options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it kind of makes sense to leave it here because it only sets the Tendermint log level to debug and isn't some unsupported debug flag.

go/consensus/tendermint/config/config.go Outdated Show resolved Hide resolved
go/oasis-node/cmd/node/node.go Outdated Show resolved Hide resolved
go/runtime/txpool/config/config.go Outdated Show resolved Hide resolved
go/runtime/txpool/config/config.go Outdated Show resolved Hide resolved
Use a config file instead of command-line options.
@abukosek abukosek merged commit 4c815ba into master Feb 7, 2023
@abukosek abukosek deleted the andrej/feature/config branch February 7, 2023 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants