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

go/oasis-node/cmd/config: Add the migrate subcommand #5237

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

abukosek
Copy link
Contributor

@abukosek abukosek commented Mar 22, 2023

A new migrate subcommand is added to the node's config
command. This subcommand can be used to automatically migrate
the old YAML config file into the new format introduced in
commit 2a132b3.

The subcommand logs the various changes it makes and warns the
user if a config option is no longer supported, etc.
At the end, any unknown sections of the input config file are
printed to the terminal to give the user a chance to review
them and make manual changes if appropriate.

@abukosek abukosek force-pushed the andrej/feature/config-migration branch 4 times, most recently from 2c035fc to cc4368c Compare March 22, 2023 15:50
@codecov
Copy link

codecov bot commented Mar 22, 2023

Codecov Report

Merging #5237 (2622d56) into master (70b1f66) will decrease coverage by 0.17%.
The diff coverage is 64.03%.

❗ Current head 2622d56 differs from pull request most recent head 19cffd5. Consider uploading reports for the commit 19cffd5 to get more accurate results

@@            Coverage Diff             @@
##           master    #5237      +/-   ##
==========================================
- Coverage   67.23%   67.07%   -0.17%     
==========================================
  Files         512      514       +2     
  Lines       54293    54685     +392     
==========================================
+ Hits        36502    36678     +176     
- Misses      13371    13555     +184     
- Partials     4420     4452      +32     
Impacted Files Coverage Δ
go/oasis-node/cmd/config/migrate/migrate.go 63.65% <63.65%> (ø)
go/oasis-node/cmd/config/config.go 100.00% <100.00%> (ø)
go/oasis-node/cmd/root.go 85.36% <100.00%> (+0.36%) ⬆️

... and 62 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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.

I would not put this under debug.

Also can you add a cfg changelog entry that describes how to use this command?

@abukosek abukosek force-pushed the andrej/feature/config-migration branch from cc4368c to 873ba13 Compare March 23, 2023 10:26
@abukosek abukosek changed the title go/oasis-node/cmd/debug: Add the migrate-config subcommand go/oasis-node/cmd/config: Add the migrate subcommand Mar 23, 2023
@abukosek
Copy link
Contributor Author

Done :)
I've originally put it under debug because the fixgenesis subcommand was also there. We should probably clean that up at some point.

Going to try this out on various config files now and add code to migrate worker.p2p as well (this is the only thing missing, I think).

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.

Can you also add some quick unit tests for these migrations? E.g. using some dummy configs derived from real ones.

@abukosek abukosek force-pushed the andrej/feature/config-migration branch 5 times, most recently from f4dcf82 to 41a1b64 Compare March 30, 2023 12:46
@abukosek abukosek marked this pull request as ready for review March 30, 2023 13:31
go/oasis-node/cmd/config/migrate/migrate.go Show resolved Hide resolved
logger.Warn("note that grpc.* options are from now on only available on the command-line")
}
if _, ok = oldCfg["metrics"]; ok {
logger.Warn("note that metrics.* options are from now on only available on the command-line")
Copy link
Member

Choose a reason for hiding this comment

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

Oh, didn't notice that before, why is this the case, doesn't it make sense to have them in the config file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we could move them into the config in a separate PR...

go/oasis-node/cmd/config/migrate/migrate.go Outdated Show resolved Hide resolved
@abukosek abukosek force-pushed the andrej/feature/config-migration branch 2 times, most recently from 52ffc9e to 9a9785c Compare April 3, 2023 11:44
Copy link
Contributor

@peternose peternose left a comment

Choose a reason for hiding this comment

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

I think that most of the code could be simplified with a map old.config.value => new.config.value and a function which creates all maps on the path, copies values from one config to the other and prints a comment, but not sure.

go/oasis-node/cmd/config/migrate/migrate.go Outdated Show resolved Hide resolved
go/oasis-node/cmd/config/migrate/migrate.go Outdated Show resolved Hide resolved
logger.Error("output file name missing, use the --out flag to specify it")
os.Exit(1)
}
if cfgInFileName == cfgOutFileName {
Copy link
Contributor

Choose a reason for hiding this comment

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

This check probably won't work for oasis-node config migrate --in a.yaml --out ./folder/../a.yaml.
Files could also be folders, e.g. oasis-node config migrate --out folder (not sure if we need so thorough validation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is by design, it's just a safeguard against fatfingering :)

@abukosek abukosek force-pushed the andrej/feature/config-migration branch 3 times, most recently from d42cc40 to 17cd76c Compare April 3, 2023 12:28
@abukosek
Copy link
Contributor Author

abukosek commented Apr 3, 2023

Thank you for your comments!

I also tried to come up with a way to represent and apply the changes in a nicer, more organized way, but the actual changes are too chaotic to do that, so unfortunately this mess of if/else statements is what works best :D

This command will only be useful in the next release. Afterwards, we can remove it or replace its structure with something nicer if necessary.
I don't think overengineering it at this point is worth the time.

newCfgStruct := config.DefaultConfig()
err = yaml.Unmarshal(newCfgRaw, &newCfgStruct)
if err != nil {
logger.Error("failed to parse config file after migration (this might be normal if you're using environment variable substitutions in your original config file)", "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

This error message is a bit confusing for me, as I expect the problem is in the original file and not in the converted one. I hope the users won't have the same problem.

Options:

  • Add few extra lines, one printing that we are doing a migration, one that migration was completed, file saved, another that we are validating the migrated file.
  • Or split migration/validation, e.g. create a new command and print the command for validation at the end. Maybe even add a warning that the file is not validated. New command could be useful latter to verify already migrated config files.
  • Keep as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Config validation is done by default now when then node starts up and loads the config file, so I don't think a separate command is needed for that.

I will add a few more info logs to let the user know what's happening.

@abukosek abukosek force-pushed the andrej/feature/config-migration branch from 17cd76c to 2622d56 Compare April 3, 2023 14:10
Copy link
Contributor

@peternose peternose left a comment

Choose a reason for hiding this comment

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

Looks good.

One last thing. I would maybe change that the mode is always present in the config file, so that you know the node's type as soon as you see the config file, without need to know the default value.

@abukosek abukosek force-pushed the andrej/feature/config-migration branch from 2622d56 to 19cffd5 Compare April 3, 2023 16:35
@abukosek abukosek enabled auto-merge April 3, 2023 16:36
@abukosek abukosek merged commit 8f3cf28 into master Apr 3, 2023
@abukosek abukosek deleted the andrej/feature/config-migration branch April 3, 2023 17:04
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

3 participants