From d41a71497b008a2cc7180c54ab6f5dd4f7e1751a Mon Sep 17 00:00:00 2001 From: Phoeniix Zhao Date: Thu, 16 May 2024 16:10:26 +0800 Subject: [PATCH] style: format code style Signed-off-by: Phoeniix Zhao --- crates/curp/src/client/mod.rs | 2 +- crates/curp/src/server/curp_node.rs | 11 +- crates/curp/src/server/mod.rs | 6 +- crates/curp/src/server/raw_curp/mod.rs | 8 +- crates/curp/tests/it/common/curp_group.rs | 6 +- crates/utils/src/config/client_config.rs | 3 +- crates/utils/src/config/cluster_config.rs | 4 +- crates/utils/src/config/metrics_config.rs | 123 +++++++++++----------- crates/utils/src/config/mod.rs | 23 ++-- crates/xline-test-utils/src/lib.rs | 14 ++- crates/xline/src/server/xline_server.rs | 9 +- crates/xline/src/utils/args.rs | 54 ++++++---- crates/xline/src/utils/trace.rs | 5 +- crates/xline/tests/it/tls_test.rs | 5 +- 14 files changed, 151 insertions(+), 122 deletions(-) diff --git a/crates/curp/src/client/mod.rs b/crates/curp/src/client/mod.rs index 42a463a9d..87d990893 100644 --- a/crates/curp/src/client/mod.rs +++ b/crates/curp/src/client/mod.rs @@ -30,9 +30,9 @@ use tokio::task::JoinHandle; #[cfg(not(madsim))] use tonic::transport::ClientTlsConfig; use tracing::debug; -use utils::{build_endpoint, config::client_config::ClientConfig}; #[cfg(madsim)] use utils::ClientTlsConfig; +use utils::{build_endpoint, config::client_config::ClientConfig}; use self::{ retry::{Retry, RetryConfig}, diff --git a/crates/curp/src/server/curp_node.rs b/crates/curp/src/server/curp_node.rs index b4efe3e32..aecfd1b9e 100644 --- a/crates/curp/src/server/curp_node.rs +++ b/crates/curp/src/server/curp_node.rs @@ -18,15 +18,20 @@ use tokio::{ #[cfg(not(madsim))] use tonic::transport::ClientTlsConfig; use tracing::{debug, error, info, trace, warn}; -use utils::{config::curp_config::CurpConfig, task_manager::{tasks::TaskName, Listener, State, TaskManager}}; #[cfg(madsim)] use utils::ClientTlsConfig; +use utils::{ + config::curp_config::CurpConfig, + task_manager::{tasks::TaskName, Listener, State, TaskManager}, +}; use super::{ cmd_board::{CmdBoardRef, CommandBoard}, cmd_worker::{conflict_checked_mpmc, start_cmd_workers}, - conflict::spec_pool_new::{SpObject, SpeculativePool}, - conflict::uncommitted_pool::{UcpObject, UncommittedPool}, + conflict::{ + spec_pool_new::{SpObject, SpeculativePool}, + uncommitted_pool::{UcpObject, UncommittedPool}, + }, gc::gc_cmd_board, lease_manager::LeaseManager, raw_curp::{AppendEntries, RawCurp, Vote}, diff --git a/crates/curp/src/server/mod.rs b/crates/curp/src/server/mod.rs index 0872dafb9..5b64456b3 100644 --- a/crates/curp/src/server/mod.rs +++ b/crates/curp/src/server/mod.rs @@ -10,8 +10,10 @@ use utils::ClientTlsConfig; use utils::{config::curp_config::CurpConfig, task_manager::TaskManager, tracing::Extract}; use self::curp_node::CurpNode; -pub use self::raw_curp::RawCurp; -pub use self::{conflict::spec_pool_new::SpObject, conflict::uncommitted_pool::UcpObject}; +pub use self::{ + conflict::{spec_pool_new::SpObject, uncommitted_pool::UcpObject}, + raw_curp::RawCurp, +}; use crate::{ cmd::{Command, CommandExecutor}, members::{ClusterInfo, ServerId}, diff --git a/crates/curp/src/server/raw_curp/mod.rs b/crates/curp/src/server/raw_curp/mod.rs index cffb7c4f2..278e512f3 100644 --- a/crates/curp/src/server/raw_curp/mod.rs +++ b/crates/curp/src/server/raw_curp/mod.rs @@ -47,9 +47,11 @@ use self::{ state::{CandidateState, LeaderState, State}, }; use super::{ - cmd_worker::CEEventTxApi, conflict::spec_pool_new::SpeculativePool, - conflict::uncommitted_pool::UncommittedPool, lease_manager::LeaseManagerRef, - storage::StorageApi, DB, + cmd_worker::CEEventTxApi, + conflict::{spec_pool_new::SpeculativePool, uncommitted_pool::UncommittedPool}, + lease_manager::LeaseManagerRef, + storage::StorageApi, + DB, }; use crate::{ cmd::Command, diff --git a/crates/curp/tests/it/common/curp_group.rs b/crates/curp/tests/it/common/curp_group.rs index 980ac2c82..2b370e71a 100644 --- a/crates/curp/tests/it/common/curp_group.rs +++ b/crates/curp/tests/it/common/curp_group.rs @@ -39,8 +39,10 @@ use tracing::debug; use utils::{ build_endpoint, config::{ - client_config::ClientConfig, curp_config::CurpConfig, curp_config::CurpConfigBuilder, - engine_config::EngineConfig, storage_config::default_quota, storage_config::StorageConfig, + client_config::ClientConfig, + curp_config::{CurpConfig, CurpConfigBuilder}, + engine_config::EngineConfig, + storage_config::{default_quota, StorageConfig}, }, task_manager::{tasks::TaskName, Listener, TaskManager}, }; diff --git a/crates/utils/src/config/client_config.rs b/crates/utils/src/config/client_config.rs index bbc2f8c98..8763f0304 100644 --- a/crates/utils/src/config/client_config.rs +++ b/crates/utils/src/config/client_config.rs @@ -40,7 +40,7 @@ pub struct ClientConfig { #[serde(default = "default_fixed_backoff")] fixed_backoff: bool, - /// Curp client keep client id alive interval + /// Curp client keep client id alive interval #[getset(get = "pub")] #[serde( with = "duration_format", @@ -111,7 +111,6 @@ pub const fn default_propose_timeout() -> Duration { Duration::from_secs(1) } - /// default client id keep alive interval #[must_use] #[inline] diff --git a/crates/utils/src/config/cluster_config.rs b/crates/utils/src/config/cluster_config.rs index 28ab1314a..064aa1d77 100644 --- a/crates/utils/src/config/cluster_config.rs +++ b/crates/utils/src/config/cluster_config.rs @@ -3,9 +3,7 @@ use std::collections::HashMap; use getset::Getters; use serde::Deserialize; -use super::client_config::ClientConfig; -use super::curp_config::CurpConfig; -use super::server_config::ServerTimeout; +use super::{client_config::ClientConfig, curp_config::CurpConfig, server_config::ServerTimeout}; /// Cluster configuration object, including cluster relevant configuration fields #[allow(clippy::module_name_repetitions)] diff --git a/crates/utils/src/config/metrics_config.rs b/crates/utils/src/config/metrics_config.rs index 40d974c61..ec10cb8f8 100644 --- a/crates/utils/src/config/metrics_config.rs +++ b/crates/utils/src/config/metrics_config.rs @@ -5,109 +5,109 @@ use serde::Deserialize; #[allow(clippy::module_name_repetitions)] #[derive(Clone, Debug, Deserialize, PartialEq, Eq, Getters)] pub struct MetricsConfig { - /// 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, + /// 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, } impl MetricsConfig { - /// Create a new `MetricsConfig` - #[must_use] - #[inline] - pub fn new( - enable: bool, - port: u16, - path: String, - push: bool, - push_endpoint: String, - push_protocol: MetricsPushProtocol, - ) -> Self { - Self { - enable, - port, - path, - push, - push_endpoint, - push_protocol, - } - } + /// Create a new `MetricsConfig` + #[must_use] + #[inline] + pub fn new( + enable: bool, + port: u16, + path: String, + push: bool, + push_endpoint: String, + push_protocol: MetricsPushProtocol, + ) -> Self { + Self { + enable, + port, + path, + push, + push_endpoint, + push_protocol, + } + } } impl Default for MetricsConfig { - #[inline] - fn default() -> Self { - Self { - enable: default_metrics_enable(), - port: default_metrics_port(), - path: default_metrics_path(), - push: default_metrics_push(), - push_endpoint: default_metrics_push_endpoint(), - push_protocol: default_metrics_push_protocol(), - } - } + #[inline] + fn default() -> Self { + Self { + enable: default_metrics_enable(), + port: default_metrics_port(), + path: default_metrics_path(), + push: default_metrics_push(), + push_endpoint: default_metrics_push_endpoint(), + push_protocol: default_metrics_push_protocol(), + } + } } /// Default metrics enable #[must_use] #[inline] pub const fn default_metrics_enable() -> bool { - true + true } /// Default metrics port #[must_use] #[inline] pub const fn default_metrics_port() -> u16 { - 9100 + 9100 } /// Default metrics path #[must_use] #[inline] pub fn default_metrics_path() -> String { - "/metrics".to_owned() + "/metrics".to_owned() } /// Default metrics push option #[must_use] #[inline] pub fn default_metrics_push() -> bool { - false + false } /// Default metrics push protocol #[must_use] #[inline] pub fn default_metrics_push_protocol() -> MetricsPushProtocol { - MetricsPushProtocol::GRPC + MetricsPushProtocol::GRPC } /// Default metrics push endpoint #[must_use] #[inline] pub fn default_metrics_push_endpoint() -> String { - "http://127.0.0.1:4318".to_owned() + "http://127.0.0.1:4318".to_owned() } /// Xline metrics push protocol @@ -135,6 +135,7 @@ impl std::fmt::Display for MetricsPushProtocol { /// Metrics push protocol format pub mod protocol_format { use serde::{Deserialize, Deserializer}; + use super::MetricsPushProtocol; use crate::parse_metrics_push_protocol; diff --git a/crates/utils/src/config/mod.rs b/crates/utils/src/config/mod.rs index 4be9f6327..eb21c7c34 100644 --- a/crates/utils/src/config/mod.rs +++ b/crates/utils/src/config/mod.rs @@ -26,14 +26,11 @@ pub mod trace_config; use getset::Getters; use serde::Deserialize; -use crate::config::cluster_config::ClusterConfig; -use crate::config::compact_config::CompactConfig; -use crate::config::log_config::LogConfig; -use crate::config::metrics_config::MetricsConfig; -use crate::config::storage_config::StorageConfig; -use crate::config::trace_config::TraceConfig; - -use crate::config::{auth_config::AuthConfig, tls_config::TlsConfig}; +use crate::config::{ + auth_config::AuthConfig, cluster_config::ClusterConfig, compact_config::CompactConfig, + log_config::LogConfig, metrics_config::MetricsConfig, storage_config::StorageConfig, + tls_config::TlsConfig, trace_config::TraceConfig, +}; /// Xline server configuration object #[allow(clippy::module_name_repetitions)] @@ -96,11 +93,14 @@ impl XlineServerConfig { #[cfg(test)] mod tests { + use std::{collections::HashMap, path::PathBuf, time::Duration}; + + use super::*; use crate::{ config::{ client_config::{ - default_client_id_keep_alive_interval, default_client_wait_synced_timeout, default_fixed_backoff, default_propose_timeout, - default_retry_count, ClientConfig, + default_client_id_keep_alive_interval, default_client_wait_synced_timeout, + default_fixed_backoff, default_propose_timeout, default_retry_count, ClientConfig, }, compact_config::AutoCompactConfig, curp_config::CurpConfigBuilder, @@ -111,9 +111,6 @@ mod tests { InitialClusterState, LevelConfig, MetricsPushProtocol, RotationConfig, }; - use super::*; - use std::{collections::HashMap, path::PathBuf, time::Duration}; - #[allow(clippy::too_many_lines)] // just a testcase, not too bad #[test] fn test_xline_server_config_should_be_loaded() { diff --git a/crates/xline-test-utils/src/lib.rs b/crates/xline-test-utils/src/lib.rs index 98390b74b..33b9f04f0 100644 --- a/crates/xline-test-utils/src/lib.rs +++ b/crates/xline-test-utils/src/lib.rs @@ -10,10 +10,16 @@ use tokio::{ }; use tonic::transport::ClientTlsConfig; use utils::config::{ - auth_config::AuthConfig, cluster_config::ClusterConfig, cluster_config::InitialClusterState, - compact_config::CompactConfig, engine_config::EngineConfig, log_config::LogConfig, - metrics_config::MetricsConfig, storage_config::default_quota, storage_config::StorageConfig, - tls_config::TlsConfig, trace_config::TraceConfig, XlineServerConfig, + auth_config::AuthConfig, + cluster_config::{ClusterConfig, InitialClusterState}, + compact_config::CompactConfig, + engine_config::EngineConfig, + log_config::LogConfig, + metrics_config::MetricsConfig, + storage_config::{default_quota, StorageConfig}, + tls_config::TlsConfig, + trace_config::TraceConfig, + XlineServerConfig, }; use xline::server::XlineServer; use xline_client::types::auth::{ diff --git a/crates/xline/src/server/xline_server.rs b/crates/xline/src/server/xline_server.rs index 0da8c6b46..70c829316 100644 --- a/crates/xline/src/server/xline_server.rs +++ b/crates/xline/src/server/xline_server.rs @@ -24,9 +24,12 @@ use tonic::transport::{server::Router, Server}; use tracing::{info, warn}; use utils::{ config::{ - auth_config::AuthConfig, cluster_config::ClusterConfig, - cluster_config::InitialClusterState, compact_config::CompactConfig, - engine_config::EngineConfig, storage_config::StorageConfig, tls_config::TlsConfig, + auth_config::AuthConfig, + cluster_config::{ClusterConfig, InitialClusterState}, + compact_config::CompactConfig, + engine_config::EngineConfig, + storage_config::StorageConfig, + tls_config::TlsConfig, }, task_manager::{tasks::TaskName, TaskManager}, }; diff --git a/crates/xline/src/utils/args.rs b/crates/xline/src/utils/args.rs index c83c1d96e..a2e82f4ea 100644 --- a/crates/xline/src/utils/args.rs +++ b/crates/xline/src/utils/args.rs @@ -5,28 +5,38 @@ use clap::Parser; use tokio::fs; use utils::{ config::{ - auth_config::AuthConfig, client_config::default_client_wait_synced_timeout, client_config::default_client_id_keep_alive_interval, - client_config::default_initial_retry_timeout, client_config::default_max_retry_timeout, - client_config::default_propose_timeout, client_config::default_retry_count, - client_config::ClientConfig, cluster_config::ClusterConfig, - cluster_config::InitialClusterState, compact_config::default_compact_batch_size, - compact_config::default_compact_sleep_interval, compact_config::AutoCompactConfig, - compact_config::CompactConfig, curp_config::default_batch_max_size, - curp_config::default_batch_timeout, curp_config::default_candidate_timeout_ticks, - curp_config::default_cmd_workers, curp_config::default_follower_timeout_ticks, - curp_config::default_gc_interval, curp_config::default_heartbeat_interval, - curp_config::default_log_entries_cap, curp_config::default_rpc_timeout, - curp_config::default_server_wait_synced_timeout, curp_config::CurpConfigBuilder, - engine_config::EngineConfig, log_config::default_log_level, log_config::default_rotation, - log_config::LevelConfig, log_config::LogConfig, log_config::RotationConfig, - metrics_config::default_metrics_enable, metrics_config::default_metrics_path, - metrics_config::default_metrics_port, metrics_config::default_metrics_push_endpoint, - metrics_config::default_metrics_push_protocol, metrics_config::MetricsConfig, - metrics_config::MetricsPushProtocol, server_config::default_compact_timeout, - server_config::default_range_retry_timeout, server_config::default_sync_victims_interval, - server_config::default_watch_progress_notify_interval, server_config::ServerTimeout, - storage_config::default_quota, storage_config::StorageConfig, tls_config::TlsConfig, - trace_config::TraceConfig, XlineServerConfig, + auth_config::AuthConfig, + client_config::{ + default_client_id_keep_alive_interval, default_client_wait_synced_timeout, + default_initial_retry_timeout, default_max_retry_timeout, default_propose_timeout, + default_retry_count, ClientConfig, + }, + cluster_config::{ClusterConfig, InitialClusterState}, + compact_config::{ + default_compact_batch_size, default_compact_sleep_interval, AutoCompactConfig, + CompactConfig, + }, + curp_config::{ + default_batch_max_size, default_batch_timeout, default_candidate_timeout_ticks, + default_cmd_workers, default_follower_timeout_ticks, default_gc_interval, + default_heartbeat_interval, default_log_entries_cap, default_rpc_timeout, + default_server_wait_synced_timeout, CurpConfigBuilder, + }, + engine_config::EngineConfig, + log_config::{default_log_level, default_rotation, LevelConfig, LogConfig, RotationConfig}, + metrics_config::{ + default_metrics_enable, default_metrics_path, default_metrics_port, + default_metrics_push_endpoint, default_metrics_push_protocol, MetricsConfig, + MetricsPushProtocol, + }, + server_config::{ + default_compact_timeout, default_range_retry_timeout, default_sync_victims_interval, + default_watch_progress_notify_interval, ServerTimeout, + }, + storage_config::{default_quota, StorageConfig}, + tls_config::TlsConfig, + trace_config::TraceConfig, + XlineServerConfig, }, parse_batch_bytes, parse_duration, parse_log_level, parse_members, parse_metrics_push_protocol, parse_rotation, parse_state, ConfigFileError, diff --git a/crates/xline/src/utils/trace.rs b/crates/xline/src/utils/trace.rs index 4f6faabbf..85435dd7c 100644 --- a/crates/xline/src/utils/trace.rs +++ b/crates/xline/src/utils/trace.rs @@ -3,7 +3,10 @@ use opentelemetry_contrib::trace::exporter::jaeger_json::JaegerJsonExporter; use opentelemetry_sdk::runtime::Tokio; use tracing_appender::non_blocking::WorkerGuard; use tracing_subscriber::{fmt::format, layer::SubscriberExt, util::SubscriberInitExt, Layer}; -use utils::config::{log_config::file_appender, log_config::LogConfig, trace_config::TraceConfig}; +use utils::config::{ + log_config::{file_appender, LogConfig}, + trace_config::TraceConfig, +}; /// init tracing subscriber /// # Errors diff --git a/crates/xline/tests/it/tls_test.rs b/crates/xline/tests/it/tls_test.rs index 64b856bb0..ba2c036e6 100644 --- a/crates/xline/tests/it/tls_test.rs +++ b/crates/xline/tests/it/tls_test.rs @@ -4,8 +4,9 @@ use etcd_client::ConnectOptions; use test_macros::abort_on_panic; use tonic::transport::{Certificate, ClientTlsConfig, Identity}; use utils::config::{ - auth_config::AuthConfig, cluster_config::ClusterConfig, compact_config::CompactConfig, log_config::LogConfig, metrics_config::MetricsConfig, storage_config::StorageConfig, tls_config::TlsConfig, - trace_config::TraceConfig, XlineServerConfig, + auth_config::AuthConfig, cluster_config::ClusterConfig, compact_config::CompactConfig, + log_config::LogConfig, metrics_config::MetricsConfig, storage_config::StorageConfig, + tls_config::TlsConfig, trace_config::TraceConfig, XlineServerConfig, }; use xline_client::types::kv::PutRequest; use xline_test_utils::{enable_auth, set_user, Cluster};