diff --git a/config/config.md b/config/config.md
index d5926583d63f..778f2ca34f7f 100644
--- a/config/config.md
+++ b/config/config.md
@@ -164,7 +164,7 @@
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
| `logging.slow_query.enable` | Bool | `false` | Whether to enable slow query log. |
-| `logging.slow_query.threshold` | String | `None` | The threshold of slow query. |
+| `logging.slow_query.threshold` | String | Unset | The threshold of slow query. |
| `export_metrics` | -- | -- | The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
@@ -253,7 +253,7 @@
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
| `logging.slow_query.enable` | Bool | `false` | Whether to enable slow query log. |
-| `logging.slow_query.threshold` | String | `None` | The threshold of slow query. |
+| `logging.slow_query.threshold` | String | Unset | The threshold of slow query. |
| `export_metrics` | -- | -- | The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
@@ -321,7 +321,7 @@
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
| `logging.slow_query.enable` | Bool | `false` | Whether to enable slow query log. |
-| `logging.slow_query.threshold` | String | `None` | The threshold of slow query. |
+| `logging.slow_query.threshold` | String | Unset | The threshold of slow query. |
| `export_metrics` | -- | -- | The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
@@ -473,6 +473,9 @@
| `logging.log_format` | String | `text` | The log format. Can be `text`/`json`. |
| `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. |
+| `logging.slow_query.enable` | Bool | `false` | Whether to enable slow query log. |
+| `logging.slow_query.threshold` | String | Unset | The threshold of slow query. |
| `export_metrics` | -- | -- | The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape. |
| `export_metrics.enable` | Bool | `false` | whether enable export metrics. |
| `export_metrics.write_interval` | String | `30s` | The interval of export metrics. |
@@ -521,6 +524,6 @@
| `logging.tracing_sample_ratio.default_ratio` | Float | `1.0` | -- |
| `logging.slow_query` | -- | -- | The slow query log options. |
| `logging.slow_query.enable` | Bool | `false` | Whether to enable slow query log. |
-| `logging.slow_query.threshold` | String | `None` | The threshold of slow query. |
+| `logging.slow_query.threshold` | String | Unset | The threshold of slow query. |
| `tracing` | -- | -- | The tracing options. Only effect when compiled with `tokio-console` feature. |
| `tracing.tokio_console_addr` | String | Unset | The tokio console address. |
diff --git a/config/datanode.example.toml b/config/datanode.example.toml
index 4388c4420f8b..96848c34c41f 100644
--- a/config/datanode.example.toml
+++ b/config/datanode.example.toml
@@ -583,6 +583,15 @@ log_format = "text"
[logging.tracing_sample_ratio]
default_ratio = 1.0
+## The slow query log options.
+[logging.slow_query]
+## Whether to enable slow query log.
+enable = false
+
+## The threshold of slow query.
+## @toml2docs:none-default
+threshold = "10s"
+
## The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
## This is only used for `greptimedb` to export its own metrics internally. It's different from prometheus scrape.
[export_metrics]
diff --git a/config/flownode.example.toml b/config/flownode.example.toml
index dc0740368ef4..defb5ef1e8d1 100644
--- a/config/flownode.example.toml
+++ b/config/flownode.example.toml
@@ -90,7 +90,7 @@ default_ratio = 1.0
enable = false
## The threshold of slow query.
-## +toml2docs:none-default
+## @toml2docs:none-default
threshold = "10s"
## The tracing options. Only effect when compiled with `tokio-console` feature.
diff --git a/config/frontend.example.toml b/config/frontend.example.toml
index 85cfb792eed0..2c6ecd7f53b0 100644
--- a/config/frontend.example.toml
+++ b/config/frontend.example.toml
@@ -197,7 +197,7 @@ default_ratio = 1.0
enable = false
## The threshold of slow query.
-## +toml2docs:none-default
+## @toml2docs:none-default
threshold = "10s"
## The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
diff --git a/config/metasrv.example.toml b/config/metasrv.example.toml
index 1726a747d171..f518e7826b2f 100644
--- a/config/metasrv.example.toml
+++ b/config/metasrv.example.toml
@@ -184,7 +184,7 @@ default_ratio = 1.0
enable = false
## The threshold of slow query.
-## +toml2docs:none-default
+## @toml2docs:none-default
threshold = "10s"
## The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
diff --git a/config/standalone.example.toml b/config/standalone.example.toml
index f632152a7d8f..c99bbda49eba 100644
--- a/config/standalone.example.toml
+++ b/config/standalone.example.toml
@@ -633,7 +633,7 @@ default_ratio = 1.0
enable = false
## The threshold of slow query.
-## +toml2docs:none-default
+## @toml2docs:none-default
threshold = "10s"
## The datanode can export its metrics and send to Prometheus compatible service (e.g. send to `greptimedb` itself) from remote-write API.
diff --git a/src/common/telemetry/src/logging.rs b/src/common/telemetry/src/logging.rs
index 05c7af2f81ed..bd0e3e53421e 100644
--- a/src/common/telemetry/src/logging.rs
+++ b/src/common/telemetry/src/logging.rs
@@ -71,7 +71,7 @@ pub struct LoggingOptions {
}
/// The slow query log options.
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(Clone, Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct SlowQueryLoggingOptions {
/// Whether to enable slow query log.
@@ -82,15 +82,6 @@ pub struct SlowQueryLoggingOptions {
pub threshold: Option,
}
-impl Default for SlowQueryLoggingOptions {
- fn default() -> Self {
- Self {
- enable: false,
- threshold: None,
- }
- }
-}
-
#[derive(Clone, Debug, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum LogFormat {
@@ -341,6 +332,7 @@ pub fn init_global_logging(
.with(stdout_logging_layer)
.with(file_logging_layer)
.with(err_file_logging_layer)
+ .with(slow_query_logging_layer)
};
// consume the `tracing_opts` to avoid "unused" warnings.
diff --git a/src/servers/tests/http/http_handler_test.rs b/src/servers/tests/http/http_handler_test.rs
index d31352072bfb..c6613be63479 100644
--- a/src/servers/tests/http/http_handler_test.rs
+++ b/src/servers/tests/http/http_handler_test.rs
@@ -45,6 +45,7 @@ async fn test_sql_not_provided() {
let api_state = ApiState {
sql_handler,
script_handler: None,
+ slow_query_threshold: None,
};
for format in ["greptimedb_v1", "influxdb_v1", "csv", "table"] {
@@ -79,6 +80,7 @@ async fn test_sql_output_rows() {
let api_state = ApiState {
sql_handler,
script_handler: None,
+ slow_query_threshold: None,
};
let query_sql = "select sum(uint32s) from numbers limit 20";
@@ -185,6 +187,7 @@ async fn test_dashboard_sql_limit() {
let api_state = ApiState {
sql_handler,
script_handler: None,
+ slow_query_threshold: None,
};
for format in ["greptimedb_v1", "csv", "table"] {
let query = create_query(format, "select * from numbers", Some(1000));
@@ -231,6 +234,7 @@ async fn test_sql_form() {
let api_state = ApiState {
sql_handler,
script_handler: None,
+ slow_query_threshold: None,
};
for format in ["greptimedb_v1", "influxdb_v1", "csv", "table"] {
@@ -352,6 +356,7 @@ async fn insert_script(
State(ApiState {
sql_handler: sql_handler.clone(),
script_handler: Some(script_handler.clone()),
+ slow_query_threshold: None,
}),
invalid_query,
body,
@@ -369,6 +374,7 @@ async fn insert_script(
State(ApiState {
sql_handler: sql_handler.clone(),
script_handler: Some(script_handler.clone()),
+ slow_query_threshold: None,
}),
exec,
body,
@@ -400,6 +406,7 @@ def test(n) -> vector[i64]:
State(ApiState {
sql_handler,
script_handler: Some(script_handler),
+ slow_query_threshold: None,
}),
exec,
)
@@ -468,6 +475,7 @@ def test(n, **params) -> vector[i64]:
State(ApiState {
sql_handler,
script_handler: Some(script_handler),
+ slow_query_threshold: None,
}),
exec,
)