From c4d5c5c5ecd74f3c4b0fbb07db966ff39b2473b8 Mon Sep 17 00:00:00 2001 From: houseme Date: Tue, 28 Apr 2026 19:57:15 +0800 Subject: [PATCH] fix(obs): disable profiling export by default and fix Helm env name (#2719) --- crates/config/src/constants/app.rs | 4 +-- crates/obs/README.md | 6 ++-- crates/obs/src/config.rs | 50 ++++++++++++++++++++++++++-- helm/rustfs/templates/configmap.yaml | 3 +- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/crates/config/src/constants/app.rs b/crates/config/src/constants/app.rs index 96ee6c00c..8a8a2a4b7 100644 --- a/crates/config/src/constants/app.rs +++ b/crates/config/src/constants/app.rs @@ -296,9 +296,9 @@ pub const DEFAULT_OBS_LOGS_EXPORT_ENABLED: bool = true; /// Default profiling export enabled /// It is used to enable or disable exporting profiles -/// Default value: true +/// Default value: false /// Environment variable: RUSTFS_OBS_PROFILING_EXPORT_ENABLED -pub const DEFAULT_OBS_PROFILING_EXPORT_ENABLED: bool = true; +pub const DEFAULT_OBS_PROFILING_EXPORT_ENABLED: bool = false; /// Default log local logging enabled for rustfs /// This is the default log local logging enabled for rustfs. diff --git a/crates/obs/README.md b/crates/obs/README.md index 570083b49..38cf734bd 100644 --- a/crates/obs/README.md +++ b/crates/obs/README.md @@ -80,7 +80,9 @@ The library selects a backend automatically based on configuration: ``` 1. Any OTLP endpoint set? - └─ YES → Full OTLP/HTTP pipeline (traces + metrics + logs + profiling) + └─ YES → Full OTLP/HTTP pipeline (traces + metrics + logs) + + Profiling (Pyroscope) only if: + - RUSTFS_OBS_PROFILING_EXPORT_ENABLED=true (explicit opt-in, default: false) 2. RUSTFS_OBS_LOG_DIRECTORY set to a non-empty path? └─ YES → Rolling-file JSON logging @@ -117,7 +119,7 @@ All configuration is read from environment variables at startup. | `RUSTFS_OBS_TRACES_EXPORT_ENABLED` | `true` | Toggle trace export | | `RUSTFS_OBS_METRICS_EXPORT_ENABLED` | `true` | Toggle metrics export | | `RUSTFS_OBS_LOGS_EXPORT_ENABLED` | `true` | Toggle OTLP log export | -| `RUSTFS_OBS_PROFILING_EXPORT_ENABLED` | `true` | Toggle profiling export | +| `RUSTFS_OBS_PROFILING_EXPORT_ENABLED` | `false` | Toggle profiling export | | `RUSTFS_OBS_USE_STDOUT` | `false` | Mirror all signals to stdout alongside OTLP | | `RUSTFS_OBS_SAMPLE_RATIO` | `0.1` | Trace sampling ratio `0.0`–`1.0` | | `RUSTFS_OBS_METER_INTERVAL` | `15` | Metrics export interval (seconds) | diff --git a/crates/obs/src/config.rs b/crates/obs/src/config.rs index b9fc834a9..4abd0a160 100644 --- a/crates/obs/src/config.rs +++ b/crates/obs/src/config.rs @@ -48,10 +48,15 @@ use rustfs_config::{ DEFAULT_OBS_PROFILING_EXPORT_ENABLED, DEFAULT_OBS_TRACES_EXPORT_ENABLED, ENVIRONMENT, METER_INTERVAL, SAMPLE_RATIO, SERVICE_VERSION, USE_STDOUT, }; -use rustfs_utils::{get_env_bool, get_env_f64, get_env_opt_str, get_env_opt_u64, get_env_str, get_env_u64, get_env_usize}; +use rustfs_utils::{ + get_env_bool, get_env_bool_with_aliases, get_env_f64, get_env_opt_str, get_env_opt_u64, get_env_str, get_env_u64, + get_env_usize, +}; use serde::{Deserialize, Serialize}; use std::env; +const LEGACY_ENV_OBS_PROFILING_ENABLED: &str = "RUSTFS_OBS_PROFILING_ENABLED"; + /// Full observability configuration used by all telemetry backends. /// /// Fields are grouped into three logical sections: @@ -134,7 +139,7 @@ pub struct OtelConfig { pub metrics_export_enabled: Option, /// Whether to export logs via OTLP (default: `true`). pub logs_export_enabled: Option, - /// Whether to export profiles via pyroscope (default: `true`). + /// Whether to export profiles via pyroscope (default: `false`). pub profiling_export_enabled: Option, /// **[OTLP-only]** Mirror all signals to stdout in addition to OTLP export. /// Only applies when an OTLP endpoint is configured. @@ -282,7 +287,11 @@ impl OtelConfig { traces_export_enabled: Some(get_env_bool(ENV_OBS_TRACES_EXPORT_ENABLED, DEFAULT_OBS_TRACES_EXPORT_ENABLED)), metrics_export_enabled: Some(get_env_bool(ENV_OBS_METRICS_EXPORT_ENABLED, DEFAULT_OBS_METRICS_EXPORT_ENABLED)), logs_export_enabled: Some(get_env_bool(ENV_OBS_LOGS_EXPORT_ENABLED, DEFAULT_OBS_LOGS_EXPORT_ENABLED)), - profiling_export_enabled: Some(get_env_bool(ENV_OBS_PROFILING_EXPORT_ENABLED, DEFAULT_OBS_PROFILING_EXPORT_ENABLED)), + profiling_export_enabled: Some(get_env_bool_with_aliases( + ENV_OBS_PROFILING_EXPORT_ENABLED, + &[LEGACY_ENV_OBS_PROFILING_ENABLED], + DEFAULT_OBS_PROFILING_EXPORT_ENABLED, + )), use_stdout: Some(use_stdout), sample_ratio: Some(get_env_f64(ENV_OBS_SAMPLE_RATIO, SAMPLE_RATIO)), meter_interval: Some(get_env_u64(ENV_OBS_METER_INTERVAL, METER_INTERVAL)), @@ -415,3 +424,38 @@ impl Default for AppConfig { pub fn is_production_environment() -> bool { get_env_str(ENV_OBS_ENVIRONMENT, ENVIRONMENT).eq_ignore_ascii_case(DEFAULT_OBS_ENVIRONMENT_PRODUCTION) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn profiling_export_defaults_to_disabled_when_unset() { + temp_env::with_var_unset(ENV_OBS_PROFILING_EXPORT_ENABLED, || { + temp_env::with_var_unset(LEGACY_ENV_OBS_PROFILING_ENABLED, || { + let config = OtelConfig::extract_otel_config_from_env(None); + assert_eq!(config.profiling_export_enabled, Some(false)); + }); + }); + } + + #[test] + fn profiling_export_accepts_legacy_env_alias() { + temp_env::with_var_unset(ENV_OBS_PROFILING_EXPORT_ENABLED, || { + temp_env::with_var(LEGACY_ENV_OBS_PROFILING_ENABLED, Some("true"), || { + let config = OtelConfig::extract_otel_config_from_env(None); + assert_eq!(config.profiling_export_enabled, Some(true)); + }); + }); + } + + #[test] + fn canonical_profiling_toggle_has_priority_over_legacy_alias() { + temp_env::with_var(LEGACY_ENV_OBS_PROFILING_ENABLED, Some("true"), || { + temp_env::with_var(ENV_OBS_PROFILING_EXPORT_ENABLED, Some("false"), || { + let config = OtelConfig::extract_otel_config_from_env(None); + assert_eq!(config.profiling_export_enabled, Some(false)); + }); + }); + } +} diff --git a/helm/rustfs/templates/configmap.yaml b/helm/rustfs/templates/configmap.yaml index c54dfa657..39a5fb524 100644 --- a/helm/rustfs/templates/configmap.yaml +++ b/helm/rustfs/templates/configmap.yaml @@ -65,9 +65,10 @@ data: {{- end }} {{- if .profiling.enabled }} RUSTFS_OBS_PROFILING_ENDPOINT: {{ .profiling.endpoint | quote }} + RUSTFS_OBS_PROFILING_EXPORT_ENABLED: "true" {{- else }} RUSTFS_OBS_PROFILING_ENDPOINT: "" - RUSTFS_OBS_PROFILING_ENABLED: "false" + RUSTFS_OBS_PROFILING_EXPORT_ENABLED: "false" {{- end }} {{- end }} {{- end }}