diff --git a/src/cmd/src/bin/greptime.rs b/src/cmd/src/bin/greptime.rs index ec87176b9fbe..6a258e3b5a2d 100644 --- a/src/cmd/src/bin/greptime.rs +++ b/src/cmd/src/bin/greptime.rs @@ -14,11 +14,9 @@ #![doc = include_str!("../../../../README.md")] -use std::fmt; - use clap::{Parser, Subcommand}; use cmd::error::Result; -use cmd::options::{GlobalOptions, Options}; +use cmd::options::GlobalOptions; use cmd::{cli, datanode, frontend, log_versions, metasrv, standalone, App}; use common_version::{short_version, version}; @@ -56,58 +54,6 @@ enum SubCommand { Cli(cli::Command), } -impl SubCommand { - async fn build(self, opts: Options) -> Result> { - let app: Box = match (self, opts) { - (SubCommand::Datanode(cmd), Options::Datanode(dn_opts)) => { - let app = cmd.build(*dn_opts).await?; - Box::new(app) as _ - } - (SubCommand::Frontend(cmd), Options::Frontend(fe_opts)) => { - let app = cmd.build(*fe_opts).await?; - Box::new(app) as _ - } - (SubCommand::Metasrv(cmd), Options::Metasrv(meta_opts)) => { - let app = cmd.build(*meta_opts).await?; - Box::new(app) as _ - } - (SubCommand::Standalone(cmd), Options::Standalone(opts)) => { - let app = cmd.build(*opts).await?; - Box::new(app) as _ - } - (SubCommand::Cli(cmd), Options::Cli(_)) => { - let app = cmd.build().await?; - Box::new(app) as _ - } - - _ => unreachable!(), - }; - Ok(app) - } - - fn load_options(&self, global_options: &GlobalOptions) -> Result { - match self { - SubCommand::Datanode(cmd) => cmd.load_options(global_options), - SubCommand::Frontend(cmd) => cmd.load_options(global_options), - SubCommand::Metasrv(cmd) => cmd.load_options(global_options), - SubCommand::Standalone(cmd) => cmd.load_options(global_options), - SubCommand::Cli(cmd) => cmd.load_options(global_options), - } - } -} - -impl fmt::Display for SubCommand { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - SubCommand::Datanode(..) => write!(f, "greptime-datanode"), - SubCommand::Frontend(..) => write!(f, "greptime-frontend"), - SubCommand::Metasrv(..) => write!(f, "greptime-metasrv"), - SubCommand::Standalone(..) => write!(f, "greptime-standalone"), - SubCommand::Cli(_) => write!(f, "greptime-cli"), - } - } -} - #[cfg(not(windows))] #[global_allocator] static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; @@ -115,26 +61,43 @@ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; #[tokio::main] async fn main() -> Result<()> { setup_human_panic(); + log_versions(version!(), short_version!()); start(Command::parse()).await } async fn start(cli: Command) -> Result<()> { - let subcmd = cli.subcmd; - - let app_name = subcmd.to_string(); - - let opts = subcmd.load_options(&cli.global_options)?; - - let _guard = common_telemetry::init_global_logging( - &app_name, - opts.logging_options(), - &cli.global_options.tracing_options(), - opts.node_id(), - ); - - log_versions(version!(), short_version!()); - - subcmd.build(opts).await?.run().await + match cli.subcmd { + SubCommand::Datanode(cmd) => { + cmd.build(cmd.load_options(&cli.global_options)?) + .await? + .run() + .await + } + SubCommand::Frontend(cmd) => { + cmd.build(cmd.load_options(&cli.global_options)?) + .await? + .run() + .await + } + SubCommand::Metasrv(cmd) => { + cmd.build(cmd.load_options(&cli.global_options)?) + .await? + .run() + .await + } + SubCommand::Standalone(cmd) => { + cmd.build(cmd.load_options(&cli.global_options)?) + .await? + .run() + .await + } + SubCommand::Cli(cmd) => { + cmd.build(cmd.load_options(&cli.global_options)?) + .await? + .run() + .await + } + } } fn setup_human_panic() { diff --git a/src/cmd/src/cli.rs b/src/cmd/src/cli.rs index b47293240c98..fbdd5fc17e58 100644 --- a/src/cmd/src/cli.rs +++ b/src/cmd/src/cli.rs @@ -30,15 +30,17 @@ mod upgrade; use async_trait::async_trait; use bench::BenchTableMetadataCommand; use clap::Parser; -use common_telemetry::logging::LoggingOptions; +use common_telemetry::logging::{LoggingOptions, TracingOptions}; // pub use repl::Repl; use upgrade::UpgradeCommand; use self::export::ExportCommand; use crate::error::Result; -use crate::options::{GlobalOptions, Options}; +use crate::options::GlobalOptions; use crate::App; +pub const APP_NAME: &str = "greptime-cli"; + #[async_trait] pub trait Tool: Send + Sync { async fn do_work(&self) -> Result<()>; @@ -57,7 +59,7 @@ impl Instance { #[async_trait] impl App for Instance { fn name(&self) -> &str { - "greptime-cli" + APP_NAME } async fn start(&mut self) -> Result<()> { @@ -80,11 +82,18 @@ pub struct Command { } impl Command { - pub async fn build(self) -> Result { + pub async fn build(&self, opts: LoggingOptions) -> Result { + let _guard = common_telemetry::init_global_logging( + &APP_NAME, + &opts, + &TracingOptions::default(), + None, + ); + self.cmd.build().await } - pub fn load_options(&self, global_options: &GlobalOptions) -> Result { + pub fn load_options(&self, global_options: &GlobalOptions) -> Result { let mut logging_opts = LoggingOptions::default(); if let Some(dir) = &global_options.log_dir { @@ -93,7 +102,7 @@ impl Command { logging_opts.level.clone_from(&global_options.log_level); - Ok(Options::Cli(Box::new(logging_opts))) + Ok(logging_opts) } } @@ -106,7 +115,7 @@ enum SubCommand { } impl SubCommand { - async fn build(self) -> Result { + async fn build(&self) -> Result { match self { // SubCommand::Attach(cmd) => cmd.build().await, SubCommand::Upgrade(cmd) => cmd.build().await, diff --git a/src/cmd/src/datanode.rs b/src/cmd/src/datanode.rs index c21e03499973..6cffc6f224ad 100644 --- a/src/cmd/src/datanode.rs +++ b/src/cmd/src/datanode.rs @@ -32,9 +32,11 @@ use snafu::{OptionExt, ResultExt}; use crate::error::{ LoadLayeredConfigSnafu, MissingConfigSnafu, Result, ShutdownDatanodeSnafu, StartDatanodeSnafu, }; -use crate::options::{GlobalOptions, Options}; +use crate::options::GlobalOptions; use crate::App; +pub const APP_NAME: &str = "greptime-datanode"; + pub struct Instance { datanode: Datanode, } @@ -56,7 +58,7 @@ impl Instance { #[async_trait] impl App for Instance { fn name(&self) -> &str { - "greptime-datanode" + APP_NAME } async fn start(&mut self) -> Result<()> { @@ -82,11 +84,11 @@ pub struct Command { } impl Command { - pub async fn build(self, opts: DatanodeOptions) -> Result { + pub async fn build(&self, opts: DatanodeOptions) -> Result { self.subcmd.build(opts).await } - pub fn load_options(&self, global_options: &GlobalOptions) -> Result { + pub fn load_options(&self, global_options: &GlobalOptions) -> Result { self.subcmd.load_options(global_options) } } @@ -97,13 +99,13 @@ enum SubCommand { } impl SubCommand { - async fn build(self, opts: DatanodeOptions) -> Result { + async fn build(&self, opts: DatanodeOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.build(opts).await, } } - fn load_options(&self, global_options: &GlobalOptions) -> Result { + fn load_options(&self, global_options: &GlobalOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.load_options(global_options), } @@ -135,17 +137,15 @@ struct StartCommand { } impl StartCommand { - fn load_options(&self, global_options: &GlobalOptions) -> Result { - Ok(Options::Datanode(Box::new( - self.merge_with_cli_options( - global_options, - DatanodeOptions::load_layered_options( - self.config_file.as_deref(), - self.env_prefix.as_ref(), - ) - .context(LoadLayeredConfigSnafu)?, - )?, - ))) + fn load_options(&self, global_options: &GlobalOptions) -> Result { + self.merge_with_cli_options( + global_options, + DatanodeOptions::load_layered_options( + self.config_file.as_deref(), + self.env_prefix.as_ref(), + ) + .context(LoadLayeredConfigSnafu)?, + ) } // The precedence order is: cli > config file > environment variables > default values. @@ -226,7 +226,14 @@ impl StartCommand { Ok(opts) } - async fn build(self, mut opts: DatanodeOptions) -> Result { + async fn build(&self, mut opts: DatanodeOptions) -> Result { + let _guard = common_telemetry::init_global_logging( + &APP_NAME, + &opts.logging, + &opts.tracing, + opts.node_id.map(|x| x.to_string()), + ); + let plugins = plugins::setup_datanode_plugins(&mut opts) .await .context(StartDatanodeSnafu)?; @@ -337,10 +344,7 @@ mod tests { ..Default::default() }; - let Options::Datanode(options) = cmd.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let options = cmd.load_options(&GlobalOptions::default()).unwrap(); assert_eq!("127.0.0.1:3001".to_string(), options.rpc_addr); assert_eq!(Some(42), options.node_id); @@ -399,23 +403,19 @@ mod tests { #[test] fn test_try_from_cmd() { - if let Options::Datanode(opt) = StartCommand::default() + let opt = StartCommand::default() .load_options(&GlobalOptions::default()) - .unwrap() - { - assert_eq!(Mode::Standalone, opt.mode) - } + .unwrap(); + assert_eq!(Mode::Standalone, opt.mode); - if let Options::Datanode(opt) = (StartCommand { + let opt = (StartCommand { node_id: Some(42), metasrv_addrs: Some(vec!["127.0.0.1:3002".to_string()]), ..Default::default() }) .load_options(&GlobalOptions::default()) - .unwrap() - { - assert_eq!(Mode::Distributed, opt.mode) - } + .unwrap(); + assert_eq!(Mode::Distributed, opt.mode); assert!((StartCommand { metasrv_addrs: Some(vec!["127.0.0.1:3002".to_string()]), @@ -447,7 +447,7 @@ mod tests { }) .unwrap(); - let logging_opt = options.logging_options(); + let logging_opt = options.logging; assert_eq!("/tmp/greptimedb/test/logs", logging_opt.dir); assert_eq!("debug", logging_opt.level.as_ref().unwrap()); } @@ -527,11 +527,7 @@ mod tests { ..Default::default() }; - let Options::Datanode(opts) = - command.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let opts = command.load_options(&GlobalOptions::default()).unwrap(); // Should be read from env, env > default values. let DatanodeWalConfig::RaftEngine(raft_engine_config) = opts.wal else { diff --git a/src/cmd/src/frontend.rs b/src/cmd/src/frontend.rs index f8fd5cbd511d..840e397de2c4 100644 --- a/src/cmd/src/frontend.rs +++ b/src/cmd/src/frontend.rs @@ -45,13 +45,15 @@ use snafu::{OptionExt, ResultExt}; use crate::error::{ self, InitTimezoneSnafu, LoadLayeredConfigSnafu, MissingConfigSnafu, Result, StartFrontendSnafu, }; -use crate::options::{GlobalOptions, Options}; +use crate::options::GlobalOptions; use crate::App; pub struct Instance { frontend: FeInstance, } +pub const APP_NAME: &str = "greptime-frontend"; + impl Instance { pub fn new(frontend: FeInstance) -> Self { Self { frontend } @@ -69,7 +71,7 @@ impl Instance { #[async_trait] impl App for Instance { fn name(&self) -> &str { - "greptime-frontend" + APP_NAME } async fn start(&mut self) -> Result<()> { @@ -95,11 +97,11 @@ pub struct Command { } impl Command { - pub async fn build(self, opts: FrontendOptions) -> Result { + pub async fn build(&self, opts: FrontendOptions) -> Result { self.subcmd.build(opts).await } - pub fn load_options(&self, global_options: &GlobalOptions) -> Result { + pub fn load_options(&self, global_options: &GlobalOptions) -> Result { self.subcmd.load_options(global_options) } } @@ -110,13 +112,13 @@ enum SubCommand { } impl SubCommand { - async fn build(self, opts: FrontendOptions) -> Result { + async fn build(&self, opts: FrontendOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.build(opts).await, } } - fn load_options(&self, global_options: &GlobalOptions) -> Result { + fn load_options(&self, global_options: &GlobalOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.load_options(global_options), } @@ -156,17 +158,15 @@ pub struct StartCommand { } impl StartCommand { - fn load_options(&self, global_options: &GlobalOptions) -> Result { - Ok(Options::Frontend(Box::new( - self.merge_with_cli_options( - global_options, - FrontendOptions::load_layered_options( - self.config_file.as_deref(), - self.env_prefix.as_ref(), - ) - .context(LoadLayeredConfigSnafu)?, - )?, - ))) + fn load_options(&self, global_options: &GlobalOptions) -> Result { + self.merge_with_cli_options( + global_options, + FrontendOptions::load_layered_options( + self.config_file.as_deref(), + self.env_prefix.as_ref(), + ) + .context(LoadLayeredConfigSnafu)?, + ) } // The precedence order is: cli > config file > environment variables > default values. @@ -239,7 +239,14 @@ impl StartCommand { Ok(opts) } - async fn build(self, mut opts: FrontendOptions) -> Result { + async fn build(&self, mut opts: FrontendOptions) -> Result { + let _guard = common_telemetry::init_global_logging( + &APP_NAME, + &opts.logging, + &opts.tracing, + opts.node_id.clone(), + ); + #[allow(clippy::unnecessary_mut_passed)] let plugins = plugins::setup_frontend_plugins(&mut opts) .await @@ -379,10 +386,7 @@ mod tests { ..Default::default() }; - let Options::Frontend(opts) = command.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let opts = command.load_options(&GlobalOptions::default()).unwrap(); assert_eq!(opts.http.addr, "127.0.0.1:1234"); assert_eq!(ReadableSize::mb(64), opts.http.body_limit); @@ -430,10 +434,7 @@ mod tests { ..Default::default() }; - let Options::Frontend(fe_opts) = command.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let fe_opts = command.load_options(&GlobalOptions::default()).unwrap(); assert_eq!(Mode::Distributed, fe_opts.mode); assert_eq!("127.0.0.1:4000".to_string(), fe_opts.http.addr); assert_eq!(Duration::from_secs(30), fe_opts.http.timeout); @@ -486,7 +487,7 @@ mod tests { }) .unwrap(); - let logging_opt = options.logging_options(); + let logging_opt = options.logging; assert_eq!("/tmp/greptimedb/test/logs", logging_opt.dir); assert_eq!("debug", logging_opt.level.as_ref().unwrap()); } @@ -562,11 +563,7 @@ mod tests { ..Default::default() }; - let Options::Frontend(fe_opts) = - command.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let fe_opts = command.load_options(&GlobalOptions::default()).unwrap(); // Should be read from env, env > default values. assert_eq!(fe_opts.mysql.runtime_size, 11); diff --git a/src/cmd/src/metasrv.rs b/src/cmd/src/metasrv.rs index f6e7a0c3c472..edfda7b35a9c 100644 --- a/src/cmd/src/metasrv.rs +++ b/src/cmd/src/metasrv.rs @@ -24,9 +24,11 @@ use meta_srv::metasrv::MetasrvOptions; use snafu::ResultExt; use crate::error::{self, LoadLayeredConfigSnafu, Result, StartMetaServerSnafu}; -use crate::options::{GlobalOptions, Options}; +use crate::options::GlobalOptions; use crate::App; +pub const APP_NAME: &str = "greptime-metasrv"; + pub struct Instance { instance: MetasrvInstance, } @@ -40,7 +42,7 @@ impl Instance { #[async_trait] impl App for Instance { fn name(&self) -> &str { - "greptime-metasrv" + APP_NAME } async fn start(&mut self) -> Result<()> { @@ -66,11 +68,11 @@ pub struct Command { } impl Command { - pub async fn build(self, opts: MetasrvOptions) -> Result { + pub async fn build(&self, opts: MetasrvOptions) -> Result { self.subcmd.build(opts).await } - pub fn load_options(&self, global_options: &GlobalOptions) -> Result { + pub fn load_options(&self, global_options: &GlobalOptions) -> Result { self.subcmd.load_options(global_options) } } @@ -81,13 +83,13 @@ enum SubCommand { } impl SubCommand { - async fn build(self, opts: MetasrvOptions) -> Result { + async fn build(&self, opts: MetasrvOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.build(opts).await, } } - fn load_options(&self, global_options: &GlobalOptions) -> Result { + fn load_options(&self, global_options: &GlobalOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.load_options(global_options), } @@ -128,17 +130,15 @@ struct StartCommand { } impl StartCommand { - fn load_options(&self, global_options: &GlobalOptions) -> Result { - Ok(Options::Metasrv(Box::new( - self.merge_with_cli_options( - global_options, - MetasrvOptions::load_layered_options( - self.config_file.as_deref(), - self.env_prefix.as_ref(), - ) - .context(LoadLayeredConfigSnafu)?, - )?, - ))) + fn load_options(&self, global_options: &GlobalOptions) -> Result { + self.merge_with_cli_options( + global_options, + MetasrvOptions::load_layered_options( + self.config_file.as_deref(), + self.env_prefix.as_ref(), + ) + .context(LoadLayeredConfigSnafu)?, + ) } // The precedence order is: cli > config file > environment variables > default values. @@ -212,7 +212,10 @@ impl StartCommand { Ok(opts) } - async fn build(self, mut opts: MetasrvOptions) -> Result { + async fn build(&self, mut opts: MetasrvOptions) -> Result { + let _guard = + common_telemetry::init_global_logging(&APP_NAME, &opts.logging, &opts.tracing, None); + let plugins = plugins::setup_metasrv_plugins(&mut opts) .await .context(StartMetaServerSnafu)?; @@ -254,9 +257,7 @@ mod tests { ..Default::default() }; - let Options::Metasrv(options) = cmd.load_options(&GlobalOptions::default()).unwrap() else { - unreachable!() - }; + let options = cmd.load_options(&GlobalOptions::default()).unwrap(); assert_eq!("127.0.0.1:3002".to_string(), options.bind_addr); assert_eq!(vec!["127.0.0.1:2380".to_string()], options.store_addrs); assert_eq!(SelectorType::LoadBased, options.selector); @@ -289,9 +290,7 @@ mod tests { ..Default::default() }; - let Options::Metasrv(options) = cmd.load_options(&GlobalOptions::default()).unwrap() else { - unreachable!() - }; + let options = cmd.load_options(&GlobalOptions::default()).unwrap(); assert_eq!("127.0.0.1:3002".to_string(), options.bind_addr); assert_eq!("127.0.0.1:3002".to_string(), options.server_addr); assert_eq!(vec!["127.0.0.1:2379".to_string()], options.store_addrs); @@ -343,7 +342,7 @@ mod tests { }) .unwrap(); - let logging_opt = options.logging_options(); + let logging_opt = options.logging; assert_eq!("/tmp/greptimedb/test/logs", logging_opt.dir); assert_eq!("debug", logging_opt.level.as_ref().unwrap()); } @@ -398,11 +397,7 @@ mod tests { ..Default::default() }; - let Options::Metasrv(opts) = - command.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let opts = command.load_options(&GlobalOptions::default()).unwrap(); // Should be read from env, env > default values. assert_eq!(opts.bind_addr, "127.0.0.1:14002"); diff --git a/src/cmd/src/options.rs b/src/cmd/src/options.rs index 98b2fd0d2a8e..03ccbc536247 100644 --- a/src/cmd/src/options.rs +++ b/src/cmd/src/options.rs @@ -13,20 +13,6 @@ // limitations under the License. use clap::Parser; -use common_telemetry::logging::{LoggingOptions, TracingOptions}; -use datanode::config::DatanodeOptions; -use frontend::frontend::FrontendOptions; -use meta_srv::metasrv::MetasrvOptions; - -use crate::standalone::StandaloneOptions; - -pub enum Options { - Datanode(Box), - Frontend(Box), - Metasrv(Box), - Standalone(Box), - Cli(Box), -} #[derive(Parser, Default, Debug, Clone)] pub struct GlobalOptions { @@ -43,32 +29,3 @@ pub struct GlobalOptions { #[arg(global = true)] pub tokio_console_addr: Option, } - -impl GlobalOptions { - pub fn tracing_options(&self) -> TracingOptions { - TracingOptions { - #[cfg(feature = "tokio-console")] - tokio_console_addr: self.tokio_console_addr.clone(), - } - } -} - -impl Options { - pub fn logging_options(&self) -> &LoggingOptions { - match self { - Options::Datanode(opts) => &opts.logging, - Options::Frontend(opts) => &opts.logging, - Options::Metasrv(opts) => &opts.logging, - Options::Standalone(opts) => &opts.logging, - Options::Cli(opts) => opts, - } - } - - pub fn node_id(&self) -> Option { - match self { - Options::Metasrv(_) | Options::Cli(_) | Options::Standalone(_) => None, - Options::Datanode(opt) => opt.node_id.map(|x| x.to_string()), - Options::Frontend(opt) => opt.node_id.clone(), - } - } -} diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs index 21901e9b967a..35c966444ebe 100644 --- a/src/cmd/src/standalone.rs +++ b/src/cmd/src/standalone.rs @@ -68,9 +68,11 @@ use crate::error::{ ShutdownDatanodeSnafu, ShutdownFrontendSnafu, StartDatanodeSnafu, StartFrontendSnafu, StartProcedureManagerSnafu, StartWalOptionsAllocatorSnafu, StopProcedureManagerSnafu, }; -use crate::options::{GlobalOptions, Options}; +use crate::options::GlobalOptions; use crate::App; +pub const APP_NAME: &str = "greptime-standalone"; + #[derive(Parser)] pub struct Command { #[clap(subcommand)] @@ -78,11 +80,11 @@ pub struct Command { } impl Command { - pub async fn build(self, opts: StandaloneOptions) -> Result { + pub async fn build(&self, opts: StandaloneOptions) -> Result { self.subcmd.build(opts).await } - pub fn load_options(&self, global_options: &GlobalOptions) -> Result { + pub fn load_options(&self, global_options: &GlobalOptions) -> Result { self.subcmd.load_options(global_options) } } @@ -93,13 +95,13 @@ enum SubCommand { } impl SubCommand { - async fn build(self, opts: StandaloneOptions) -> Result { + async fn build(&self, opts: StandaloneOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.build(opts).await, } } - fn load_options(&self, global_options: &GlobalOptions) -> Result { + fn load_options(&self, global_options: &GlobalOptions) -> Result { match self { SubCommand::Start(cmd) => cmd.load_options(global_options), } @@ -212,7 +214,7 @@ pub struct Instance { #[async_trait] impl App for Instance { fn name(&self) -> &str { - "greptime-standalone" + APP_NAME } async fn start(&mut self) -> Result<()> { @@ -287,17 +289,15 @@ pub struct StartCommand { } impl StartCommand { - fn load_options(&self, global_options: &GlobalOptions) -> Result { - Ok(Options::Standalone(Box::new( - self.merge_with_cli_options( - global_options, - StandaloneOptions::load_layered_options( - self.config_file.as_deref(), - self.env_prefix.as_ref(), - ) - .context(LoadLayeredConfigSnafu)?, - )?, - ))) + fn load_options(&self, global_options: &GlobalOptions) -> Result { + self.merge_with_cli_options( + global_options, + StandaloneOptions::load_layered_options( + self.config_file.as_deref(), + self.env_prefix.as_ref(), + ) + .context(LoadLayeredConfigSnafu)?, + ) } // The precedence order is: cli > config file > environment variables > default values. @@ -373,7 +373,10 @@ impl StartCommand { #[allow(unreachable_code)] #[allow(unused_variables)] #[allow(clippy::diverging_sub_expression)] - async fn build(self, opts: StandaloneOptions) -> Result { + async fn build(&self, opts: StandaloneOptions) -> Result { + let _guard = + common_telemetry::init_global_logging(&APP_NAME, &opts.logging, &opts.tracing, None); + info!("Standalone start command: {:#?}", self); info!("Building standalone instance with {opts:#?}"); @@ -665,10 +668,7 @@ mod tests { ..Default::default() }; - let Options::Standalone(options) = cmd.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let options = cmd.load_options(&GlobalOptions::default()).unwrap(); let fe_opts = options.frontend_options(); let dn_opts = options.datanode_options(); let logging_opts = options.logging; @@ -721,7 +721,7 @@ mod tests { ..Default::default() }; - let Options::Standalone(opts) = cmd + let opts = cmd .load_options(&GlobalOptions { log_dir: Some("/tmp/greptimedb/test/logs".to_string()), log_level: Some("debug".to_string()), @@ -729,10 +729,7 @@ mod tests { #[cfg(feature = "tokio-console")] tokio_console_addr: None, }) - .unwrap() - else { - unreachable!() - }; + .unwrap(); assert_eq!("/tmp/greptimedb/test/logs", opts.logging.dir); assert_eq!("debug", opts.logging.level.unwrap()); @@ -794,11 +791,7 @@ mod tests { ..Default::default() }; - let Options::Standalone(opts) = - command.load_options(&GlobalOptions::default()).unwrap() - else { - unreachable!() - }; + let opts = command.load_options(&GlobalOptions::default()).unwrap(); // Should be read from env, env > default values. assert_eq!(opts.logging.dir, "/other/log/dir");