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: split config into multiple modules #676

Closed
wants to merge 6 commits into from

Conversation

Harsh1s
Copy link

@Harsh1s Harsh1s commented Mar 6, 2024

  • what problem are you trying to solve? (or if there's no problem, what's the motivation for this change?)
    -> Fixes [Refactor]: config #604
    -> Currently all configurations are in a single file, utils/src/config.rs,It also contains a lot of parse_xxx, xxx_format, default_xxx methods, It's messy and difficult to manage. This PR organizes these configurations into modules, each containing the configuration itself, its parse method, and default values.

  • what changes does this pull request make?
    -> It adds a different folder structure and splits every config struct into a separate module. I plan on replacing new method with a more flexible builder method.

  • are there any non-obvious implications of these changes? (does it break compatibility with previous versions, etc)
    -> Not yet, although a builder refactor could mean little rewrites in curp

@Harsh1s
Copy link
Author

Harsh1s commented Mar 6, 2024

I'll refactor the new methods into builder methods into another commit. Before doing that just some wanted feedback if possible.

Copy link
Collaborator

@Phoenix500526 Phoenix500526 left a comment

Choose a reason for hiding this comment

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

There are some code style problems, please format the code. BTW, please comment on the issue #604, so I can assign this issue to you.

Copy link

mergify bot commented Apr 18, 2024

@Harsh1s Convert your pr to draft since CI failed

@mergify mergify bot marked this pull request as draft April 18, 2024 06:51
Copy link

mergify bot commented Apr 18, 2024

@Harsh1s Your PR is in conflict and cannot be merged.

@mergify mergify bot requested a review from a team April 19, 2024 04:35
@Phoenix500526
Copy link
Collaborator

Hi, @Harsh1s ! This pr has been stalled for 2 months. Would you like to update it? 😄

@Harsh1s
Copy link
Author

Harsh1s commented May 10, 2024

Hi, @Harsh1s ! This pr has been stalled for 2 months. Would you like to update it? 😄

I am so very sorry, I assure you I'll update it within a day.

@Harsh1s Harsh1s force-pushed the refactor-config branch from 267110c to 7993e50 Compare May 12, 2024 17:59
@Harsh1s Harsh1s marked this pull request as ready for review May 12, 2024 18:01
@Harsh1s
Copy link
Author

Harsh1s commented May 14, 2024

@Phoenix500526 I redid the refactor with latest changes, I still have to rewrite new methods into builder pattern which I'll do by EOD. Could you please review if current refactor is fine? I'll do the builder rewrite in the meantime.

Copy link

mergify bot commented May 14, 2024

@Harsh1s Convert your pr to draft since CI failed

@mergify mergify bot marked this pull request as draft May 14, 2024 08:29
@mergify mergify bot added the CI:fail CI has failed label May 14, 2024
Signed-off-by: Phoeniix Zhao <[email protected]>
@Phoenix500526 Phoenix500526 force-pushed the refactor-config branch 2 times, most recently from 9c1aaa9 to d1904bd Compare May 16, 2024 09:37
@mergify mergify bot marked this pull request as ready for review May 16, 2024 09:56
@mergify mergify bot removed the CI:fail CI has failed label May 16, 2024
Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 89.13325% with 84 lines in your changes are missing coverage. Please review.

Project coverage is 75.54%. Comparing base (e35b35a) to head (3482952).
Report is 84 commits behind head on master.

Current head 3482952 differs from pull request most recent head 93f0429

Please upload reports for the commit 93f0429 to get more accurate results.

Files Patch % Lines
crates/utils/src/config/metrics.rs 57.62% 22 Missing and 3 partials ⚠️
crates/utils/src/config/log.rs 60.37% 17 Missing and 4 partials ⚠️
crates/utils/src/config/compact.rs 57.57% 11 Missing and 3 partials ⚠️
crates/utils/src/config/curp.rs 85.93% 7 Missing and 2 partials ⚠️
crates/utils/src/config/client.rs 95.16% 1 Missing and 2 partials ⚠️
crates/utils/src/config/cluster.rs 94.44% 0 Missing and 3 partials ⚠️
crates/utils/src/config/mod.rs 99.40% 1 Missing and 1 partial ⚠️
crates/utils/src/config/server.rs 95.12% 0 Missing and 2 partials ⚠️
crates/utils/src/config/auth.rs 85.71% 0 Missing and 1 partial ⚠️
crates/utils/src/config/engine.rs 75.00% 0 Missing and 1 partial ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #676      +/-   ##
==========================================
- Coverage   75.55%   75.54%   -0.02%     
==========================================
  Files         180      198      +18     
  Lines       26938    27496     +558     
  Branches    26938    27496     +558     
==========================================
+ Hits        20353    20771     +418     
- Misses       5366     5446      +80     
- Partials     1219     1279      +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Phoenix500526
Copy link
Collaborator

Hi, @Harsh1s I've rebased this pr and modify the code to pass the ci process.

use getset::Getters;
use serde::Deserialize;

use crate::config::{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better use use self::{auth::AuthConfig, .....}

/// Generates a new `XlineServerConfig` object
#[must_use]
#[inline]
#[allow(clippy::too_many_arguments)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we use a builder pattern to refactor it?

@@ -0,0 +1,442 @@
/// Xline auth configuration module
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can provide a prelude here or publicly use those XXConfig here. In doing so, we can use use utils::config::prelude::{AuthConfig, ClientConfig} or use utils::config::{AuthConfig, ClientConfig} instead of use utils::config::{auth::AuthConfig, client::ClientConfig}.

Comment on lines +9 to +32
/// Enable or not
#[getset(get = "pub")]
#[serde(default = "default_metrics_enable")]
pub enable: bool,
/// The http port to expose
#[getset(get = "pub")]
#[serde(default = "default_metrics_port")]
pub port: u16,
/// The http path to expose
#[getset(get = "pub")]
#[serde(default = "default_metrics_path")]
pub path: String,
/// Enable push or not
#[getset(get = "pub")]
#[serde(default = "default_metrics_push")]
pub push: bool,
/// Push endpoint
#[getset(get = "pub")]
#[serde(default = "default_metrics_push_endpoint")]
pub push_endpoint: String,
/// Push protocol
#[getset(get = "pub")]
#[serde(with = "protocol_format", default = "default_metrics_push_protocol")]
pub push_protocol: MetricsPushProtocol,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you change the visibility of these fields when you already have their public getter methods?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually, I prefer to change the visibility of fields rather than use a public getter in that both achieve the same result, but the getter method introduces additional dependencies.

Comment on lines +11 to +16
/// The public key file
#[getset(get = "pub")]
pub auth_public_key: Option<PathBuf>,
/// The private key file
#[getset(get = "pub")]
pub auth_private_key: Option<PathBuf>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above.

@@ -422,7 +422,7 @@ impl TestCE {
after_sync_sender: mpsc::UnboundedSender<(TestCommand, LogIndex)>,
engine_cfg: EngineConfig,
) -> Self {
let engine_type = match engine_cfg {
let engine_type: EngineType = match engine_cfg {
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: please remove this EngineType.

Comment on lines +12 to +16
#[getset(get = "pub")]
pub auth_public_key: Option<PathBuf>,
/// The private key file
#[getset(get = "pub")]
pub auth_private_key: Option<PathBuf>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

@mergify mergify bot requested a review from a team May 17, 2024 02:29
Comment on lines +12 to +28
#[getset(get = "pub")]
pub peer_ca_cert_path: Option<PathBuf>,
/// The public key file used by peer
#[getset(get = "pub")]
pub peer_cert_path: Option<PathBuf>,
/// The private key file used by peer
#[getset(get = "pub")]
pub peer_key_path: Option<PathBuf>,
/// The CA certificate file used by client to verify peer certificates
#[getset(get = "pub")]
pub client_ca_cert_path: Option<PathBuf>,
/// The public key file used by client
#[getset(get = "pub")]
pub client_cert_path: Option<PathBuf>,
/// The private key file used by client
#[getset(get = "pub")]
pub client_key_path: Option<PathBuf>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

@Phoenix500526 Phoenix500526 requested a review from bsbds May 17, 2024 02:36
@mergify mergify bot requested a review from a team May 17, 2024 02:36
@Phoenix500526 Phoenix500526 self-assigned this May 17, 2024
@Harsh1s
Copy link
Author

Harsh1s commented May 17, 2024

Thanks for the help @Phoenix500526 , I've pulled the changes and I'll address all your reviews now. I also started working on builder patterns for all the structs, I'll make commits one by one.

Copy link

mergify bot commented May 17, 2024

@Harsh1s Convert your pr to draft since CI failed

@mergify mergify bot marked this pull request as draft May 17, 2024 09:49
@mergify mergify bot added the CI:fail CI has failed label May 17, 2024
@Phoenix500526
Copy link
Collaborator

Hi, @Harsh1s! IMO, to implement the builder pattern for all these XXConfig structures may not be a good practice. I only recommend implementing the builder pattern for those XXConfig structures with too many arguments in their constructor. BTW, to pass the commit message validation ci task, please use "refactor(config)" or "refactor" to replace the "refactor-config" in your commit message. 😄

@Harsh1s
Copy link
Author

Harsh1s commented May 17, 2024

Hi, @Harsh1s! IMO, to implement the builder pattern for all these XXConfig structures may not be a good practice. I only recommend implementing the builder pattern for those XXConfig structures with too many arguments in their constructor. BTW, to pass the commit message validation ci task, please use "refactor(config)" or "refactor" to replace the "refactor-config" in your commit message. 😄

Understood, thank you so much for all the help and being so patient with me!

@Phoenix500526
Copy link
Collaborator

We also provide the .pre-commit-config.yaml in our project root. You can execute the pre-commit install command at the project root to install the git hook. It will automatically run the cargo fmt, cargo clippy and validate the commit message for you before you commit your code modifications. I think it's helpful.

@Harsh1s
Copy link
Author

Harsh1s commented May 17, 2024

We also provide the .pre-commit-config.yaml in our project root. You can execute the pre-commit install command at the project root to install the git hook. It will automatically run the cargo fmt, cargo clippy and validate the commit message for you before you commit your code modifications. I think it's helpful.

Okay, will do. Thanks!

@lxl66566
Copy link
Collaborator

lxl66566 commented Aug 8, 2024

It has been a while since there was any activity on this pull request. Unfortunately, we have decided to close this PR for now.

If you're still interested in contributing this change, please reopen this pr. Alternatively, if you could provide an update or a status on your end, that would also be very helpful.

Thank you for your contribution!

@lxl66566 lxl66566 closed this Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI:fail CI has failed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Refactor]: config
3 participants