-
Notifications
You must be signed in to change notification settings - Fork 760
/
Copy pathconfig.rs
135 lines (115 loc) · 3.96 KB
/
config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2020-2021 The Datafuse Authors.
//
// SPDX-License-Identifier: Apache-2.0.
use common_exception::ErrorCode;
use common_exception::Result;
use structopt::StructOpt;
use structopt_toml::StructOptToml;
pub const FUSE_COMMIT_VERSION: &str = env!("FUSE_COMMIT_VERSION");
#[derive(Clone, Debug, serde::Deserialize, PartialEq, StructOpt, StructOptToml)]
#[serde(default)]
pub struct Config {
#[structopt(long, env = "FUSE_QUERY_LOG_LEVEL", default_value = "INFO")]
pub log_level: String,
#[structopt(long, env = "FUSE_QUERY_NUM_CPUS", default_value = "0")]
pub num_cpus: u64,
#[structopt(
long,
env = "FUSE_QUERY_MYSQL_HANDLER_HOST",
default_value = "127.0.0.1"
)]
pub mysql_handler_host: String,
#[structopt(long, env = "FUSE_QUERY_MYSQL_HANDLER_PORT", default_value = "3307")]
pub mysql_handler_port: u16,
#[structopt(
long,
env = "FUSE_QUERY_MYSQL_HANDLER_THREAD_NUM",
default_value = "256"
)]
pub mysql_handler_thread_num: u64,
#[structopt(
long,
env = "FUSE_QUERY_CLICKHOUSE_HANDLER_HOST",
default_value = "127.0.0.1"
)]
pub clickhouse_handler_host: String,
#[structopt(
long,
env = "FUSE_QUERY_CLICKHOUSE_HANDLER_PORT",
default_value = "9000"
)]
pub clickhouse_handler_port: u64,
#[structopt(
long,
env = "FUSE_QUERY_CLICKHOUSE_HANDLER_THREAD_NUM",
default_value = "256"
)]
pub clickhouse_handler_thread_num: u64,
#[structopt(
long,
env = "FUSE_QUERY_FLIGHT_API_ADDRESS",
default_value = "127.0.0.1:9090"
)]
pub flight_api_address: String,
#[structopt(
long,
env = "FUSE_QUERY_HTTP_API_ADDRESS",
default_value = "127.0.0.1:8080"
)]
pub http_api_address: String,
#[structopt(
long,
env = "FUSE_QUERY_METRIC_API_ADDRESS",
default_value = "127.0.0.1:7070"
)]
pub metric_api_address: String,
#[structopt(long, env = "STORE_API_ADDRESS", default_value = "127.0.0.1:9191")]
pub store_api_address: String,
#[structopt(long, env = "STORE_API_USERNAME", default_value = "root")]
pub store_api_username: String,
#[structopt(long, env = "STORE_API_PASSWORD", default_value = "root")]
pub store_api_password: String,
#[structopt(long, short = "c", env = "CONFIG_FILE", default_value = "")]
pub config_file: String,
}
impl Config {
/// Default configs.
pub fn default() -> Self {
Config {
log_level: "debug".to_string(),
num_cpus: 8,
mysql_handler_host: "127.0.0.1".to_string(),
mysql_handler_port: 3307,
mysql_handler_thread_num: 256,
clickhouse_handler_host: "127.0.0.1".to_string(),
clickhouse_handler_port: 9000,
clickhouse_handler_thread_num: 256,
flight_api_address: "127.0.0.1:9090".to_string(),
http_api_address: "127.0.0.1:8080".to_string(),
metric_api_address: "127.0.0.1:7070".to_string(),
store_api_address: "127.0.0.1:9191".to_string(),
store_api_username: "root".to_string(),
store_api_password: "root".to_string(),
config_file: "".to_string(),
}
}
/// Load configs from args.
pub fn load_from_args() -> Self {
let mut cfg = Config::from_args();
if cfg.num_cpus == 0 {
cfg.num_cpus = num_cpus::get() as u64;
}
cfg
}
/// Load configs from toml file.
pub fn load_from_toml(file: &str) -> Result<Self> {
let context = std::fs::read_to_string(file)
.map_err(|e| ErrorCode::CannotReadFile(format!("File: {}, err: {:?}", file, e)))?;
let mut cfg = Config::from_args_with_toml(context.as_str())
.map_err(|e| ErrorCode::BadArguments(format!("{:?}", e)))?;
if cfg.num_cpus == 0 {
cfg.num_cpus = num_cpus::get() as u64;
}
Ok(cfg)
}
}