mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-25 17:30:41 +00:00
fix!: align gRPC CLI option names with config naming (#8021)
* fix: align gRPC CLI option names with config naming Signed-off-by: QuakeWang <wangfuzheng0814@foxmail.com> * fix: warn on deprecated metasrv grpc config Signed-off-by: QuakeWang <wangfuzheng0814@foxmail.com> --------- Signed-off-by: QuakeWang <wangfuzheng0814@foxmail.com>
This commit is contained in:
@@ -162,7 +162,7 @@ mod tests {
|
||||
&*output_dir.path().to_string_lossy(),
|
||||
"--http-addr",
|
||||
&http_addr,
|
||||
"--rpc-bind-addr",
|
||||
"--grpc-bind-addr",
|
||||
&rpc_addr,
|
||||
"--mysql-addr",
|
||||
&mysql_addr,
|
||||
|
||||
@@ -197,13 +197,17 @@ pub struct StartCommand {
|
||||
#[clap(long)]
|
||||
node_id: Option<u64>,
|
||||
/// The address to bind the gRPC server.
|
||||
#[clap(long, alias = "rpc-addr")]
|
||||
rpc_bind_addr: Option<String>,
|
||||
#[clap(long = "grpc-bind-addr", alias = "rpc-bind-addr", alias = "rpc-addr")]
|
||||
grpc_bind_addr: Option<String>,
|
||||
/// The address advertised to the metasrv, and used for connections from outside the host.
|
||||
/// If left empty or unset, the server will automatically use the IP address of the first network interface
|
||||
/// on the host, with the same port number as the one specified in `rpc_bind_addr`.
|
||||
#[clap(long, alias = "rpc-hostname")]
|
||||
rpc_server_addr: Option<String>,
|
||||
/// on the host, with the same port number as the one specified in `grpc_bind_addr`.
|
||||
#[clap(
|
||||
long = "grpc-server-addr",
|
||||
alias = "rpc-server-addr",
|
||||
alias = "rpc-hostname"
|
||||
)]
|
||||
grpc_server_addr: Option<String>,
|
||||
#[clap(long, value_delimiter = ',', num_args = 1..)]
|
||||
metasrv_addrs: Option<Vec<String>>,
|
||||
#[clap(short, long)]
|
||||
@@ -256,20 +260,20 @@ impl StartCommand {
|
||||
tokio_console_addr: global_options.tokio_console_addr.clone(),
|
||||
};
|
||||
|
||||
if let Some(addr) = &self.rpc_bind_addr {
|
||||
if let Some(addr) = &self.grpc_bind_addr {
|
||||
opts.grpc.bind_addr.clone_from(addr);
|
||||
} else if let Some(addr) = &opts.rpc_addr {
|
||||
warn!(
|
||||
"Use the deprecated attribute `DatanodeOptions.rpc_addr`, please use `grpc.addr` instead."
|
||||
"Use the deprecated attribute `DatanodeOptions.rpc_addr`, please use `grpc.bind_addr` instead."
|
||||
);
|
||||
opts.grpc.bind_addr.clone_from(addr);
|
||||
}
|
||||
|
||||
if let Some(server_addr) = &self.rpc_server_addr {
|
||||
if let Some(server_addr) = &self.grpc_server_addr {
|
||||
opts.grpc.server_addr.clone_from(server_addr);
|
||||
} else if let Some(server_addr) = &opts.rpc_hostname {
|
||||
warn!(
|
||||
"Use the deprecated attribute `DatanodeOptions.rpc_hostname`, please use `grpc.hostname` instead."
|
||||
"Use the deprecated attribute `DatanodeOptions.rpc_hostname`, please use `grpc.server_addr` instead."
|
||||
);
|
||||
opts.grpc.server_addr.clone_from(server_addr);
|
||||
}
|
||||
@@ -360,6 +364,7 @@ mod tests {
|
||||
use std::io::Write;
|
||||
use std::time::Duration;
|
||||
|
||||
use clap::{CommandFactory, Parser};
|
||||
use common_config::ENV_VAR_SEP;
|
||||
use common_test_util::temp_dir::create_named_temp_file;
|
||||
use object_store::config::{FileConfig, GcsConfig, ObjectStoreConfig, S3Config};
|
||||
@@ -402,8 +407,8 @@ mod tests {
|
||||
node_id = 42
|
||||
|
||||
[grpc]
|
||||
addr = "127.0.0.1:3001"
|
||||
hostname = "127.0.0.1"
|
||||
bind_addr = "127.0.0.1:3001"
|
||||
server_addr = "127.0.0.1"
|
||||
runtime_size = 8
|
||||
|
||||
[meta_client]
|
||||
@@ -449,6 +454,7 @@ mod tests {
|
||||
let options = cmd.load_options(&Default::default()).unwrap().component;
|
||||
|
||||
assert_eq!("127.0.0.1:3001".to_string(), options.grpc.bind_addr);
|
||||
assert_eq!("127.0.0.1".to_string(), options.grpc.server_addr);
|
||||
assert_eq!(Some(42), options.node_id);
|
||||
|
||||
let DatanodeWalConfig::RaftEngine(raft_engine_config) = options.wal else {
|
||||
@@ -661,4 +667,55 @@ mod tests {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_grpc_cli_aliases() {
|
||||
let command = StartCommand::try_parse_from([
|
||||
"datanode",
|
||||
"--grpc-bind-addr",
|
||||
"127.0.0.1:13001",
|
||||
"--grpc-server-addr",
|
||||
"10.0.0.1:13001",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:13001"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.1:13001"));
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"datanode",
|
||||
"--rpc-bind-addr",
|
||||
"127.0.0.1:23001",
|
||||
"--rpc-server-addr",
|
||||
"10.0.0.2:23001",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:23001"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.2:23001"));
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"datanode",
|
||||
"--rpc-addr",
|
||||
"127.0.0.1:33001",
|
||||
"--rpc-hostname",
|
||||
"10.0.0.3:33001",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:33001"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.3:33001"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help_uses_grpc_option_names() {
|
||||
let mut cmd = StartCommand::command();
|
||||
let mut help = Vec::new();
|
||||
cmd.write_long_help(&mut help).unwrap();
|
||||
let help = String::from_utf8(help).unwrap();
|
||||
|
||||
assert!(help.contains("--grpc-bind-addr"));
|
||||
assert!(help.contains("--grpc-server-addr"));
|
||||
assert!(!help.contains("--rpc-bind-addr"));
|
||||
assert!(!help.contains("--rpc-server-addr"));
|
||||
assert!(!help.contains("--rpc-addr"));
|
||||
assert!(!help.contains("--rpc-hostname"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,13 +139,17 @@ struct StartCommand {
|
||||
#[clap(long)]
|
||||
node_id: Option<u64>,
|
||||
/// Bind address for the gRPC server.
|
||||
#[clap(long, alias = "rpc-addr")]
|
||||
rpc_bind_addr: Option<String>,
|
||||
#[clap(long = "grpc-bind-addr", alias = "rpc-bind-addr", alias = "rpc-addr")]
|
||||
grpc_bind_addr: Option<String>,
|
||||
/// The address advertised to the metasrv, and used for connections from outside the host.
|
||||
/// If left empty or unset, the server will automatically use the IP address of the first network interface
|
||||
/// on the host, with the same port number as the one specified in `rpc_bind_addr`.
|
||||
#[clap(long, alias = "rpc-hostname")]
|
||||
rpc_server_addr: Option<String>,
|
||||
/// on the host, with the same port number as the one specified in `grpc_bind_addr`.
|
||||
#[clap(
|
||||
long = "grpc-server-addr",
|
||||
alias = "rpc-server-addr",
|
||||
alias = "rpc-hostname"
|
||||
)]
|
||||
grpc_server_addr: Option<String>,
|
||||
/// Metasrv address list;
|
||||
#[clap(long, value_delimiter = ',', num_args = 1..)]
|
||||
metasrv_addrs: Option<Vec<String>>,
|
||||
@@ -207,11 +211,11 @@ impl StartCommand {
|
||||
tokio_console_addr: global_options.tokio_console_addr.clone(),
|
||||
};
|
||||
|
||||
if let Some(addr) = &self.rpc_bind_addr {
|
||||
if let Some(addr) = &self.grpc_bind_addr {
|
||||
opts.grpc.bind_addr.clone_from(addr);
|
||||
}
|
||||
|
||||
if let Some(server_addr) = &self.rpc_server_addr {
|
||||
if let Some(server_addr) = &self.grpc_server_addr {
|
||||
opts.grpc.server_addr.clone_from(server_addr);
|
||||
}
|
||||
|
||||
@@ -432,3 +436,61 @@ impl StartCommand {
|
||||
Ok(Instance::new(flownode, guard))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use clap::{CommandFactory, Parser};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_grpc_cli_aliases() {
|
||||
let command = StartCommand::try_parse_from([
|
||||
"flownode",
|
||||
"--grpc-bind-addr",
|
||||
"127.0.0.1:14004",
|
||||
"--grpc-server-addr",
|
||||
"10.0.0.1:14004",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:14004"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.1:14004"));
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"flownode",
|
||||
"--rpc-bind-addr",
|
||||
"127.0.0.1:24004",
|
||||
"--rpc-server-addr",
|
||||
"10.0.0.2:24004",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:24004"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.2:24004"));
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"flownode",
|
||||
"--rpc-addr",
|
||||
"127.0.0.1:34004",
|
||||
"--rpc-hostname",
|
||||
"10.0.0.3:34004",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:34004"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.3:34004"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help_uses_grpc_option_names() {
|
||||
let mut cmd = StartCommand::command();
|
||||
let mut help = Vec::new();
|
||||
cmd.write_long_help(&mut help).unwrap();
|
||||
let help = String::from_utf8(help).unwrap();
|
||||
|
||||
assert!(help.contains("--grpc-bind-addr"));
|
||||
assert!(help.contains("--grpc-server-addr"));
|
||||
assert!(!help.contains("--rpc-bind-addr"));
|
||||
assert!(!help.contains("--rpc-server-addr"));
|
||||
assert!(!help.contains("--rpc-addr"));
|
||||
assert!(!help.contains("--rpc-hostname"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,21 +152,33 @@ impl SubCommand {
|
||||
#[derive(Debug, Default, Parser)]
|
||||
pub struct StartCommand {
|
||||
/// The address to bind the gRPC server.
|
||||
#[clap(long, alias = "rpc-addr")]
|
||||
rpc_bind_addr: Option<String>,
|
||||
#[clap(long = "grpc-bind-addr", alias = "rpc-bind-addr", alias = "rpc-addr")]
|
||||
grpc_bind_addr: Option<String>,
|
||||
/// The address advertised to the metasrv, and used for connections from outside the host.
|
||||
/// If left empty or unset, the server will automatically use the IP address of the first network interface
|
||||
/// on the host, with the same port number as the one specified in `rpc_bind_addr`.
|
||||
#[clap(long, alias = "rpc-hostname")]
|
||||
rpc_server_addr: Option<String>,
|
||||
/// on the host, with the same port number as the one specified in `grpc_bind_addr`.
|
||||
#[clap(
|
||||
long = "grpc-server-addr",
|
||||
alias = "rpc-server-addr",
|
||||
alias = "rpc-hostname"
|
||||
)]
|
||||
grpc_server_addr: Option<String>,
|
||||
/// The address to bind the internal gRPC server.
|
||||
#[clap(long, alias = "internal-rpc-addr")]
|
||||
internal_rpc_bind_addr: Option<String>,
|
||||
#[clap(
|
||||
long = "internal-grpc-bind-addr",
|
||||
alias = "internal-rpc-bind-addr",
|
||||
alias = "internal-rpc-addr"
|
||||
)]
|
||||
internal_grpc_bind_addr: Option<String>,
|
||||
/// The address advertised to the metasrv, and used for connections from outside the host.
|
||||
/// If left empty or unset, the server will automatically use the IP address of the first network interface
|
||||
/// on the host, with the same port number as the one specified in `internal_rpc_bind_addr`.
|
||||
#[clap(long, alias = "internal-rpc-hostname")]
|
||||
internal_rpc_server_addr: Option<String>,
|
||||
/// on the host, with the same port number as the one specified in `internal_grpc_bind_addr`.
|
||||
#[clap(
|
||||
long = "internal-grpc-server-addr",
|
||||
alias = "internal-rpc-server-addr",
|
||||
alias = "internal-rpc-hostname"
|
||||
)]
|
||||
internal_grpc_server_addr: Option<String>,
|
||||
#[clap(long)]
|
||||
http_addr: Option<String>,
|
||||
#[clap(long)]
|
||||
@@ -258,16 +270,16 @@ impl StartCommand {
|
||||
opts.http.disable_dashboard = disable_dashboard;
|
||||
}
|
||||
|
||||
if let Some(addr) = &self.rpc_bind_addr {
|
||||
if let Some(addr) = &self.grpc_bind_addr {
|
||||
opts.grpc.bind_addr.clone_from(addr);
|
||||
opts.grpc.tls = merge_tls_option(&opts.grpc.tls, tls_opts.clone());
|
||||
}
|
||||
|
||||
if let Some(addr) = &self.rpc_server_addr {
|
||||
if let Some(addr) = &self.grpc_server_addr {
|
||||
opts.grpc.server_addr.clone_from(addr);
|
||||
}
|
||||
|
||||
if let Some(addr) = &self.internal_rpc_bind_addr {
|
||||
if let Some(addr) = &self.internal_grpc_bind_addr {
|
||||
if let Some(internal_grpc) = &mut opts.internal_grpc {
|
||||
internal_grpc.bind_addr = addr.clone();
|
||||
} else {
|
||||
@@ -280,7 +292,7 @@ impl StartCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(addr) = &self.internal_rpc_server_addr {
|
||||
if let Some(addr) = &self.internal_grpc_server_addr {
|
||||
if let Some(internal_grpc) = &mut opts.internal_grpc {
|
||||
internal_grpc.server_addr = addr.clone();
|
||||
} else {
|
||||
@@ -515,6 +527,7 @@ mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use auth::{Identity, Password, UserProviderRef};
|
||||
use clap::{CommandFactory, Parser};
|
||||
use common_base::readable_size::ReadableSize;
|
||||
use common_config::ENV_VAR_SEP;
|
||||
use common_test_util::temp_dir::create_named_temp_file;
|
||||
@@ -530,8 +543,8 @@ mod tests {
|
||||
http_addr: Some("127.0.0.1:1234".to_string()),
|
||||
mysql_addr: Some("127.0.0.1:5678".to_string()),
|
||||
postgres_addr: Some("127.0.0.1:5432".to_string()),
|
||||
internal_rpc_bind_addr: Some("127.0.0.1:4010".to_string()),
|
||||
internal_rpc_server_addr: Some("10.0.0.24:4010".to_string()),
|
||||
internal_grpc_bind_addr: Some("127.0.0.1:4010".to_string()),
|
||||
internal_grpc_server_addr: Some("10.0.0.24:4010".to_string()),
|
||||
influxdb_enable: Some(false),
|
||||
disable_dashboard: Some(false),
|
||||
..Default::default()
|
||||
@@ -744,4 +757,97 @@ mod tests {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_grpc_cli_aliases() {
|
||||
let command = StartCommand::try_parse_from([
|
||||
"frontend",
|
||||
"--grpc-bind-addr",
|
||||
"127.0.0.1:14001",
|
||||
"--grpc-server-addr",
|
||||
"10.0.0.1:14001",
|
||||
"--internal-grpc-bind-addr",
|
||||
"127.0.0.1:14010",
|
||||
"--internal-grpc-server-addr",
|
||||
"10.0.0.1:14010",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:14001"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.1:14001"));
|
||||
assert_eq!(
|
||||
command.internal_grpc_bind_addr.as_deref(),
|
||||
Some("127.0.0.1:14010")
|
||||
);
|
||||
assert_eq!(
|
||||
command.internal_grpc_server_addr.as_deref(),
|
||||
Some("10.0.0.1:14010")
|
||||
);
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"frontend",
|
||||
"--rpc-bind-addr",
|
||||
"127.0.0.1:24001",
|
||||
"--rpc-server-addr",
|
||||
"10.0.0.2:24001",
|
||||
"--internal-rpc-bind-addr",
|
||||
"127.0.0.1:24010",
|
||||
"--internal-rpc-server-addr",
|
||||
"10.0.0.2:24010",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:24001"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.2:24001"));
|
||||
assert_eq!(
|
||||
command.internal_grpc_bind_addr.as_deref(),
|
||||
Some("127.0.0.1:24010")
|
||||
);
|
||||
assert_eq!(
|
||||
command.internal_grpc_server_addr.as_deref(),
|
||||
Some("10.0.0.2:24010")
|
||||
);
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"frontend",
|
||||
"--rpc-addr",
|
||||
"127.0.0.1:34001",
|
||||
"--rpc-hostname",
|
||||
"10.0.0.3:34001",
|
||||
"--internal-rpc-addr",
|
||||
"127.0.0.1:34010",
|
||||
"--internal-rpc-hostname",
|
||||
"10.0.0.3:34010",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:34001"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.3:34001"));
|
||||
assert_eq!(
|
||||
command.internal_grpc_bind_addr.as_deref(),
|
||||
Some("127.0.0.1:34010")
|
||||
);
|
||||
assert_eq!(
|
||||
command.internal_grpc_server_addr.as_deref(),
|
||||
Some("10.0.0.3:34010")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help_uses_grpc_option_names() {
|
||||
let mut cmd = StartCommand::command();
|
||||
let mut help = Vec::new();
|
||||
cmd.write_long_help(&mut help).unwrap();
|
||||
let help = String::from_utf8(help).unwrap();
|
||||
|
||||
assert!(help.contains("--grpc-bind-addr"));
|
||||
assert!(help.contains("--grpc-server-addr"));
|
||||
assert!(help.contains("--internal-grpc-bind-addr"));
|
||||
assert!(help.contains("--internal-grpc-server-addr"));
|
||||
assert!(!help.contains("--rpc-bind-addr"));
|
||||
assert!(!help.contains("--rpc-server-addr"));
|
||||
assert!(!help.contains("--rpc-addr"));
|
||||
assert!(!help.contains("--rpc-hostname"));
|
||||
assert!(!help.contains("--internal-rpc-bind-addr"));
|
||||
assert!(!help.contains("--internal-rpc-server-addr"));
|
||||
assert!(!help.contains("--internal-rpc-addr"));
|
||||
assert!(!help.contains("--internal-rpc-hostname"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ use clap::Parser;
|
||||
use common_base::Plugins;
|
||||
use common_config::Configurable;
|
||||
use common_meta::distributed_time_constants::init_distributed_time_constants;
|
||||
use common_telemetry::info;
|
||||
use common_telemetry::logging::{DEFAULT_LOGGING_DIR, TracingOptions};
|
||||
use common_telemetry::{info, warn};
|
||||
use common_version::{short_version, verbose_version};
|
||||
use meta_srv::bootstrap::{MetasrvInstance, metasrv_builder};
|
||||
use meta_srv::metasrv::BackendImpl;
|
||||
@@ -141,13 +141,17 @@ impl SubCommand {
|
||||
#[derive(Default, Parser)]
|
||||
pub struct StartCommand {
|
||||
/// The address to bind the gRPC server.
|
||||
#[clap(long, alias = "bind-addr")]
|
||||
rpc_bind_addr: Option<String>,
|
||||
#[clap(long = "grpc-bind-addr", alias = "rpc-bind-addr", alias = "bind-addr")]
|
||||
grpc_bind_addr: Option<String>,
|
||||
/// The communication server address for the frontend and datanode to connect to metasrv.
|
||||
/// If left empty or unset, the server will automatically use the IP address of the first network interface
|
||||
/// on the host, with the same port number as the one specified in `rpc_bind_addr`.
|
||||
#[clap(long, alias = "server-addr")]
|
||||
rpc_server_addr: Option<String>,
|
||||
/// on the host, with the same port number as the one specified in `grpc_bind_addr`.
|
||||
#[clap(
|
||||
long = "grpc-server-addr",
|
||||
alias = "rpc-server-addr",
|
||||
alias = "server-addr"
|
||||
)]
|
||||
grpc_server_addr: Option<String>,
|
||||
#[clap(long, alias = "store-addr", value_delimiter = ',', num_args = 1..)]
|
||||
store_addrs: Option<Vec<String>>,
|
||||
#[clap(short, long)]
|
||||
@@ -179,8 +183,8 @@ pub struct StartCommand {
|
||||
impl Debug for StartCommand {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("StartCommand")
|
||||
.field("rpc_bind_addr", &self.rpc_bind_addr)
|
||||
.field("rpc_server_addr", &self.rpc_server_addr)
|
||||
.field("grpc_bind_addr", &self.grpc_bind_addr)
|
||||
.field("grpc_server_addr", &self.grpc_server_addr)
|
||||
.field("store_addrs", &self.sanitize_store_addrs())
|
||||
.field("config_file", &self.config_file)
|
||||
.field("selector", &self.selector)
|
||||
@@ -240,18 +244,24 @@ impl StartCommand {
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
if let Some(addr) = &self.rpc_bind_addr {
|
||||
if let Some(addr) = &self.grpc_bind_addr {
|
||||
opts.bind_addr.clone_from(addr);
|
||||
opts.grpc.bind_addr.clone_from(addr);
|
||||
} else if !opts.bind_addr.is_empty() {
|
||||
warn!(
|
||||
"Use the deprecated attribute `MetasrvOptions.bind_addr`, please use `grpc.bind_addr` instead."
|
||||
);
|
||||
opts.grpc.bind_addr.clone_from(&opts.bind_addr);
|
||||
}
|
||||
|
||||
#[allow(deprecated)]
|
||||
if let Some(addr) = &self.rpc_server_addr {
|
||||
if let Some(addr) = &self.grpc_server_addr {
|
||||
opts.server_addr.clone_from(addr);
|
||||
opts.grpc.server_addr.clone_from(addr);
|
||||
} else if !opts.server_addr.is_empty() {
|
||||
warn!(
|
||||
"Use the deprecated attribute `MetasrvOptions.server_addr`, please use `grpc.server_addr` instead."
|
||||
);
|
||||
opts.grpc.server_addr.clone_from(&opts.server_addr);
|
||||
}
|
||||
|
||||
@@ -353,6 +363,7 @@ impl StartCommand {
|
||||
mod tests {
|
||||
use std::io::Write;
|
||||
|
||||
use clap::{CommandFactory, Parser};
|
||||
use common_base::readable_size::ReadableSize;
|
||||
use common_config::ENV_VAR_SEP;
|
||||
use common_test_util::temp_dir::create_named_temp_file;
|
||||
@@ -363,8 +374,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_read_from_cmd() {
|
||||
let cmd = StartCommand {
|
||||
rpc_bind_addr: Some("127.0.0.1:3002".to_string()),
|
||||
rpc_server_addr: Some("127.0.0.1:3002".to_string()),
|
||||
grpc_bind_addr: Some("127.0.0.1:3002".to_string()),
|
||||
grpc_server_addr: Some("127.0.0.1:3002".to_string()),
|
||||
store_addrs: Some(vec!["127.0.0.1:2380".to_string()]),
|
||||
selector: Some("LoadBased".to_string()),
|
||||
..Default::default()
|
||||
@@ -432,8 +443,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_load_log_options_from_cli() {
|
||||
let cmd = StartCommand {
|
||||
rpc_bind_addr: Some("127.0.0.1:3002".to_string()),
|
||||
rpc_server_addr: Some("127.0.0.1:3002".to_string()),
|
||||
grpc_bind_addr: Some("127.0.0.1:3002".to_string()),
|
||||
grpc_server_addr: Some("127.0.0.1:3002".to_string()),
|
||||
store_addrs: Some(vec!["127.0.0.1:2380".to_string()]),
|
||||
selector: Some("LoadBased".to_string()),
|
||||
..Default::default()
|
||||
@@ -520,4 +531,55 @@ mod tests {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_grpc_cli_aliases() {
|
||||
let command = StartCommand::try_parse_from([
|
||||
"metasrv",
|
||||
"--grpc-bind-addr",
|
||||
"127.0.0.1:13002",
|
||||
"--grpc-server-addr",
|
||||
"10.0.0.1:13002",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:13002"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.1:13002"));
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"metasrv",
|
||||
"--rpc-bind-addr",
|
||||
"127.0.0.1:23002",
|
||||
"--rpc-server-addr",
|
||||
"10.0.0.2:23002",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:23002"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.2:23002"));
|
||||
|
||||
let command = StartCommand::try_parse_from([
|
||||
"metasrv",
|
||||
"--bind-addr",
|
||||
"127.0.0.1:33002",
|
||||
"--server-addr",
|
||||
"10.0.0.3:33002",
|
||||
])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:33002"));
|
||||
assert_eq!(command.grpc_server_addr.as_deref(), Some("10.0.0.3:33002"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help_uses_grpc_option_names() {
|
||||
let mut cmd = StartCommand::command();
|
||||
let mut help = Vec::new();
|
||||
cmd.write_long_help(&mut help).unwrap();
|
||||
let help = String::from_utf8(help).unwrap();
|
||||
|
||||
assert!(help.contains("--grpc-bind-addr"));
|
||||
assert!(help.contains("--grpc-server-addr"));
|
||||
assert!(!help.contains("--rpc-bind-addr"));
|
||||
assert!(!help.contains("--rpc-server-addr"));
|
||||
assert!(!help.contains("--bind-addr"));
|
||||
assert!(!help.contains("--server-addr"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,8 +212,8 @@ impl App for Instance {
|
||||
pub struct StartCommand {
|
||||
#[clap(long)]
|
||||
http_addr: Option<String>,
|
||||
#[clap(long, alias = "rpc-addr")]
|
||||
rpc_bind_addr: Option<String>,
|
||||
#[clap(long = "grpc-bind-addr", alias = "rpc-bind-addr", alias = "rpc-addr")]
|
||||
grpc_bind_addr: Option<String>,
|
||||
#[clap(long)]
|
||||
mysql_addr: Option<String>,
|
||||
#[clap(long)]
|
||||
@@ -299,7 +299,7 @@ impl StartCommand {
|
||||
.to_string();
|
||||
}
|
||||
|
||||
if let Some(addr) = &self.rpc_bind_addr {
|
||||
if let Some(addr) = &self.grpc_bind_addr {
|
||||
// frontend grpc addr conflict with datanode default grpc addr
|
||||
let datanode_grpc_addr = DatanodeOptions::default().grpc.bind_addr;
|
||||
if addr.eq(&datanode_grpc_addr) {
|
||||
@@ -755,6 +755,7 @@ mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use auth::{Identity, Password, UserProviderRef};
|
||||
use clap::{CommandFactory, Parser};
|
||||
use common_base::readable_size::ReadableSize;
|
||||
use common_config::ENV_VAR_SEP;
|
||||
use common_test_util::temp_dir::create_named_temp_file;
|
||||
@@ -1000,6 +1001,35 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_grpc_bind_addr_aliases() {
|
||||
let command =
|
||||
StartCommand::try_parse_from(["standalone", "--grpc-bind-addr", "127.0.0.1:14001"])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:14001"));
|
||||
|
||||
let command =
|
||||
StartCommand::try_parse_from(["standalone", "--rpc-bind-addr", "127.0.0.1:24001"])
|
||||
.unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:24001"));
|
||||
|
||||
let command =
|
||||
StartCommand::try_parse_from(["standalone", "--rpc-addr", "127.0.0.1:34001"]).unwrap();
|
||||
assert_eq!(command.grpc_bind_addr.as_deref(), Some("127.0.0.1:34001"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_help_uses_grpc_option_names() {
|
||||
let mut cmd = StartCommand::command();
|
||||
let mut help = Vec::new();
|
||||
cmd.write_long_help(&mut help).unwrap();
|
||||
let help = String::from_utf8(help).unwrap();
|
||||
|
||||
assert!(help.contains("--grpc-bind-addr"));
|
||||
assert!(!help.contains("--rpc-bind-addr"));
|
||||
assert!(!help.contains("--rpc-addr"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_load_default_standalone_options() {
|
||||
let options =
|
||||
|
||||
Reference in New Issue
Block a user