From fd9c4f65c6da3ddfd7e02b078d912033c805db51 Mon Sep 17 00:00:00 2001 From: wangzhen05 Date: Mon, 28 Jun 2021 21:31:01 +0800 Subject: [PATCH 1/7] remove user and root information --- fusequery/query/src/configs/config.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fusequery/query/src/configs/config.rs b/fusequery/query/src/configs/config.rs index 25cf68eb8ddf8..9c2502ead28e7 100644 --- a/fusequery/query/src/configs/config.rs +++ b/fusequery/query/src/configs/config.rs @@ -27,8 +27,19 @@ lazy_static! { ver }; } - -#[derive(Clone, Debug, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] +impl fmt::Debug for Config{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{{ log_level: \"{}\", log_dir: \"{}\", num_cpus: {}, mysql_handler_host: \"{}\", + mysql_handler_port: {}, mysql_handler_thread_num: {}, clickhouse_handler_host: \"{}\", clickhouse_handler_clickhouse_handler_port: {}, + clickhouse_handler_thread_num: {}, flight_api_address: \"{}\", http_api_address: \"{}\", metric_api_address: \"{}\", + store_api_address: \"{}\", config_file: \"{}\", }}", + self.log_level, self.log_dir, self.num_cpus, self.mysql_handler_host, self.mysql_handler_port, + self.mysql_handler_thread_num, self.clickhouse_handler_host, self.clickhouse_handler_port, + self.clickhouse_handler_thread_num, self.flight_api_address, self.http_api_address, self.metric_api_address, + self.store_api_address, self.config_file) + } +} +#[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] #[serde(default)] pub struct Config { #[structopt(long, env = "FUSE_QUERY_LOG_LEVEL", default_value = "INFO")] From 6c495766405eebf0dd2b9b6c0347ac7f1f107e63 Mon Sep 17 00:00:00 2001 From: wangzhen05 Date: Tue, 29 Jun 2021 23:04:49 +0800 Subject: [PATCH 2/7] import std::fmt, and pass all tests with a Lost connection to MySQL server Error --- fusequery/query/src/configs/config.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fusequery/query/src/configs/config.rs b/fusequery/query/src/configs/config.rs index 9c2502ead28e7..39fd9f528a243 100644 --- a/fusequery/query/src/configs/config.rs +++ b/fusequery/query/src/configs/config.rs @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: Apache-2.0. +use std::fmt; + use common_exception::ErrorCode; use common_exception::Result; use lazy_static::lazy_static; From dad5daf01c1b5838d9a6247f0f6d7e63de486233 Mon Sep 17 00:00:00 2001 From: wangzhen05 Date: Wed, 30 Jun 2021 12:45:25 +0800 Subject: [PATCH 3/7] refine code to remove the user and password information --- fusequery/query/src/configs/config.rs | 78 ++++++++++++++----- fusequery/query/src/configs/config_test.rs | 6 +- .../src/datasources/remote/remote_factory.rs | 4 +- 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/fusequery/query/src/configs/config.rs b/fusequery/query/src/configs/config.rs index 39fd9f528a243..70d3c5390f08c 100644 --- a/fusequery/query/src/configs/config.rs +++ b/fusequery/query/src/configs/config.rs @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0. -use std::fmt; +use std::{fmt, str::FromStr}; use common_exception::ErrorCode; use common_exception::Result; @@ -29,19 +29,8 @@ lazy_static! { ver }; } -impl fmt::Debug for Config{ - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{{ log_level: \"{}\", log_dir: \"{}\", num_cpus: {}, mysql_handler_host: \"{}\", - mysql_handler_port: {}, mysql_handler_thread_num: {}, clickhouse_handler_host: \"{}\", clickhouse_handler_clickhouse_handler_port: {}, - clickhouse_handler_thread_num: {}, flight_api_address: \"{}\", http_api_address: \"{}\", metric_api_address: \"{}\", - store_api_address: \"{}\", config_file: \"{}\", }}", - self.log_level, self.log_dir, self.num_cpus, self.mysql_handler_host, self.mysql_handler_port, - self.mysql_handler_thread_num, self.clickhouse_handler_host, self.clickhouse_handler_port, - self.clickhouse_handler_thread_num, self.flight_api_address, self.http_api_address, self.metric_api_address, - self.store_api_address, self.config_file) - } -} -#[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] + +#[derive(Clone, Debug, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] #[serde(default)] pub struct Config { #[structopt(long, env = "FUSE_QUERY_LOG_LEVEL", default_value = "INFO")] @@ -114,16 +103,67 @@ pub struct Config { #[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, + pub store_api_username: User, #[structopt(long, env = "STORE_API_PASSWORD", default_value = "root")] - pub store_api_password: String, + pub store_api_password: Password, #[structopt(long, short = "c", env = "CONFIG_FILE", default_value = "")] pub config_file: String, } +#[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] +#[serde(default)] +pub struct Password{ + pub store_api_password: String, +} + +impl AsRef for Password { + fn as_ref(&self) -> &String{ + &self.store_api_password + } +} + +impl FromStr for Password{ + type Err = ErrorCode; + fn from_str(s: &str) -> common_exception::Result { + Ok(Self{ + store_api_password: s.to_string(), + }) + } +} + +impl fmt::Debug for Password{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "******") + } +} +#[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] +#[serde(default)] +pub struct User{ + pub store_api_username: String, +} + +impl fmt::Debug for User { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "******") + } +} +impl AsRef for User { + fn as_ref(&self) -> &String { + &self.store_api_username + } +} + +impl FromStr for User{ + type Err = ErrorCode; + fn from_str(s: &str) -> common_exception::Result { + Ok(Self{ + store_api_username: s.to_string(), + }) + } +} impl Config { /// Default configs. @@ -142,8 +182,8 @@ impl Config { 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(), + store_api_username: User{store_api_username: "root".to_string()}, + store_api_password: Password{store_api_password: "root".to_string()}, config_file: "".to_string(), } } diff --git a/fusequery/query/src/configs/config_test.rs b/fusequery/query/src/configs/config_test.rs index d4dfb9f26decf..20defd201c0de 100644 --- a/fusequery/query/src/configs/config_test.rs +++ b/fusequery/query/src/configs/config_test.rs @@ -4,6 +4,8 @@ use common_exception::Result; +use crate::configs::config::{Password, User}; + #[test] fn test_config() -> Result<()> { use pretty_assertions::assert_eq; @@ -26,8 +28,8 @@ fn test_config() -> Result<()> { 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(), + store_api_username: User{store_api_username:"root".to_string()}, + store_api_password: Password{store_api_password: "root".to_string()}, config_file: "".to_string(), }; let actual = Config::default(); diff --git a/fusequery/query/src/datasources/remote/remote_factory.rs b/fusequery/query/src/datasources/remote/remote_factory.rs index 84d2151699c03..ac4a4fbdc5c2a 100644 --- a/fusequery/query/src/datasources/remote/remote_factory.rs +++ b/fusequery/query/src/datasources/remote/remote_factory.rs @@ -53,8 +53,8 @@ impl TryGetStoreClient for ClientProvider { async fn try_get_client(&self) -> Result { let client = StoreClient::try_create( &self.conf.store_api_address, - &self.conf.store_api_username, - &self.conf.store_api_password, + &self.conf.store_api_username.as_ref(), + &self.conf.store_api_password.as_ref(), ) .await .map_err(ErrorCode::from)?; From 01a0b9844f4d01a20a1a94761172cca7242744fd Mon Sep 17 00:00:00 2001 From: wangzhen05 Date: Wed, 30 Jun 2021 17:54:03 +0800 Subject: [PATCH 4/7] Add new line after each code block --- fusequery/query/src/configs/config.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fusequery/query/src/configs/config.rs b/fusequery/query/src/configs/config.rs index 70d3c5390f08c..7d8523bfc4b7d 100644 --- a/fusequery/query/src/configs/config.rs +++ b/fusequery/query/src/configs/config.rs @@ -31,7 +31,7 @@ lazy_static! { } #[derive(Clone, Debug, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] -#[serde(default)] + #[serde(default)] pub struct Config { #[structopt(long, env = "FUSE_QUERY_LOG_LEVEL", default_value = "INFO")] pub log_level: String, @@ -103,7 +103,7 @@ pub struct Config { #[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: User, @@ -113,6 +113,7 @@ pub struct Config { #[structopt(long, short = "c", env = "CONFIG_FILE", default_value = "")] pub config_file: String, } + #[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] #[serde(default)] pub struct Password{ @@ -139,6 +140,7 @@ impl fmt::Debug for Password{ write!(f, "******") } } + #[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] #[serde(default)] pub struct User{ @@ -150,6 +152,7 @@ impl fmt::Debug for User { write!(f, "******") } } + impl AsRef for User { fn as_ref(&self) -> &String { &self.store_api_username From da1dc077744979ed8f2c74ac6e7b8655b79c8fa9 Mon Sep 17 00:00:00 2001 From: wangzhen05 Date: Wed, 30 Jun 2021 19:34:21 +0800 Subject: [PATCH 5/7] remove empty space before #[serde(default)] --- fusequery/query/src/configs/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fusequery/query/src/configs/config.rs b/fusequery/query/src/configs/config.rs index 7d8523bfc4b7d..d33941230f5f8 100644 --- a/fusequery/query/src/configs/config.rs +++ b/fusequery/query/src/configs/config.rs @@ -31,7 +31,7 @@ lazy_static! { } #[derive(Clone, Debug, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] - #[serde(default)] +#[serde(default)] pub struct Config { #[structopt(long, env = "FUSE_QUERY_LOG_LEVEL", default_value = "INFO")] pub log_level: String, From a583eb974a609a293acc66cb7e054a69d7221e24 Mon Sep 17 00:00:00 2001 From: wangzhen05 Date: Wed, 30 Jun 2021 20:23:33 +0800 Subject: [PATCH 6/7] In compatible with master code --- fusequery/query/src/configs/config.rs | 47 +++++++++++++++------- fusequery/query/src/configs/config_test.rs | 15 ++++--- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/fusequery/query/src/configs/config.rs b/fusequery/query/src/configs/config.rs index 2397add69f750..c53795f2cb3e1 100644 --- a/fusequery/query/src/configs/config.rs +++ b/fusequery/query/src/configs/config.rs @@ -2,7 +2,8 @@ // // SPDX-License-Identifier: Apache-2.0. -use std::{fmt, str::FromStr}; +use std::fmt; +use std::str::FromStr; use common_exception::ErrorCode; use common_exception::Result; @@ -150,26 +151,32 @@ pub struct Config { #[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] #[serde(default)] -pub struct Password{ - pub store_api_password: String, +pub struct Password { + pub store_api_password: String, } impl AsRef for Password { - fn as_ref(&self) -> &String{ + fn as_ref(&self) -> &String { &self.store_api_password } } -impl FromStr for Password{ +impl FromStr for Password { type Err = ErrorCode; fn from_str(s: &str) -> common_exception::Result { - Ok(Self{ + Ok(Self { store_api_password: s.to_string(), }) } } -impl fmt::Debug for Password{ +impl ToString for Password { + fn to_string(&self) -> String { + self.store_api_password.clone() + } +} + +impl fmt::Debug for Password { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "******") } @@ -177,8 +184,14 @@ impl fmt::Debug for Password{ #[derive(Clone, serde::Deserialize, PartialEq, StructOpt, StructOptToml)] #[serde(default)] -pub struct User{ - pub store_api_username: String, +pub struct User { + pub store_api_username: String, +} + +impl ToString for User { + fn to_string(&self) -> String { + self.store_api_username.clone() + } } impl fmt::Debug for User { @@ -193,10 +206,10 @@ impl AsRef for User { } } -impl FromStr for User{ +impl FromStr for User { type Err = ErrorCode; fn from_str(s: &str) -> common_exception::Result { - Ok(Self{ + Ok(Self { store_api_username: s.to_string(), }) } @@ -219,8 +232,12 @@ impl Config { 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: User{store_api_username: "root".to_string()}, - store_api_password: Password{store_api_password: "root".to_string()}, + store_api_username: User { + store_api_username: "root".to_string(), + }, + store_api_password: Password { + store_api_password: "root".to_string(), + }, config_file: "".to_string(), } } @@ -287,8 +304,8 @@ impl Config { env_helper!(mut_config, http_api_address, String, HTTP_API_ADDRESS); env_helper!(mut_config, metric_api_address, String, METRICS_API_ADDRESS); env_helper!(mut_config, store_api_address, String, STORE_API_ADDRESS); - env_helper!(mut_config, store_api_username, String, STORE_API_USERNAME); - env_helper!(mut_config, store_api_password, String, STORE_API_PASSWORD); + env_helper!(mut_config, store_api_username, User, STORE_API_USERNAME); + env_helper!(mut_config, store_api_password, Password, STORE_API_PASSWORD); Ok(mut_config) } diff --git a/fusequery/query/src/configs/config_test.rs b/fusequery/query/src/configs/config_test.rs index 1bc023e633aab..8752303246616 100644 --- a/fusequery/query/src/configs/config_test.rs +++ b/fusequery/query/src/configs/config_test.rs @@ -4,7 +4,8 @@ use common_exception::Result; -use crate::configs::config::{Password, User}; +use crate::configs::config::Password; +use crate::configs::config::User; #[test] fn test_config() -> Result<()> { @@ -28,8 +29,12 @@ fn test_config() -> Result<()> { 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: User{store_api_username:"root".to_string()}, - store_api_password: Password{store_api_password: "root".to_string()}, + store_api_username: User { + store_api_username: "root".to_string(), + }, + store_api_password: Password { + store_api_password: "root".to_string(), + }, config_file: "".to_string(), }; let actual = Config::default(); @@ -97,8 +102,8 @@ fn test_config() -> Result<()> { assert_eq!("1.2.3.4:7071", configured.metric_api_address); assert_eq!("1.2.3.4:1234", configured.store_api_address); - assert_eq!("admin", configured.store_api_username); - assert_eq!("password!", configured.store_api_password); + assert_eq!("admin", configured.store_api_username.to_string()); + assert_eq!("password!", configured.store_api_password.to_string()); // clean up std::env::remove_var("FUSE_QUERY_LOG_LEVEL"); From ecfa8fd05d1372a57a432fc897427e71c8f468cb Mon Sep 17 00:00:00 2001 From: Winter Zhang Date: Wed, 30 Jun 2021 23:51:58 +0800 Subject: [PATCH 7/7] Update config.rs --- fusequery/query/src/configs/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fusequery/query/src/configs/config.rs b/fusequery/query/src/configs/config.rs index c53795f2cb3e1..e58bff2cb8c28 100644 --- a/fusequery/query/src/configs/config.rs +++ b/fusequery/query/src/configs/config.rs @@ -139,10 +139,10 @@ pub struct Config { #[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")] + #[structopt(long, env = STORE_API_USERNAME, default_value = "root")] pub store_api_username: User, - #[structopt(long, env = "STORE_API_PASSWORD", default_value = "root")] + #[structopt(long, env = STORE_API_PASSWORD, default_value = "root")] pub store_api_password: Password, #[structopt(long, short = "c", env = CONFIG_FILE, default_value = "")]