Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: allow wildcard address for advertise-status-addr to keep compatible with tidb-operator (#8016) #8046

Merged
merged 6 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/src/bin/tikv-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ fn main() {
.value_name("IP:PORT")
.help("Set the HTTP listening address for the status report service"),
)
.arg(
Arg::with_name("advertise-status-addr")
.long("advertise-status-addr")
.takes_value(true)
.value_name("IP:PORT")
.help("Set the advertise listening address for the client communication of status report service"),
)
.arg(
Arg::with_name("data-dir")
.long("data-dir")
Expand Down
1 change: 1 addition & 0 deletions cmd/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ impl TiKVServer {
// Start the status server.
if let Err(e) = status_server.start(
self.config.server.status_addr.clone(),
self.config.server.advertise_status_addr.clone(),
&self.config.security,
) {
error!(
Expand Down
4 changes: 4 additions & 0 deletions cmd/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ pub fn overwrite_config_with_cmd_args(config: &mut TiKvConfig, matches: &ArgMatc
config.server.status_addr = status_addr.to_owned();
}

if let Some(advertise_status_addr) = matches.value_of("advertise-status-addr") {
config.server.advertise_status_addr = advertise_status_addr.to_owned();
}

if let Some(data_dir) = matches.value_of("data-dir") {
config.storage.data_dir = data_dir.to_owned();
}
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,8 @@ mod readpool_tests {
#[serde(default)]
#[serde(rename_all = "kebab-case")]
pub struct TiKvConfig {
#[doc(hidden)]
#[serde(skip_serializing)]
#[config(hidden)]
pub cfg_path: String,

Expand Down
38 changes: 35 additions & 3 deletions src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ pub struct Config {

// These are related to TiKV status.
pub status_addr: String,

// Status server's advertise listening address for outer communication.
// If not set, the status server's listening address will be used.
pub advertise_status_addr: String,

pub status_thread_pool_size: usize,

pub max_grpc_send_msg_len: i32,
Expand Down Expand Up @@ -125,6 +130,7 @@ impl Default for Config {
labels: HashMap::default(),
advertise_addr: DEFAULT_ADVERTISE_LISTENING_ADDR.to_owned(),
status_addr: DEFAULT_STATUS_ADDR.to_owned(),
advertise_status_addr: DEFAULT_ADVERTISE_LISTENING_ADDR.to_owned(),
status_thread_pool_size: 1,
max_grpc_send_msg_len: DEFAULT_MAX_GRPC_SEND_MSG_LEN,
grpc_compression_type: GrpcCompressionType::None,
Expand Down Expand Up @@ -185,12 +191,30 @@ impl Config {
self.advertise_addr
));
}
if self.status_addr.is_empty() && !self.advertise_status_addr.is_empty() {
return Err(box_err!("status-addr can not be empty"));
}
if !self.status_addr.is_empty() {
box_try!(config::check_addr(&self.status_addr));
if !self.advertise_status_addr.is_empty() {
box_try!(config::check_addr(&self.advertise_status_addr));
if self.advertise_status_addr.starts_with("0.0.0.0") {
return Err(box_err!(
"invalid advertise-status-addr: {:?}",
self.advertise_status_addr
));
}
} else {
info!(
"no advertise-status-addr is specified, falling back to status-addr";
"status-addr" => %self.status_addr
);
self.advertise_status_addr = self.status_addr.clone();
}
}
if self.status_addr == self.advertise_addr {
if self.advertise_status_addr == self.advertise_addr {
return Err(box_err!(
"status-addr has already been used: {:?}",
"advertise-status-addr has already been used: {:?}",
self.advertise_addr
));
}
Expand Down Expand Up @@ -286,8 +310,10 @@ mod tests {
fn test_config_validate() {
let mut cfg = Config::default();
assert!(cfg.advertise_addr.is_empty());
assert!(cfg.advertise_status_addr.is_empty());
cfg.validate().unwrap();
assert_eq!(cfg.addr, cfg.advertise_addr);
assert_eq!(cfg.status_addr, cfg.advertise_status_addr);

let mut invalid_cfg = cfg.clone();
invalid_cfg.concurrent_send_snap_limit = 0;
Expand All @@ -311,9 +337,15 @@ mod tests {
invalid_cfg.advertise_addr = "127.0.0.1:1000".to_owned();
invalid_cfg.validate().unwrap();

invalid_cfg = Config::default();
invalid_cfg.status_addr = "0.0.0.0:1000".to_owned();
invalid_cfg.validate().unwrap();
invalid_cfg.advertise_status_addr = "0.0.0.0:1000".to_owned();
assert!(invalid_cfg.validate().is_err());

let mut invalid_cfg = cfg.clone();
invalid_cfg.advertise_addr = "127.0.0.1:1000".to_owned();
invalid_cfg.status_addr = "127.0.0.1:1000".to_owned();
invalid_cfg.advertise_status_addr = "127.0.0.1:1000".to_owned();
assert!(invalid_cfg.validate().is_err());

let mut invalid_cfg = cfg.clone();
Expand Down
6 changes: 5 additions & 1 deletion src/server/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ where
} else {
store.set_address(cfg.advertise_addr.clone())
}
if cfg.advertise_status_addr.is_empty() {
store.set_status_address(cfg.status_addr.clone());
} else {
store.set_status_address(cfg.advertise_status_addr.clone())
}
store.set_version(env!("CARGO_PKG_VERSION").to_string());
store.set_status_address(cfg.status_addr.clone());

if let Ok(path) = std::env::current_exe() {
if let Some(path) = path.parent() {
Expand Down
Loading