Skip to content

Commit

Permalink
style: format code style
Browse files Browse the repository at this point in the history
Signed-off-by: Phoeniix Zhao <[email protected]>
  • Loading branch information
Phoenix500526 committed May 16, 2024
1 parent cb9497b commit d41a714
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 122 deletions.
2 changes: 1 addition & 1 deletion crates/curp/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
11 changes: 8 additions & 3 deletions crates/curp/src/server/curp_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
6 changes: 4 additions & 2 deletions crates/curp/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
8 changes: 5 additions & 3 deletions crates/curp/src/server/raw_curp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions crates/curp/tests/it/common/curp_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
3 changes: 1 addition & 2 deletions crates/utils/src/config/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -111,7 +111,6 @@ pub const fn default_propose_timeout() -> Duration {
Duration::from_secs(1)
}


/// default client id keep alive interval
#[must_use]
#[inline]
Expand Down
4 changes: 1 addition & 3 deletions crates/utils/src/config/cluster_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
123 changes: 62 additions & 61 deletions crates/utils/src/config/metrics_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
23 changes: 10 additions & 13 deletions crates/utils/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -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() {
Expand Down
14 changes: 10 additions & 4 deletions crates/xline-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
9 changes: 6 additions & 3 deletions crates/xline/src/server/xline_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
Loading

0 comments on commit d41a714

Please sign in to comment.