perf(observability): avoid cgroup path allocation (#5711)

* perf(observability): avoid cgroup path allocation

Co-Authored-By: heihutu <heihutu@gmail.com>

* test(e2e): satisfy regression test clippy

Co-Authored-By: heihutu <heihutu@gmail.com>

---------

Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
houseme
2026-08-05 01:47:07 +08:00
committed by GitHub
parent 15c2bade5f
commit 3dabac4a09
9 changed files with 50 additions and 55 deletions
@@ -430,12 +430,16 @@ mod tests {
#[test]
fn issued_credentials_and_replication_item_use_minio_parent_shape() {
let transaction = transaction();
let expected_parent = transaction
.authorization
.oidc_virtual_parent()
.expect("test authorization should have a virtual parent");
let secret = "federated-session-test-signing-secret";
let selected_policy_names = vec!["readonly".to_string()];
let credentials =
issue_credentials(&transaction, &selected_policy_names, Some(secret)).expect("credential issuance should succeed");
assert_eq!(credentials.parent_user, "TwyekekG2eMes0qk9Tgh7KXEitwGi1z2W1f2KccrXGA");
assert_eq!(credentials.parent_user, expected_parent);
assert_eq!(credentials.groups, Some(vec!["devs".to_string()]));
assert_eq!(credentials.status, "on");
assert!(!credentials.access_key.is_empty());
@@ -468,11 +472,8 @@ mod tests {
("preferred_username".to_string(), serde_json::json!("user")),
("groups".to_string(), serde_json::json!(["devs"])),
("roles".to_string(), serde_json::json!(["admin", "reader"])),
("parent".to_string(), serde_json::json!("TwyekekG2eMes0qk9Tgh7KXEitwGi1z2W1f2KccrXGA")),
(
OIDC_VIRTUAL_PARENT_CLAIM.to_string(),
serde_json::json!("TwyekekG2eMes0qk9Tgh7KXEitwGi1z2W1f2KccrXGA"),
),
("parent".to_string(), serde_json::json!(expected_parent)),
(OIDC_VIRTUAL_PARENT_CLAIM.to_string(), serde_json::json!(expected_parent)),
("policy".to_string(), serde_json::json!("readonly")),
])
);
@@ -499,7 +500,7 @@ mod tests {
"accessKey": "<access-key>",
"secretKey": "<secret-key>",
"sessionToken": "<session-token>",
"parentUser": "TwyekekG2eMes0qk9Tgh7KXEitwGi1z2W1f2KccrXGA",
"parentUser": expected_parent,
"parentPolicyMapping": OIDC_STS_REQUIRES_VIRTUAL_PARENT_RECEIVER_POLICY,
"apiVersion": SITE_REPL_API_VERSION,
},
+12 -18
View File
@@ -33,6 +33,12 @@ static MEMORY_SYSTEM: OnceLock<Mutex<System>> = OnceLock::new();
const ENV_MEMORY_OBSERVABILITY_INTERVAL_SECS: &str = "RUSTFS_MEMORY_OBSERVABILITY_INTERVAL_SECS";
const DEFAULT_MEMORY_OBSERVABILITY_INTERVAL_SECS: u64 = 15;
const MEMORY_OBSERVABILITY_SERVICE_NAME: &str = "memory_observability";
const CGROUP_V2_MEMORY_STAT_PATH: &str = "/sys/fs/cgroup/memory.stat";
const CGROUP_V2_MEMORY_CURRENT_PATH: &str = "/sys/fs/cgroup/memory.current";
const CGROUP_V2_MEMORY_MAX_PATH: &str = "/sys/fs/cgroup/memory.max";
const CGROUP_V1_MEMORY_STAT_PATH: &str = "/sys/fs/cgroup/memory/memory.stat";
const CGROUP_V1_MEMORY_USAGE_PATH: &str = "/sys/fs/cgroup/memory/memory.usage_in_bytes";
const CGROUP_V1_MEMORY_LIMIT_PATH: &str = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
@@ -198,16 +204,10 @@ fn parse_cgroup_memory_stat(content: &str) -> CgroupMemoryStatFields {
}
fn read_cgroup_v2() -> Option<CgroupMemorySnapshot> {
let root = Path::new("/sys/fs/cgroup");
let stat_path = root.join("memory.stat");
if !stat_path.exists() {
return None;
}
let stats = parse_cgroup_memory_stat(&std::fs::read_to_string(&stat_path).ok()?);
let stats = parse_cgroup_memory_stat(&std::fs::read_to_string(CGROUP_V2_MEMORY_STAT_PATH).ok()?);
Some(CgroupMemorySnapshot {
current_bytes: read_optional_u64(&root.join("memory.current")),
limit_bytes: read_optional_u64(&root.join("memory.max")),
current_bytes: read_optional_u64(Path::new(CGROUP_V2_MEMORY_CURRENT_PATH)),
limit_bytes: read_optional_u64(Path::new(CGROUP_V2_MEMORY_MAX_PATH)),
anon_bytes: stats.anon,
file_bytes: stats.file,
active_file_bytes: stats.active_file,
@@ -216,16 +216,10 @@ fn read_cgroup_v2() -> Option<CgroupMemorySnapshot> {
}
fn read_cgroup_v1() -> Option<CgroupMemorySnapshot> {
let root = Path::new("/sys/fs/cgroup/memory");
let stat_path = root.join("memory.stat");
if !stat_path.exists() {
return None;
}
let stats = parse_cgroup_memory_stat(&std::fs::read_to_string(&stat_path).ok()?);
let stats = parse_cgroup_memory_stat(&std::fs::read_to_string(CGROUP_V1_MEMORY_STAT_PATH).ok()?);
Some(CgroupMemorySnapshot {
current_bytes: read_optional_u64(&root.join("memory.usage_in_bytes")),
limit_bytes: read_optional_u64(&root.join("memory.limit_in_bytes")),
current_bytes: read_optional_u64(Path::new(CGROUP_V1_MEMORY_USAGE_PATH)),
limit_bytes: read_optional_u64(Path::new(CGROUP_V1_MEMORY_LIMIT_PATH)),
anon_bytes: stats.total_rss.or(stats.rss),
file_bytes: stats.total_cache.or(stats.cache),
active_file_bytes: stats.total_active_file.or(stats.active_file),