Skip to content

Commit 118b05d

Browse files
committed
refactor: initialize logging dir by using data_home
1 parent 41a706c commit 118b05d

File tree

9 files changed

+62
-16
lines changed

9 files changed

+62
-16
lines changed

src/cmd/src/datanode.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515
pub mod builder;
1616

17+
use std::path::Path;
1718
use std::time::Duration;
1819

1920
use async_trait::async_trait;
2021
use clap::Parser;
2122
use common_config::Configurable;
22-
use common_telemetry::logging::TracingOptions;
23+
use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR};
2324
use common_telemetry::{info, warn};
2425
use common_wal::config::DatanodeWalConfig;
2526
use datanode::datanode::Datanode;
@@ -247,6 +248,14 @@ impl StartCommand {
247248
raft_engine_config.dir.replace(wal_dir.clone());
248249
}
249250

251+
// If the logging dir is not set, use the default logs dir in the data home.
252+
if opts.logging.dir.is_empty() {
253+
opts.logging.dir = Path::new(&opts.storage.data_home)
254+
.join(DEFAULT_LOGGING_DIR)
255+
.to_string_lossy()
256+
.to_string();
257+
}
258+
250259
if let Some(http_addr) = &self.http_addr {
251260
opts.http.addr.clone_from(http_addr);
252261
}

src/cmd/src/flownode.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::path::Path;
1516
use std::sync::Arc;
1617
use std::time::Duration;
1718

@@ -21,7 +22,7 @@ use catalog::kvbackend::{CachedKvBackendBuilder, KvBackendCatalogManager, MetaKv
2122
use clap::Parser;
2223
use client::client_manager::NodeClients;
2324
use common_base::Plugins;
24-
use common_config::Configurable;
25+
use common_config::{Configurable, DEFAULT_DATA_HOME};
2526
use common_grpc::channel_manager::ChannelConfig;
2627
use common_meta::cache::{CacheRegistryBuilder, LayeredCacheRegistryBuilder};
2728
use common_meta::heartbeat::handler::invalidate_table_cache::InvalidateCacheHandler;
@@ -30,7 +31,7 @@ use common_meta::heartbeat::handler::HandlerGroupExecutor;
3031
use common_meta::key::flow::FlowMetadataManager;
3132
use common_meta::key::TableMetadataManager;
3233
use common_telemetry::info;
33-
use common_telemetry::logging::TracingOptions;
34+
use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR};
3435
use common_version::{short_version, version};
3536
use flow::{
3637
FlownodeBuilder, FlownodeInstance, FlownodeServiceBuilder, FrontendClient, FrontendInvoker,
@@ -178,6 +179,14 @@ impl StartCommand {
178179
opts.logging.dir.clone_from(dir);
179180
}
180181

182+
// If the logging dir is not set, use the default logs dir in the data home.
183+
if opts.logging.dir.is_empty() {
184+
opts.logging.dir = Path::new(DEFAULT_DATA_HOME)
185+
.join(DEFAULT_LOGGING_DIR)
186+
.to_string_lossy()
187+
.to_string();
188+
}
189+
181190
if global_options.log_level.is_some() {
182191
opts.logging.level.clone_from(&global_options.log_level);
183192
}

src/cmd/src/frontend.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::path::Path;
1516
use std::sync::Arc;
1617
use std::time::Duration;
1718

@@ -22,14 +23,14 @@ use catalog::kvbackend::{CachedKvBackendBuilder, KvBackendCatalogManager, MetaKv
2223
use clap::Parser;
2324
use client::client_manager::NodeClients;
2425
use common_base::Plugins;
25-
use common_config::Configurable;
26+
use common_config::{Configurable, DEFAULT_DATA_HOME};
2627
use common_grpc::channel_manager::ChannelConfig;
2728
use common_meta::cache::{CacheRegistryBuilder, LayeredCacheRegistryBuilder};
2829
use common_meta::heartbeat::handler::invalidate_table_cache::InvalidateCacheHandler;
2930
use common_meta::heartbeat::handler::parse_mailbox_message::ParseMailboxMessageHandler;
3031
use common_meta::heartbeat::handler::HandlerGroupExecutor;
3132
use common_telemetry::info;
32-
use common_telemetry::logging::TracingOptions;
33+
use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR};
3334
use common_time::timezone::set_default_timezone;
3435
use common_version::{short_version, version};
3536
use frontend::frontend::Frontend;
@@ -195,6 +196,14 @@ impl StartCommand {
195196
opts.logging.dir.clone_from(dir);
196197
}
197198

199+
// If the logging dir is not set, use the default logs dir in the data home.
200+
if opts.logging.dir.is_empty() {
201+
opts.logging.dir = Path::new(DEFAULT_DATA_HOME)
202+
.join(DEFAULT_LOGGING_DIR)
203+
.to_string_lossy()
204+
.to_string();
205+
}
206+
198207
if global_options.log_level.is_some() {
199208
opts.logging.level.clone_from(&global_options.log_level);
200209
}

src/cmd/src/metasrv.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
// limitations under the License.
1414

1515
use std::fmt;
16+
use std::path::Path;
1617
use std::time::Duration;
1718

1819
use async_trait::async_trait;
1920
use clap::Parser;
2021
use common_base::Plugins;
2122
use common_config::Configurable;
2223
use common_telemetry::info;
23-
use common_telemetry::logging::TracingOptions;
24+
use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR};
2425
use common_version::{short_version, version};
2526
use meta_srv::bootstrap::MetasrvInstance;
2627
use meta_srv::metasrv::BackendImpl;
@@ -274,6 +275,14 @@ impl StartCommand {
274275
opts.data_home.clone_from(data_home);
275276
}
276277

278+
// If the logging dir is not set, use the default logs dir in the data home.
279+
if opts.logging.dir.is_empty() {
280+
opts.logging.dir = Path::new(&opts.data_home)
281+
.join(DEFAULT_LOGGING_DIR)
282+
.to_string_lossy()
283+
.to_string();
284+
}
285+
277286
if !self.store_key_prefix.is_empty() {
278287
opts.store_key_prefix.clone_from(&self.store_key_prefix)
279288
}

src/cmd/src/standalone.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::net::SocketAddr;
16+
use std::path::Path;
1617
use std::sync::Arc;
1718
use std::{fs, path};
1819

@@ -47,7 +48,7 @@ use common_meta::sequence::SequenceBuilder;
4748
use common_meta::wal_options_allocator::{build_wal_options_allocator, WalOptionsAllocatorRef};
4849
use common_procedure::{ProcedureInfo, ProcedureManagerRef};
4950
use common_telemetry::info;
50-
use common_telemetry::logging::{LoggingOptions, TracingOptions};
51+
use common_telemetry::logging::{LoggingOptions, TracingOptions, DEFAULT_LOGGING_DIR};
5152
use common_time::timezone::set_default_timezone;
5253
use common_version::{short_version, version};
5354
use common_wal::config::DatanodeWalConfig;
@@ -399,6 +400,14 @@ impl StartCommand {
399400
opts.storage.data_home.clone_from(data_home);
400401
}
401402

403+
// If the logging dir is not set, use the default logs dir in the data home.
404+
if opts.logging.dir.is_empty() {
405+
opts.logging.dir = Path::new(&opts.storage.data_home)
406+
.join(DEFAULT_LOGGING_DIR)
407+
.to_string_lossy()
408+
.to_string();
409+
}
410+
402411
if let Some(addr) = &self.rpc_bind_addr {
403412
// frontend grpc addr conflict with datanode default grpc addr
404413
let datanode_grpc_addr = DatanodeOptions::default().grpc.bind_addr;

src/common/config/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub fn metadata_store_dir(store_dir: &str) -> String {
2626
format!("{store_dir}/metadata")
2727
}
2828

29+
/// The default data home directory.
30+
pub const DEFAULT_DATA_HOME: &str = "./greptimedb_data";
31+
2932
/// The Server running mode
3033
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Copy)]
3134
#[serde(rename_all = "lowercase")]

src/common/telemetry/src/logging.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ use crate::tracing_sampler::{create_sampler, TracingSampleOptions};
3737

3838
pub const DEFAULT_OTLP_ENDPOINT: &str = "http://localhost:4317";
3939

40+
/// The default logs directory.
41+
pub const DEFAULT_LOGGING_DIR: &str = "logs";
42+
4043
// Handle for reloading log level
4144
pub static RELOAD_HANDLE: OnceCell<tracing_subscriber::reload::Handle<Targets, Registry>> =
4245
OnceCell::new();
@@ -111,7 +114,8 @@ impl Eq for LoggingOptions {}
111114
impl Default for LoggingOptions {
112115
fn default() -> Self {
113116
Self {
114-
dir: "./greptimedb_data/logs".to_string(),
117+
// The directory path will be configured at application startup, typically using the data home directory as a base.
118+
dir: "".to_string(),
115119
level: None,
116120
log_format: LogFormat::Text,
117121
enable_otlp_tracing: false,

src/datanode/src/config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use core::time::Duration;
1818

1919
use common_base::readable_size::ReadableSize;
2020
use common_base::secrets::{ExposeSecret, SecretString};
21-
use common_config::Configurable;
21+
use common_config::{Configurable, DEFAULT_DATA_HOME};
2222
pub use common_procedure::options::ProcedureConfig;
2323
use common_telemetry::logging::{LoggingOptions, TracingOptions};
2424
use common_wal::config::DatanodeWalConfig;
@@ -35,9 +35,6 @@ use servers::http::HttpOptions;
3535

3636
pub const DEFAULT_OBJECT_STORE_CACHE_SIZE: ReadableSize = ReadableSize::gb(5);
3737

38-
/// Default data home in file storage
39-
const DEFAULT_DATA_HOME: &str = "./greptimedb_data";
40-
4138
/// Object storage config
4239
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
4340
#[serde(tag = "type")]

src/meta-srv/src/metasrv.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,7 @@ impl Default for MetasrvOptions {
222222
enable_region_failover: false,
223223
allow_region_failover_on_local_wal: false,
224224
http: HttpOptions::default(),
225-
logging: LoggingOptions {
226-
dir: format!("{METASRV_HOME}/logs"),
227-
..Default::default()
228-
},
225+
logging: LoggingOptions::default(),
229226
procedure: ProcedureConfig {
230227
max_retry_times: 12,
231228
retry_delay: Duration::from_millis(500),

0 commit comments

Comments
 (0)