mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 00:26:53 +00:00
fix(obs): honor profiling export contracts (#4433)
Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
+1
-1
@@ -56,7 +56,7 @@ sftp = ["rustfs-protocols/sftp"]
|
||||
license = []
|
||||
io-scheduler-debug = [] # Enable debug information in I/O scheduler
|
||||
tracing-chunk-debug = [] # Enable per-chunk tracing in data plane (high noise, for debugging only)
|
||||
full = ["metrics-gpu", "ftps", "swift", "webdav", "sftp"]
|
||||
full = ["metrics-gpu", "ftps", "swift", "webdav", "sftp", "pyroscope"]
|
||||
manual-test-runners = []
|
||||
rio-v2 = ["rustfs-ecstore/rio-v2"]
|
||||
pyroscope = ["rustfs-obs/pyroscope"]
|
||||
|
||||
+57
-1
@@ -12,7 +12,11 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use tracing::{debug, info};
|
||||
use rustfs_config::{
|
||||
ENV_CPU_DURATION_SECS, ENV_CPU_FREQ, ENV_CPU_INTERVAL_SECS, ENV_CPU_MODE, ENV_ENABLE_PROFILING, ENV_MEM_INTERVAL_SECS,
|
||||
ENV_MEM_PERIODIC, ENV_OUTPUT_DIR,
|
||||
};
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
const LOG_COMPONENT_PROFILING: &str = "profiling";
|
||||
const LOG_SUBSYSTEM_CPU: &str = "cpu";
|
||||
@@ -23,7 +27,32 @@ const MEMORY_PPROF_UNSUPPORTED_REASON: &str = "mimalloc_memory_pprof_unsupported
|
||||
pub const LOCAL_CPU_PPROF_UNSUPPORTED_SUMMARY: &str = "local CPU pprof dumps are not supported; use Pyroscope export instead";
|
||||
pub const MEMORY_PPROF_UNSUPPORTED_SUMMARY: &str = "memory pprof dumps are not supported with the mimalloc allocator";
|
||||
|
||||
const LEGACY_PROFILING_ENV_KEYS: [&str; 8] = [
|
||||
ENV_ENABLE_PROFILING,
|
||||
ENV_CPU_MODE,
|
||||
ENV_CPU_FREQ,
|
||||
ENV_CPU_INTERVAL_SECS,
|
||||
ENV_CPU_DURATION_SECS,
|
||||
ENV_MEM_PERIODIC,
|
||||
ENV_MEM_INTERVAL_SECS,
|
||||
ENV_OUTPUT_DIR,
|
||||
];
|
||||
|
||||
pub async fn init_from_env() {
|
||||
let legacy_keys = legacy_profiling_env_keys_present();
|
||||
if !legacy_keys.is_empty() {
|
||||
warn!(
|
||||
component = LOG_COMPONENT_PROFILING,
|
||||
subsystem = LOG_SUBSYSTEM_RUNTIME,
|
||||
event = "profiling_legacy_env_ignored",
|
||||
ignored_keys = %legacy_keys.join(", "),
|
||||
recommended_enable_key = "RUSTFS_OBS_PROFILING_EXPORT_ENABLED",
|
||||
recommended_endpoint_key = "RUSTFS_OBS_PROFILING_ENDPOINT",
|
||||
output_dir_key = ENV_OUTPUT_DIR,
|
||||
"Legacy local profiling environment variables are ignored; use observability profiling export settings instead"
|
||||
);
|
||||
}
|
||||
|
||||
info!(
|
||||
component = LOG_COMPONENT_PROFILING,
|
||||
subsystem = LOG_SUBSYSTEM_RUNTIME,
|
||||
@@ -88,6 +117,33 @@ fn unsupported_message(summary: &str) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
fn legacy_profiling_env_keys_present() -> Vec<&'static str> {
|
||||
LEGACY_PROFILING_ENV_KEYS
|
||||
.into_iter()
|
||||
.filter(|key| std::env::var_os(key).is_some())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn target_env() -> &'static str {
|
||||
option_env!("CARGO_CFG_TARGET_ENV").unwrap_or("unknown")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn legacy_profiling_env_keys_present_reports_legacy_overrides() {
|
||||
temp_env::with_vars(
|
||||
[
|
||||
(ENV_ENABLE_PROFILING, Some("true")),
|
||||
(ENV_OUTPUT_DIR, Some("/tmp/rustfs-profiles")),
|
||||
],
|
||||
|| {
|
||||
let keys = legacy_profiling_env_keys_present();
|
||||
assert!(keys.contains(&ENV_ENABLE_PROFILING));
|
||||
assert!(keys.contains(&ENV_OUTPUT_DIR));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user