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

feat: support domain name as the ceresdb node addr #852

Merged
merged 2 commits into from
Apr 21, 2023
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
20 changes: 7 additions & 13 deletions src/bin/ceresdb-server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2022 CeresDB Project Authors. Licensed under Apache-2.0.
// Copyright 2022-2023 CeresDB Project Authors. Licensed under Apache-2.0.

//! The main entry point to start the server

use std::{env, net::IpAddr};
use std::env;

use ceresdb::{
config::{ClusterDeployment, Config},
Expand All @@ -12,8 +12,11 @@ use clap::{App, Arg};
use common_util::{panic, toml};
use log::info;

/// The ip address of current node.
/// By this environment variable, the address of current node can be overridden.
/// And it could be domain name or ip address, but no port follows it.
const NODE_ADDR: &str = "CERESDB_SERVER_ADDR";
/// By this environment variable, the cluster name of current node can be
/// overridden.
const CLUSTER_NAME: &str = "CLUSTER_NAME";

fn fetch_version() -> String {
Expand All @@ -36,14 +39,6 @@ fn fetch_version() -> String {
.join("\n")
}

// Parse the raw addr and panic if it is invalid.
fn parse_node_addr_or_fail(raw_addr: &str) -> IpAddr {
let socket_addr: IpAddr = raw_addr
.parse()
.unwrap_or_else(|_| panic!("invalid node addr, raw_addr:{raw_addr}"));
socket_addr
}

fn main() {
let version = fetch_version();
let matches = App::new("CeresDB Server")
Expand All @@ -67,8 +62,7 @@ fn main() {
};

if let Ok(node_addr) = env::var(NODE_ADDR) {
let ip = parse_node_addr_or_fail(&node_addr);
config.node.addr = ip.to_string();
config.node.addr = node_addr;
}
if let Ok(cluster) = env::var(CLUSTER_NAME) {
if let Some(ClusterDeployment::WithMeta(v)) = &mut config.cluster_deployment {
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use server::{
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(default)]
pub struct NodeInfo {
/// The address of the ceresdb node. It can be a domain name or an IP
/// address without port followed.
pub addr: String,
pub zone: String,
pub idc: String,
Expand Down