Skip to content
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Format
run: cargo fmt --all -- --check

Expand All @@ -33,6 +38,10 @@ jobs:
- macos-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Test
run: cargo test --all-targets --workspace
env:
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "clippy", "rust-analyzer"]
9 changes: 5 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ impl Config {
self.output_dir = PathBuf::from(output_dir);
}

if let Ok(timeout) = env::var(ENV_TIMEOUT) {
if let Ok(timeout) = timeout.parse::<u64>() {
self.timeout_seconds = timeout;
}
if let Some(timeout) = env::var(ENV_TIMEOUT)
.ok()
.and_then(|s| s.parse::<u64>().ok())
{
self.timeout_seconds = timeout;
}

self.no_progress_animation = env::var(ENV_NO_PROGRESS)
Expand Down
28 changes: 13 additions & 15 deletions src/config_loader/config_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,15 @@ fn parse_config_content(
continue;
}

if line.starts_with(LOG_DIR_KEY) {
if let Some(log_dir) = extract_value(line) {
if let Some(install) = install_dir {
if log_dir.contains("${DORIS_HOME}") {
let replaced =
log_dir.replace("${DORIS_HOME}", install.to_str().unwrap_or(""));
config.log_dir = PathBuf::from(replaced);
} else {
config.log_dir = PathBuf::from(log_dir);
}
} else {
if line.starts_with(LOG_DIR_KEY)
&& let Some(log_dir) = extract_value(line)
{
match install_dir {
Some(install) if log_dir.contains("${DORIS_HOME}") => {
let replaced = log_dir.replace("${DORIS_HOME}", install.to_str().unwrap_or(""));
config.log_dir = PathBuf::from(replaced);
}
_ => {
config.log_dir = PathBuf::from(log_dir);
}
}
Expand Down Expand Up @@ -260,10 +258,10 @@ fn parse_path_key_value(line: &str, key: &str, value: &mut Option<PathBuf>) -> R

/// Generic key-value parser
fn parse_key_value<T: FromStr>(line: &str, key: &str, value: &mut Option<T>) -> Result<()> {
if let Some(val_str) = regex_utils::extract_key_value(line, key) {
if let Ok(parsed_val) = val_str.parse::<T>() {
*value = Some(parsed_val);
}
if let Some(parsed_val) =
regex_utils::extract_key_value(line, key).and_then(|s| s.parse::<T>().ok())
{
*value = Some(parsed_val);
}
Ok(())
}
8 changes: 4 additions & 4 deletions src/config_loader/config_persister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ pub fn load_persisted_config() -> Result<DorisConfig> {
return Ok(from_persistent_config(persistent_config));
}
Err(e) => {
if e.to_string().contains("missing field `process`") {
if let Some(config) = migrate_legacy_config(&content, &config_path) {
return Ok(config);
}
if e.to_string().contains("missing field `process`")
&& migrate_legacy_config(&content, &config_path).is_some()
{
return Ok(migrate_legacy_config(&content, &config_path).unwrap());
}

last_error = Some(CliError::ConfigError(format!(
Expand Down
77 changes: 40 additions & 37 deletions src/config_loader/process_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ fn detect_process_detailed(env: Environment) -> Result<ProcessDetectionResult> {
pub fn get_process_command(pid: u32) -> Result<String> {
// Try /proc/PID/cmdline on Linux (most direct and reliable when available)
let proc_cmdline = Path::new("/proc").join(pid.to_string()).join("cmdline");
if proc_cmdline.exists() {
if let Ok(content) = std::fs::read_to_string(&proc_cmdline) {
let command = content.replace('\0', " ").trim().to_string();
if !command.is_empty() {
return Ok(command);
}
if proc_cmdline.exists()
&& let Ok(content) = std::fs::read_to_string(&proc_cmdline)
{
let command = content.replace('\0', " ").trim().to_string();
if !command.is_empty() {
return Ok(command);
}
}

Expand All @@ -104,14 +104,12 @@ pub fn get_process_command(pid: u32) -> Result<String> {
if let Ok(output) = Command::new("ps")
.args(["-p", &pid.to_string(), "-o", format])
.output()
&& output.status.success()
&& let Ok(s) = String::from_utf8(output.stdout)
{
if output.status.success() {
if let Ok(s) = String::from_utf8(output.stdout) {
let cmd = s.trim().to_string();
if !cmd.is_empty() {
return Ok(cmd);
}
}
let cmd = s.trim().to_string();
if !cmd.is_empty() {
return Ok(cmd);
}
}
}
Expand Down Expand Up @@ -195,12 +193,17 @@ pub fn get_paths(env: Environment) -> Result<(PathBuf, PathBuf)> {
/// Get paths by PID for the specified environment
fn get_paths_by_pid(pid: u32) -> (PathBuf, PathBuf) {
let grep_pattern = "DORIS_HOME|JAVA_HOME";
if let Ok(environ) = read_proc_environ_by_pid(pid, grep_pattern) {
if let Some(doris_home) = regex_utils::extract_env_var(&environ, "DORIS_HOME") {
let java_home = regex_utils::extract_env_var(&environ, "JAVA_HOME")
.unwrap_or_else(|| "/opt/jdk".to_string());
return (PathBuf::from(doris_home), PathBuf::from(java_home));
}
if let Some((doris_home, java_home)) = read_proc_environ_by_pid(pid, grep_pattern)
.ok()
.and_then(|envs| {
regex_utils::extract_env_var(&envs, "DORIS_HOME").map(|home| {
let java_home = regex_utils::extract_env_var(&envs, "JAVA_HOME")
.unwrap_or_else(|| "/opt/jdk".to_string());
(home, java_home)
})
})
{
return (PathBuf::from(doris_home), PathBuf::from(java_home));
}

// Default paths if environment variables are not available
Expand Down Expand Up @@ -241,18 +244,18 @@ pub fn detect_mixed_deployment(config: &mut crate::config_loader::DorisConfig) -
config.fe_process_command = Some(fe_process.command.clone());
config.fe_install_dir = Some(fe_process.doris_home.clone());

if config.environment != crate::config_loader::Environment::FE {
if let Ok(fe_config) = crate::config_loader::config_parser::parse_config_from_path(
if config.environment != crate::config_loader::Environment::FE
&& let Ok(fe_config) = crate::config_loader::config_parser::parse_config_from_path(
crate::config_loader::Environment::FE,
&fe_process.doris_home,
) {
config.http_port = fe_config.http_port;
config.rpc_port = fe_config.rpc_port;
config.query_port = fe_config.query_port;
config.edit_log_port = fe_config.edit_log_port;
config.cloud_http_port = fe_config.cloud_http_port;
config.meta_dir = fe_config.meta_dir;
}
)
{
config.http_port = fe_config.http_port;
config.rpc_port = fe_config.rpc_port;
config.query_port = fe_config.query_port;
config.edit_log_port = fe_config.edit_log_port;
config.cloud_http_port = fe_config.cloud_http_port;
config.meta_dir = fe_config.meta_dir;
}
}

Expand All @@ -261,16 +264,16 @@ pub fn detect_mixed_deployment(config: &mut crate::config_loader::DorisConfig) -
config.be_process_command = Some(be_process.command.clone());
config.be_install_dir = Some(be_process.doris_home.clone());

if config.environment != crate::config_loader::Environment::BE {
if let Ok(be_config) = crate::config_loader::config_parser::parse_config_from_path(
if config.environment != crate::config_loader::Environment::BE
&& let Ok(be_config) = crate::config_loader::config_parser::parse_config_from_path(
crate::config_loader::Environment::BE,
&be_process.doris_home,
) {
config.be_port = be_config.be_port;
config.brpc_port = be_config.brpc_port;
config.webserver_port = be_config.webserver_port;
config.heartbeat_service_port = be_config.heartbeat_service_port;
}
)
{
config.be_port = be_config.be_port;
config.brpc_port = be_config.brpc_port;
config.webserver_port = be_config.webserver_port;
config.heartbeat_service_port = be_config.heartbeat_service_port;
}
}
}
Expand Down
Loading
Loading