-
Notifications
You must be signed in to change notification settings - Fork 84
feat(clp-credential-manager): Create clp-credential-manager Rust service skeleton.
#1668
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
base: s3-credentials-manager
Are you sure you want to change the base?
feat(clp-credential-manager): Create clp-credential-manager Rust service skeleton.
#1668
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
hoophalab
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general. There are some comments
| fn init_tracing() { | ||
| let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); | ||
|
|
||
| let _ = tracing_subscriber::fmt() | ||
| .with_env_filter(env_filter) | ||
| .with_target(false) | ||
| .json() | ||
| .try_init(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The tracing_subscriber::fmt()...try_init() call returns a Result which is being dropped, meaning any initialization failure will be ignored, leading to silent bugs.
Possible implementations: we could use anyhow::Result<()>, or define a crate-wide Error type and use Result<(), Error>
| fn init_tracing() { | |
| let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); | |
| let _ = tracing_subscriber::fmt() | |
| .with_env_filter(env_filter) | |
| .with_target(false) | |
| .json() | |
| .try_init(); | |
| } | |
| fn init_tracing() -> Result<(), Error>{ | |
| let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); | |
| tracing_subscriber::fmt() | |
| .with_env_filter(env_filter) | |
| .with_target(false) | |
| .json() | |
| .try_init()?; | |
| } |
- Zhihao will probably suggest you implementing log file rotation in code.
https://github.com/y-scope/clp/blob/main/components/api-server/src/bin/api_server.rs#L45C1-L66C2
… into cred-mgr-pr1
hoophalab
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments to make the code more rusty, otherwise all good. @LinZhihao-723 you can start having another review.
| .try_init() | ||
| .map_err(|err| anyhow::Error::msg(err.to_string())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| .try_init() | |
| .map_err(|err| anyhow::Error::msg(err.to_string())) | |
| .try_init()? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change isn't working for me:
"? couldn't convert the error: dyn StdError + Send + Sync: Sized is not satisfied"
Co-authored-by: hoophalab <200652805+hoophalab@users.noreply.github.com>
LinZhihao-723
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general a great job, but still some things to fix. @hoophalab please also check my comments so that you can help catch more later.
I think there are two lessons learned in this PR:
- As your first PR to Rust this is still too large. Personally, I would say this PR can be split into three PRs: one to set up the error handling system, one to set up the server skeleton like #1715, and last one for the rest. In that way, you get more chance to learn step by step and save more time on the later review process.
- When contributing to sth you're not familiar with, you can check what other components are doing. We had similar set up for the API server and clp-rust-utils a month ago, which can be references to you to pick up.
| pub fn build_router() -> Router<AppState> { | ||
| Router::new() | ||
| .route("/health", get(health::health_check)) | ||
| .layer(TraceLayer::new_for_http()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can u pass the state into this method to be consistent with the API server?
clp/components/api-server/src/routes.rs
Line 38 in 2534e39
| .with_state(client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had trouble getting the above suggestion to work, plus it seems the current implementation is actually recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk thx for referring to the doc. Let me check.
| /// Supplies the default `MySQL` server port (`3306`). | ||
| const fn default_mysql_port() -> u16 { | ||
| 3306 | ||
| } | ||
|
|
||
| /// Supplies the default maximum connection count for the `MySQL` pool. | ||
| const fn default_max_connections() -> u32 { | ||
| DEFAULT_MAX_CONNECTIONS | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should group all "default" wrappers together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but I guess Eden might don't want to provide default value for every field? So he cannot use impl Default for ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's wait for @junhaoliao to check whether we should share the DB credential config schema with CLP DB config. If they're shareable then we can get rid of this entirely.
|
|
||
| /// Connection options for the `MySQL` backend that stores credentials. | ||
| #[derive(Debug, Clone, Deserialize)] | ||
| pub struct DatabaseConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub should comes before private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be irrelevant pending the option of using the clp_rust_utils config instead, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But it's a heads up for the proper ordering.
|
|
||
| init_tracing()?; | ||
|
|
||
| let config = AppConfig::from_file(&args.config)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Back to the previous comment: if you want to make the errors traceable, you should log the error before return. Otherwise when you start this thing inside docker compose I'm not sure how that error will be reflected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what you mean here; can you explain what I need to add here?
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
Description
This PR sets the foundation of the
clp-credential-managerservice.Added:
clp-credential-managerRust Crate.healthroute for service APINext up:
Checklist
breaking change.
Validation performed
Cargo fmt, check, clippy