fix(obs): disable profiling export by default and fix Helm env name (#2719)

This commit is contained in:
houseme
2026-04-28 19:57:15 +08:00
committed by GitHub
parent c698a0f2b6
commit c4d5c5c5ec
4 changed files with 55 additions and 8 deletions
+47 -3
View File
@@ -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<bool>,
/// Whether to export logs via OTLP (default: `true`).
pub logs_export_enabled: Option<bool>,
/// Whether to export profiles via pyroscope (default: `true`).
/// Whether to export profiles via pyroscope (default: `false`).
pub profiling_export_enabled: Option<bool>,
/// **[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));
});
});
}
}