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

refactor: Migrate parameter configs to YAML #8310

Merged
merged 5 commits into from
Jan 11, 2023

Conversation

aborg-dev
Copy link
Contributor

This is a refactoring PR to enable #8264. For full motivation see #8264 (comment)

This PR only changes the disk format and parsing logic but doesn't change the in-memory representation, so it should not lead to any visible behaviour changes.

The next step in this refactoring would be to investigate getting rid of serde_json::Value in favor of serde_yaml::Value or even better a specialized struct with much more restricted types to catch invalid config errors earlier.

@aborg-dev aborg-dev requested a review from a team as a code owner January 9, 2023 12:41
@aborg-dev aborg-dev requested a review from jakmeier January 9, 2023 12:41
@aborg-dev
Copy link
Contributor Author

The build is currently fails because we use two versions of serde_yaml, one introduced in this PR: "0.9.16" and the other "0.8.24" used by paperclip and insta deps. I've tried to use 0.8.24 in this PR and it exposes two non-critical bugs in older YAML implementation that are caught by our tests.

We can either use 0.8.24 in this PR and fix the failing tests or update paperclip and insta, as both use serde_yaml "0.9.*" in their latest releases. I'm not sure what is the usual approach, so need some advice here.

@akhi3030
Copy link
Collaborator

akhi3030 commented Jan 9, 2023

Assuming it isn't a lot of work, updating paperclip and insta seems like the right way to move forward.

near-bulldozer bot pushed a commit that referenced this pull request Jan 10, 2023
This PR updates multiple paperclip crates:
- paperclip: 0.7.0 -> 0.7.1
- paperclip-actix: 0.5.0 -> 0.5.1
- paperclip-core: 0.5.1 -> 0.5.2
- paperclip-macros: 0.6.0 -> 0.6.1

It is necessary to update serde_yaml to 0.9 for #8310

Tested: passes local `cargo test` run
@aborg-dev
Copy link
Contributor Author

I've tried to go the update-way, but ran into some problems described in #8320 .
I will continue working on the update, but given that it is blocked on external parties, for now I will implement workarounds for this code to work with older YAML version and add TODOs to remove them after version upgrade.

@nagisa
Copy link
Collaborator

nagisa commented Jan 10, 2023

Is there a reason we're picking the infamous YAML over something like TOML? We’d avoid a new dep too.

@aborg-dev
Copy link
Contributor Author

Is there a reason we're picking the infamous YAML over something like TOML? We’d avoid a new dep too.

TL;DR: No strong preference between the two, but YAML seemed a better fit from human readability perspective for our usecase. Would love to hear the arguments againts and reconsider this.

Long story:
I've outlined some reasons in #8264 (comment), but to list them explicitly:

  • Almost no change to existing config to turn it into YAML
  • YAML has multi-line Map values which is useful for statements like
action_receipt_creation_send_sir: {
  old: "some_long_value"
  new: "some_other_long_value"
}

In TOML, in my understanding, this either needs to be on the same line or use a table marker which in turn means that all other definitions need to use table markers or come before this definition:

[action_receipt_creation_send_sir]
old = "some_long_value"
new = "some_other_long_value"

Overall, I think the plan is to keep the config relatively flat (up to 3 layers deep) and don't use any fancy YAML features (tags, references), so we hopefully avoid any portability and debugging issues. Also, we already depend on serde_yaml indirectly, so this is not as bad as introducing a new dependency.

Copy link
Contributor

@jakmeier jakmeier left a comment

Choose a reason for hiding this comment

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

@Akashin Looks good to me, please address the one little nitpick and afterwards this can be merged as far as I am concerned. But let's settle the debate around the format first. :)

Almost no change to existing config to turn it into YAML

That's kind of nice but the more I think about it, the more I am convinced this should not influence our decision too much. Long-term it doesn't matter how big the diff in the PR is.

Overall, I think the plan is to keep the config relatively flat (up to 3 layers deep) and don't use any fancy YAML features (tags, references), so we hopefully avoid any portability and debugging issues. Also, we already depend on serde_yaml indirectly, so this is not as bad as introducing a new dependency.

I agree with everything here. Although, if we could remove the dependency on serde_yaml entirely, that would be nice and we are moving one step further away from that goal.

I guess I have some personal hatred towards yaml as the spec is rather complex and often tools are not fully compatible as a result of it. (At least it used to be like this and your struggle with serde_yaml sort of confirms that.^^) But as long as we keep it simple, as you suggested, this should not be an issue.

@nagisa do you want to veto against YAML? I think TOML would work fine here, too. I don't have a strong opinion in either direction. Both should allow to add a weight (new and old) to each parameter without too much hassle. But I can see the arguments presented by @Akashin that it's a bit nicer in YAML.

core/primitives/src/runtime/parameter_table.rs Outdated Show resolved Hide resolved
(serde_json::Value::Null, parse_parameter_txt_value(value.trim())?),
))
}
serde_json::Value::Null
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a bit ridiculous, parsing YAML text values as JSON. 😵‍💫 But definitely better to keep it like this for now, as all our tests operate on JSON. Maaaybe long-term we can think about cleaning up some more...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was hoping to get rid of this in the next refactoring PR, will give it a try and see how big of a change it is going to be. If that turns out too big, I'll add a TODO here.

@nagisa
Copy link
Collaborator

nagisa commented Jan 10, 2023

Not going to veto yaml. I had my fair share of terrible experiences with it, but mostly in the context of a project attempting to shoehorn it into an application where a DSL would have been more appropriate (ansible, github actions…) I heard horror stories about configuration files written in yaml too, but those also approaching CI definition levels of complexity. But this is neither of those cases 🤷

@aborg-dev
Copy link
Contributor Author

Ok, given that there are no strong arguments against, let's try using YAML for now and reevaluate whether we need to switch to TOML/RON when we either:

  • Run into YAML parsing/debugging issues
  • Have problems evolving the config to support our needs

@near-bulldozer near-bulldozer bot merged commit 8da4503 into near:master Jan 11, 2023
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 15, 2023
This PR updates multiple paperclip crates:
- paperclip: 0.7.0 -> 0.7.1
- paperclip-actix: 0.5.0 -> 0.5.1
- paperclip-core: 0.5.1 -> 0.5.2
- paperclip-macros: 0.6.0 -> 0.6.1

It is necessary to update serde_yaml to 0.9 for near#8310

Tested: passes local `cargo test` run
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Jan 15, 2023
This is a refactoring PR to enable near#8264. For full motivation see near#8264 (comment)

This PR only changes the disk format and parsing logic but doesn't change the in-memory representation, so it should not lead to any visible behaviour changes.

The next step in this refactoring would be to investigate getting rid of `serde_json::Value` in favor of `serde_yaml::Value` or even better a specialized struct with much more restricted types to catch invalid config errors earlier.
@aborg-dev aborg-dev added the C-housekeeping Category: Refactoring, cleanups, code quality label Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-housekeeping Category: Refactoring, cleanups, code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants