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: Rewrite config parser to respect the order #4971

Merged
merged 24 commits into from
Apr 24, 2022

Conversation

Xuanwo
Copy link
Member

@Xuanwo Xuanwo commented Apr 20, 2022

Signed-off-by: Xuanwo github@xuanwo.io

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

This PR will fix #4362

To make our config parsed in a more understandable way, I built the following two libs:

  • serde-bridge: A bridge between different serde implementations.
  • serfig: Layered configuration system built upon serde

Now, our config is parsed in the following ways:

  • Load from files (powered by toml and so on)
  • Load from env (powered by serde-env)
  • Load from clap args

All of them are bridged by serde-bridge.

With this PR, we will:

  • Avoid args conflict via the new style of args naming style
  • Remove env-helper! as we are loading by envy

Our config will be more consistent and extensible.

Breaking Changes

args naming

  • From access-key-id to storage-s3-access-key-id
  • From region to storage-s3-region
  • Remove load_from_args, load_from_env, load_from_file from Config

All storage service-related args will be prefixed by storage-<service>- instead.

env naming

  • From S3_STORAGE_ACCESS_KEY_ID to STORAGE_S3_ACCESS_KEY_ID
  • Every env will map to an arg directly.

Preview

image

Current Status

PR is ready for review now!

Works are listed here

  • Make sure all test cases passed
  • Merge with main to adapt to new changes
  • Make a release for serde-bridge, serfig and serde-env.
  • Update all docs related to this change.

Changelog

  • Improvement

Related Issues

Fixes #4362

Signed-off-by: Xuanwo <github@xuanwo.io>
@vercel
Copy link

vercel bot commented Apr 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
databend ⬜️ Ignored (Inspect) Apr 24, 2022 at 5:25AM (UTC)

@mergify
Copy link
Contributor

mergify bot commented Apr 20, 2022

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@ZhiHanZ
Copy link
Collaborator

ZhiHanZ commented Apr 20, 2022

I prefer load order like:

  1. from argument
  2. from configfile
  3. from environment variable

to treat environment variable as first-class citizen and respect the configuration from configfile, and it would also cause painful breaking change if config from configfile could overlap settings from environment variables

@Xuanwo
Copy link
Member Author

Xuanwo commented Apr 20, 2022

I prefer load order like:

  1. from argument
  2. from configfile
  3. from environment variable

to treat environment variable as first-class citizen and respect the configuration from configfile, and it would also cause painful breaking change if config from configfile could overlap settings from environment variables

Yep, this proposal does implement this order, next layer will overwrite the same value for the current layer. That means we will take env first, and overload by config and argument.

query/Cargo.toml Outdated Show resolved Hide resolved
Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo
Copy link
Member Author

Xuanwo commented Apr 21, 2022

envy is not suitable for databend as it can't deserialize value in nested structs. I build a new lib serde-env to fix it.

Now, our PR is buildable. I'm going to move to the next step: make PR ready for review 🚀

Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo
Copy link
Member Author

Xuanwo commented Apr 21, 2022

image

Oh, I love deleting code (

Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo
Copy link
Member Author

Xuanwo commented Apr 22, 2022

I added a test for override: https://github.com/datafuselabs/databend/pull/4971/files#diff-a8af230cc9f832a19df365f4ddd5cf49cc3bd752705c27445008c928d7f2041dR193-R295

@ZhiHanZ Please help check whether this behavior is expected.

@Xuanwo Xuanwo marked this pull request as ready for review April 22, 2022 12:13
@Xuanwo Xuanwo requested a review from BohuTANG as a code owner April 22, 2022 12:13
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo Xuanwo changed the title draft: Refactor config parser refactor: Rewrite config parser to respect the order Apr 23, 2022
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@sundy-li
Copy link
Member

/LGTM Tests should be fixed

Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@flaneur2020
Copy link
Member

flaneur2020 commented Apr 24, 2022

I guess we can consider a versioned config approach like: https://github.com/k3d-io/k3d/tree/main/pkg/config

on introducing incompatible config changes, we can bounce up the config version with a migration logic, like https://github.com/flaneur2020/k3d/blob/412950bd84bcee0050c42515ef19356689152328/pkg/config/v1alpha3/migrations.go#L41

thus the older configs can keep compatible until the annual deprecation cycle, allowing users to migrate the configs after reading our deprecation news but before the actual api got break.

@Xuanwo
Copy link
Member Author

Xuanwo commented Apr 24, 2022

I guess we can consider a versioned config approach like: https://github.com/k3d-io/k3d/tree/main/pkg/config

I will add a version id first in this PR.

Tracked at #5022

Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@Xuanwo
Copy link
Member Author

Xuanwo commented Apr 24, 2022

test_stateless_standalone_macos seems not very stable.

@Xuanwo
Copy link
Member Author

Xuanwo commented Apr 24, 2022

ping @BohuTANG @flaneur2020 for another approve.

Copy link
Member

@BohuTANG BohuTANG left a comment

Choose a reason for hiding this comment

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

lgtm

@mergify mergify bot merged commit 48b5d58 into datafuselabs:main Apr 24, 2022
@Xuanwo Xuanwo deleted the refactor-storage-config branch April 24, 2022 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: config overwrite when specify --config and any other command line args.
7 participants