Skip to content

Commit de5d2f0

Browse files
Add a config for tracing log rolling policy for both scheduler and executor (#487)
Co-authored-by: yangzhong <[email protected]>
1 parent 0cddc1d commit de5d2f0

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

ballista/core/src/config.rs

+24
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,30 @@ impl parse_arg::ParseArgFromStr for TaskSchedulingPolicy {
286286
}
287287
}
288288

289+
// an enum used to configure the log rolling policy
290+
// needs to be visible to code generated by configure_me
291+
#[derive(Clone, ArgEnum, Copy, Debug, serde::Deserialize)]
292+
pub enum LogRotationPolicy {
293+
Minutely,
294+
Hourly,
295+
Daily,
296+
Never,
297+
}
298+
299+
impl std::str::FromStr for LogRotationPolicy {
300+
type Err = String;
301+
302+
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
303+
ArgEnum::from_str(s, true)
304+
}
305+
}
306+
307+
impl parse_arg::ParseArgFromStr for LogRotationPolicy {
308+
fn describe_type<W: fmt::Write>(mut writer: W) -> fmt::Result {
309+
write!(writer, "The log rotation policy")
310+
}
311+
}
312+
289313
#[cfg(test)]
290314
mod tests {
291315
use super::*;

ballista/executor/executor_config_spec.toml

+6
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,9 @@ name = "log_level_setting"
125125
type = "String"
126126
doc = "special log level for sub mod. link: https://docs.rs/env_logger/latest/env_logger/#enabling-logging. For example we want whole level is INFO but datafusion mode is DEBUG"
127127
default = "std::string::String::from(\"INFO,datafusion=INFO\")"
128+
129+
[[param]]
130+
name = "log_rotation_policy"
131+
type = "ballista_core::config::LogRotationPolicy"
132+
doc = "Tracing log rotation policy, possible values: minutely, hourly, daily, never. Default: daily"
133+
default = "ballista_core::config::LogRotationPolicy::Daily"

ballista/executor/src/main.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use tokio::signal;
3333
use tokio::{fs, time};
3434
use uuid::Uuid;
3535

36-
use ballista_core::config::TaskSchedulingPolicy;
36+
use ballista_core::config::{LogRotationPolicy, TaskSchedulingPolicy};
3737
use ballista_core::error::BallistaError;
3838
use ballista_core::serde::protobuf::{
3939
executor_registration, scheduler_grpc_client::SchedulerGrpcClient,
@@ -93,13 +93,32 @@ async fn main() -> Result<()> {
9393
let grpc_port = opt.bind_grpc_port;
9494
let log_dir = opt.log_dir;
9595
let print_thread_info = opt.print_thread_info;
96-
let scheduler_name = format!("executor_{}_{}", bind_host, port);
96+
let log_file_name_prefix = format!(
97+
"executor_{}_{}",
98+
external_host
99+
.clone()
100+
.unwrap_or_else(|| "localhost".to_string()),
101+
port
102+
);
97103

98104
let rust_log = env::var(EnvFilter::DEFAULT_ENV);
99105
let log_filter = EnvFilter::new(rust_log.unwrap_or(special_mod_log_level));
100106
// File layer
101107
if let Some(log_dir) = log_dir {
102-
let log_file = tracing_appender::rolling::daily(log_dir, &scheduler_name);
108+
let log_file = match opt.log_rotation_policy {
109+
LogRotationPolicy::Minutely => {
110+
tracing_appender::rolling::minutely(log_dir, &log_file_name_prefix)
111+
}
112+
LogRotationPolicy::Hourly => {
113+
tracing_appender::rolling::hourly(log_dir, &log_file_name_prefix)
114+
}
115+
LogRotationPolicy::Daily => {
116+
tracing_appender::rolling::daily(log_dir, &log_file_name_prefix)
117+
}
118+
LogRotationPolicy::Never => {
119+
tracing_appender::rolling::never(log_dir, &log_file_name_prefix)
120+
}
121+
};
103122
tracing_subscriber::fmt()
104123
.with_ansi(true)
105124
.with_thread_names(print_thread_info)

ballista/scheduler/scheduler_config_spec.toml

+6
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,9 @@ name = "log_level_setting"
129129
type = "String"
130130
doc = "special log level for sub mod. link: https://docs.rs/env_logger/latest/env_logger/#enabling-logging. For example we want whole level is INFO but datafusion mode is DEBUG"
131131
default = "std::string::String::from(\"INFO,datafusion=INFO\")"
132+
133+
[[param]]
134+
name = "log_rotation_policy"
135+
type = "ballista_core::config::LogRotationPolicy"
136+
doc = "Tracing log rotation policy, possible values: minutely, hourly, daily, never. Default: daily"
137+
default = "ballista_core::config::LogRotationPolicy::Daily"

ballista/scheduler/src/main.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod config {
6262

6363
use ballista_core::utils::create_grpc_server;
6464

65+
use ballista_core::config::LogRotationPolicy;
6566
use ballista_scheduler::config::SchedulerConfig;
6667
#[cfg(feature = "flight-sql")]
6768
use ballista_scheduler::flight_sql::FlightSqlServiceImpl;
@@ -170,7 +171,20 @@ async fn main() -> Result<()> {
170171
let log_filter = EnvFilter::new(rust_log.unwrap_or(special_mod_log_level));
171172
// File layer
172173
if let Some(log_dir) = log_dir {
173-
let log_file = tracing_appender::rolling::daily(log_dir, &log_file_name_prefix);
174+
let log_file = match opt.log_rotation_policy {
175+
LogRotationPolicy::Minutely => {
176+
tracing_appender::rolling::minutely(log_dir, &log_file_name_prefix)
177+
}
178+
LogRotationPolicy::Hourly => {
179+
tracing_appender::rolling::hourly(log_dir, &log_file_name_prefix)
180+
}
181+
LogRotationPolicy::Daily => {
182+
tracing_appender::rolling::daily(log_dir, &log_file_name_prefix)
183+
}
184+
LogRotationPolicy::Never => {
185+
tracing_appender::rolling::never(log_dir, &log_file_name_prefix)
186+
}
187+
};
174188
tracing_subscriber::fmt()
175189
.with_ansi(true)
176190
.with_thread_names(print_thread_info)

0 commit comments

Comments
 (0)