Skip to content

Commit

Permalink
chore: refacor ceresdb config (#640)
Browse files Browse the repository at this point in the history
* chore: refacor ceresdb config

* make CI happy
  • Loading branch information
chunshao90 authored Feb 13, 2023
1 parent b7a2a7d commit 7ece981
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/example-cluster-0.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[service]
[server]
bind_addr = "0.0.0.0"
http_port = 5440
grpc_port = 8831
Expand Down
2 changes: 1 addition & 1 deletion docs/example-cluster-1.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[service]
[server]
bind_addr = "0.0.0.0"
http_port = 5441
grpc_port = 8832
Expand Down
2 changes: 1 addition & 1 deletion docs/example-standalone-static-routing.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[service]
[server]
bind_addr = "0.0.0.0"
http_port = 5000
grpc_port = 8831
Expand Down
2 changes: 1 addition & 1 deletion docs/minimal.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[service]
[server]
bind_addr = "0.0.0.0"
http_port = 5440
grpc_port = 8831
Expand Down
3 changes: 1 addition & 2 deletions integration_tests/cases/local/config.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[service]
[server]
bind_addr = "127.0.0.1"
http_port = 5440
grpc_port = 8831
log_level = "debug"
enable_cluster = true

[query]
read_parallelism = 8
Expand Down
14 changes: 7 additions & 7 deletions server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl From<&StaticTopologyConfig> for ClusterView {

#[derive(Clone, Debug, Deserialize)]
#[serde(default)]
pub struct ServiceConfig {
pub struct ServerConfig {
/// The address to listen.
pub bind_addr: String,
pub mysql_port: u16,
Expand All @@ -132,13 +132,14 @@ pub struct ServiceConfig {
pub timeout: Option<ReadableDuration>,
/// The minimum length of the response body to compress.
pub resp_compress_min_length: ReadableSize,
pub deploy_mode: DeployMode,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(default)]
pub struct Config {
/// Config for service, including http, mysql and grpc.
pub service: ServiceConfig,
/// Config for service of server, including http, mysql and grpc.
pub server: ServerConfig,
pub runtime: RuntimeConfig,

/// Log related configs:
Expand All @@ -161,7 +162,6 @@ pub struct Config {
pub query: query_engine::Config,

/// Deployment configs:
pub deploy_mode: DeployMode,
pub cluster: ClusterConfig,

/// Config of limiter
Expand All @@ -182,7 +182,7 @@ impl Default for RuntimeConfig {
}
}

impl Default for ServiceConfig {
impl Default for ServerConfig {
fn default() -> Self {
Self {
bind_addr: String::from("127.0.0.1"),
Expand All @@ -193,14 +193,15 @@ impl Default for ServiceConfig {
grpc_server_cq_count: 20,
timeout: None,
resp_compress_min_length: ReadableSize::mb(4),
deploy_mode: DeployMode::Standalone,
}
}
}

impl Default for Config {
fn default() -> Self {
Self {
service: ServiceConfig::default(),
server: ServerConfig::default(),
runtime: RuntimeConfig::default(),
log_level: "debug".to_string(),
enable_async_log: true,
Expand All @@ -211,7 +212,6 @@ impl Default for Config {
static_route: StaticRouteConfig::default(),
query: query_engine::Config::default(),
analytic: analytic_engine::Config::default(),
deploy_mode: DeployMode::Standalone,
cluster: ClusterConfig::default(),
limiter: LimiterConfig::default(),
forward: forward::Config::default(),
Expand Down
22 changes: 11 additions & 11 deletions server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ impl<Q: QueryExecutor + 'static> Builder<Q> {

// Create http config
let endpoint = Endpoint {
addr: self.config.service.bind_addr.clone(),
port: self.config.service.http_port,
addr: self.config.server.bind_addr.clone(),
port: self.config.server.http_port,
};

let http_config = HttpConfig {
endpoint,
max_body_size: self.config.service.http_max_body_size,
timeout: self.config.service.timeout.map(|v| v.0),
max_body_size: self.config.server.http_max_body_size,
timeout: self.config.server.timeout.map(|v| v.0),
};

// Start http service
Expand All @@ -308,9 +308,9 @@ impl<Q: QueryExecutor + 'static> Builder<Q> {
.context(StartHttpService)?;

let mysql_config = mysql::MysqlConfig {
ip: self.config.service.bind_addr.clone(),
port: self.config.service.mysql_port,
timeout: self.config.service.timeout.map(|v| v.0),
ip: self.config.server.bind_addr.clone(),
port: self.config.server.mysql_port,
timeout: self.config.server.timeout.map(|v| v.0),
};

let mysql_service = mysql::Builder::new(mysql_config)
Expand All @@ -322,23 +322,23 @@ impl<Q: QueryExecutor + 'static> Builder<Q> {
let router = self.router.context(MissingRouter)?;
let rpc_services = grpc::Builder::new()
.endpoint(
Endpoint::new(self.config.service.bind_addr, self.config.service.grpc_port)
Endpoint::new(self.config.server.bind_addr, self.config.server.grpc_port)
.to_string(),
)
.local_endpoint(
Endpoint::new(self.config.cluster.node.addr, self.config.service.grpc_port)
Endpoint::new(self.config.cluster.node.addr, self.config.server.grpc_port)
.to_string(),
)
.resp_compress_min_length(
self.config.service.resp_compress_min_length.as_bytes() as usize
self.config.server.resp_compress_min_length.as_bytes() as usize
)
.runtimes(engine_runtimes)
.instance(instance.clone())
.router(router)
.cluster(self.cluster.clone())
.schema_config_provider(provider)
.forward_config(self.config.forward)
.timeout(self.config.service.timeout.map(|v| v.0))
.timeout(self.config.server.timeout.map(|v| v.0))
.build()
.context(BuildGrpcService)?;

Expand Down
2 changes: 1 addition & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async fn run_server_with_runtimes<T>(
.limiter(limiter);

let engine_builder = T::default();
let builder = match config.deploy_mode {
let builder = match config.server.deploy_mode {
DeployMode::Standalone => {
build_in_standalone_mode(&config, builder, runtimes.clone(), engine_builder).await
}
Expand Down

0 comments on commit 7ece981

Please sign in to comment.