From a283e13da744b6bbe3b08e7b0940ac2d3e03e4c6 Mon Sep 17 00:00:00 2001 From: Kaifeng Zheng <100595273+Kev1n8@users.noreply.github.com> Date: Sat, 5 Oct 2024 02:05:40 +0800 Subject: [PATCH] feat: set max log files to 720 by default, info log only (#4787) * feat: set max log files to 720 by default, info log only * expose max_log_files in tomls * include dir info when panicing, limit max_log_files of err_log to 30, and that of slow_queries to opt.max_log_files * fix clippy * update config.md * update expected config str * limit err_log max files size to `max_log_files` too, include err info when panicing, put `max_l_f` in right position * fix typos * chore: config Co-authored-by: Lei, HUANG <6406592+v0y4g3r@users.noreply.github.com> --------- Co-authored-by: dennis zhuang Co-authored-by: Lei, HUANG <6406592+v0y4g3r@users.noreply.github.com> --- config/config.md | 5 +++ config/datanode.example.toml | 3 ++ config/flownode.example.toml | 3 ++ config/frontend.example.toml | 3 ++ config/metasrv.example.toml | 3 ++ config/standalone.example.toml | 3 ++ src/common/telemetry/src/logging.rs | 44 +++++++++++++++++++---- src/log-store/src/kafka/client_manager.rs | 2 +- tests-integration/tests/http.rs | 1 + 9 files changed, 60 insertions(+), 7 deletions(-) diff --git a/config/config.md b/config/config.md index d413936ff3cd..6a48ed717e69 100644 --- a/config/config.md +++ b/config/config.md @@ -161,6 +161,7 @@ | `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. | | `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. | | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | +| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `logging.slow_query` | -- | -- | The slow query log options. | @@ -251,6 +252,7 @@ | `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. | | `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. | | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | +| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `logging.slow_query` | -- | -- | The slow query log options. | @@ -320,6 +322,7 @@ | `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. | | `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. | | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | +| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `logging.slow_query` | -- | -- | The slow query log options. | @@ -476,6 +479,7 @@ | `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. | | `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. | | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | +| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `logging.slow_query` | -- | -- | The slow query log options. | @@ -526,6 +530,7 @@ | `logging.otlp_endpoint` | String | `http://localhost:4317` | The OTLP tracing endpoint. | | `logging.append_stdout` | Bool | `true` | Whether to append logs to stdout. | | `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. | +| `logging.max_log_files` | Integer | `720` | The maximum amount of log files. | | `logging.tracing_sample_ratio` | -- | -- | The percentage of tracing will be sampled and exported.
Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1.
ratio > 1 are treated as 1. Fractions < 0 are treated as 0 | | `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- | | `logging.slow_query` | -- | -- | The slow query log options. | diff --git a/config/datanode.example.toml b/config/datanode.example.toml index 06a59ebd6fcd..22670f857c06 100644 --- a/config/datanode.example.toml +++ b/config/datanode.example.toml @@ -580,6 +580,9 @@ append_stdout = true ## The log format. Can be `text`/`json`. log_format = "text" +## The maximum amount of log files. +max_log_files = 720 + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/flownode.example.toml b/config/flownode.example.toml index 9d6d2fe5aa68..34825542fa06 100644 --- a/config/flownode.example.toml +++ b/config/flownode.example.toml @@ -78,6 +78,9 @@ append_stdout = true ## The log format. Can be `text`/`json`. log_format = "text" +## The maximum amount of log files. +max_log_files = 720 + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/frontend.example.toml b/config/frontend.example.toml index cc9698f61e88..83e7808d4667 100644 --- a/config/frontend.example.toml +++ b/config/frontend.example.toml @@ -185,6 +185,9 @@ append_stdout = true ## The log format. Can be `text`/`json`. log_format = "text" +## The maximum amount of log files. +max_log_files = 720 + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/metasrv.example.toml b/config/metasrv.example.toml index 8431940b45aa..416f5ee6ef23 100644 --- a/config/metasrv.example.toml +++ b/config/metasrv.example.toml @@ -172,6 +172,9 @@ append_stdout = true ## The log format. Can be `text`/`json`. log_format = "text" +## The maximum amount of log files. +max_log_files = 720 + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/config/standalone.example.toml b/config/standalone.example.toml index 2d14b6550f3c..4c40d2dde6db 100644 --- a/config/standalone.example.toml +++ b/config/standalone.example.toml @@ -624,6 +624,9 @@ append_stdout = true ## The log format. Can be `text`/`json`. log_format = "text" +## The maximum amount of log files. +max_log_files = 720 + ## The percentage of tracing will be sampled and exported. ## Valid range `[0, 1]`, 1 means all traces are sampled, 0 means all traces are not sampled, the default value is 1. ## ratio > 1 are treated as 1. Fractions < 0 are treated as 0 diff --git a/src/common/telemetry/src/logging.rs b/src/common/telemetry/src/logging.rs index c21766f04dc9..4c5a9ee18f88 100644 --- a/src/common/telemetry/src/logging.rs +++ b/src/common/telemetry/src/logging.rs @@ -54,6 +54,9 @@ pub struct LoggingOptions { /// The log format that can be one of "json" or "text". Default is "text". pub log_format: LogFormat, + /// The maximum number of log files set by default. + pub max_log_files: usize, + /// Whether to append logs to stdout. Default is true. pub append_stdout: bool, @@ -116,6 +119,8 @@ impl Default for LoggingOptions { tracing_sample_ratio: None, append_stdout: true, slow_query: SlowQueryOptions::default(), + // Rotation hourly, 24 files per day, keeps info log files of 30 days + max_log_files: 720, } } } @@ -206,8 +211,17 @@ pub fn init_global_logging( // Configure the file logging layer with rolling policy. let file_logging_layer = if !opts.dir.is_empty() { - let rolling_appender = - RollingFileAppender::new(Rotation::HOURLY, &opts.dir, "greptimedb"); + let rolling_appender = RollingFileAppender::builder() + .rotation(Rotation::HOURLY) + .filename_prefix("greptimedb") + .max_log_files(opts.max_log_files) + .build(&opts.dir) + .unwrap_or_else(|e| { + panic!( + "initializing rolling file appender at {} failed: {}", + &opts.dir, e + ) + }); let (writer, guard) = tracing_appender::non_blocking(rolling_appender); guards.push(guard); @@ -228,8 +242,17 @@ pub fn init_global_logging( // Configure the error file logging layer with rolling policy. let err_file_logging_layer = if !opts.dir.is_empty() { - let rolling_appender = - RollingFileAppender::new(Rotation::HOURLY, &opts.dir, "greptimedb-err"); + let rolling_appender = RollingFileAppender::builder() + .rotation(Rotation::HOURLY) + .filename_prefix("greptimedb-err") + .max_log_files(opts.max_log_files) + .build(&opts.dir) + .unwrap_or_else(|e| { + panic!( + "initializing rolling file appender at {} failed: {}", + &opts.dir, e + ) + }); let (writer, guard) = tracing_appender::non_blocking(rolling_appender); guards.push(guard); @@ -256,8 +279,17 @@ pub fn init_global_logging( }; let slow_query_logging_layer = if !opts.dir.is_empty() && opts.slow_query.enable { - let rolling_appender = - RollingFileAppender::new(Rotation::HOURLY, &opts.dir, "greptimedb-slow-queries"); + let rolling_appender = RollingFileAppender::builder() + .rotation(Rotation::HOURLY) + .filename_prefix("greptimedb-slow-queries") + .max_log_files(opts.max_log_files) + .build(&opts.dir) + .unwrap_or_else(|e| { + panic!( + "initializing rolling file appender at {} failed: {}", + &opts.dir, e + ) + }); let (writer, guard) = tracing_appender::non_blocking(rolling_appender); guards.push(guard); diff --git a/src/log-store/src/kafka/client_manager.rs b/src/log-store/src/kafka/client_manager.rs index 589d5a900efb..6dfb97b027cc 100644 --- a/src/log-store/src/kafka/client_manager.rs +++ b/src/log-store/src/kafka/client_manager.rs @@ -182,7 +182,7 @@ mod tests { use super::*; - /// Creates `num_topiocs` number of topics each will be decorated by the given decorator. + /// Creates `num_topics` number of topics each will be decorated by the given decorator. pub async fn create_topics( num_topics: usize, decorator: F, diff --git a/tests-integration/tests/http.rs b/tests-integration/tests/http.rs index 5f3eb854bbe6..20a0f4edd2ae 100644 --- a/tests-integration/tests/http.rs +++ b/tests-integration/tests/http.rs @@ -833,6 +833,7 @@ max_retry_times = 3 retry_delay = "500ms" [logging] +max_log_files = 720 append_stdout = true enable_otlp_tracing = false