From db4707f18700541577b4c015c41791792d44002e Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Thu, 13 Aug 2026 11:20:18 +0800 Subject: [PATCH] chore(io-metrics): make the server label injected, drop two leaf-violating deps (#6051) --- Cargo.lock | 2 -- crates/ecstore/src/runtime/sources.rs | 3 ++ crates/io-metrics/Cargo.toml | 8 ----- crates/io-metrics/src/internode_metrics.rs | 27 ++++++++--------- scripts/check_architecture_migration_rules.sh | 30 +++++++++++++++++++ 5 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00dd64a1f..87056b90c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9620,9 +9620,7 @@ dependencies = [ "metrics", "metrics-util", "num_cpus", - "rustfs-common", "rustfs-s3-ops", - "rustfs-utils", "sysinfo", "thiserror 2.0.20", "tokio", diff --git a/crates/ecstore/src/runtime/sources.rs b/crates/ecstore/src/runtime/sources.rs index a728b7a42..ed35c14d3 100644 --- a/crates/ecstore/src/runtime/sources.rs +++ b/crates/ecstore/src/runtime/sources.rs @@ -164,6 +164,9 @@ pub(crate) async fn local_node_name() -> String { } pub(crate) async fn set_local_node_name(node_name: String) { + // Also stamp the internode-metrics server label: io-metrics is a leaf + // crate and no longer resolves node identity itself (backlog#1834). + rustfs_io_metrics::internode_metrics::set_internode_server_label(node_name.as_str()); rustfs_common::set_global_local_node_name(&node_name).await; } diff --git a/crates/io-metrics/Cargo.toml b/crates/io-metrics/Cargo.toml index 64eac650b..6124de8ca 100644 --- a/crates/io-metrics/Cargo.toml +++ b/crates/io-metrics/Cargo.toml @@ -33,31 +33,23 @@ default = [] hotpath = [ "hotpath/hotpath", "hotpath/tokio", - "rustfs-common/hotpath", "rustfs-s3-ops/hotpath", - "rustfs-utils/hotpath", ] hotpath-alloc = [ "hotpath", "hotpath/hotpath-alloc", - "rustfs-common/hotpath-alloc", "rustfs-s3-ops/hotpath-alloc", - "rustfs-utils/hotpath-alloc", ] hotpath-cpu = [ "hotpath", "hotpath/hotpath-cpu", - "rustfs-common/hotpath-cpu", "rustfs-s3-ops/hotpath-cpu", - "rustfs-utils/hotpath-cpu", ] [dependencies] hotpath.workspace = true metrics = { workspace = true } -rustfs-common = { workspace = true } rustfs-s3-ops = { workspace = true } -rustfs-utils = { workspace = true, features = ["ip"] } num_cpus = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true, features = ["sync", "fs", "rt-multi-thread"] } diff --git a/crates/io-metrics/src/internode_metrics.rs b/crates/io-metrics/src/internode_metrics.rs index 41ce7ceac..813bb6302 100644 --- a/crates/io-metrics/src/internode_metrics.rs +++ b/crates/io-metrics/src/internode_metrics.rs @@ -196,22 +196,19 @@ pub const INTERNODE_OPERATION_METRICS: &[InternodeOperationMetricDescriptor] = & }, ]; +static STABLE_SERVER_LABEL: OnceLock = OnceLock::new(); + +/// Injects the stable server label (node name or address) stamped on +/// internode metrics. The runtime calls this when the local node name is +/// published (see ecstore's `set_local_node_name`); the first write wins. +/// io-metrics is a leaf crate and no longer resolves node identity itself +/// (backlog#1834) — before injection the label reads "unset". +pub fn set_internode_server_label(label: impl Into) { + let _ = STABLE_SERVER_LABEL.set(label.into()); +} + fn current_server_label() -> &'static str { - static STABLE_SERVER_LABEL: OnceLock = OnceLock::new(); - static FALLBACK_SERVER_LABEL: LazyLock = LazyLock::new(rustfs_utils::get_local_ip_with_default); - - if let Some(server) = STABLE_SERVER_LABEL.get() { - return server.as_str(); - } - - if let Some(server) = rustfs_common::try_get_global_local_node_name() { - let _ = STABLE_SERVER_LABEL.set(server); - if let Some(server) = STABLE_SERVER_LABEL.get() { - return server.as_str(); - } - } - - FALLBACK_SERVER_LABEL.as_str() + STABLE_SERVER_LABEL.get().map(String::as_str).unwrap_or("unset") } #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] diff --git a/scripts/check_architecture_migration_rules.sh b/scripts/check_architecture_migration_rules.sh index 843c2407c..dba51a333 100755 --- a/scripts/check_architecture_migration_rules.sh +++ b/scripts/check_architecture_migration_rules.sh @@ -5420,6 +5420,36 @@ require_source_contains \ "fn set_disks_implements_storage_heal_operations_contract()" \ "SetDisks storage-api HealOperations compile-time coverage test" +# --- Leaf crates must stay free of internal dependencies (backlog#1834) --- +# ARCHITECTURE.md invariant 2 names config, credentials, crypto, io-metrics, +# and madmin as leaf crates that depend only on external crates. Allowlist: +# io-metrics -> rustfs-s3-ops (contract crate; leaf-allowance adjudication is +# tracked as backlog#1834 PR2). Adding any other rustfs-* dependency to a leaf +# crate needs a maintainer decision, not a quiet Cargo.toml edit. +LEAF_CRATE_DEP_HITS_FILE="${TMP_DIR}/leaf_crate_dep_hits.txt" +: >"$LEAF_CRATE_DEP_HITS_FILE" +( + cd "$ROOT_DIR" + for leaf in config credentials crypto io-metrics madmin; do + manifest="crates/${leaf}/Cargo.toml" + [[ -f "$manifest" ]] || continue + leaf_dep_status=0 + rg -n --with-filename '^rustfs-[a-z0-9-]+ *=' "$manifest" >"${TMP_DIR}/leaf_dep_raw.txt" || leaf_dep_status=$? + if [[ "$leaf_dep_status" -ne 0 && "$leaf_dep_status" -ne 1 ]]; then + exit "$leaf_dep_status" + fi + if [[ "$leaf" == "io-metrics" ]]; then + rg -v '^[^:]*:[0-9]+:rustfs-s3-ops *=' "${TMP_DIR}/leaf_dep_raw.txt" >>"$LEAF_CRATE_DEP_HITS_FILE" || true + else + cat "${TMP_DIR}/leaf_dep_raw.txt" >>"$LEAF_CRATE_DEP_HITS_FILE" + fi + done +) + +if [[ -s "$LEAF_CRATE_DEP_HITS_FILE" ]]; then + report_failure "leaf crates (config/credentials/crypto/io-metrics/madmin) must not depend on internal rustfs-* crates (allowlist: io-metrics -> rustfs-s3-ops, backlog#1834): $(paste -sd '; ' "$LEAF_CRATE_DEP_HITS_FILE")" +fi + if (( FAILURES > 0 )); then exit 1 fi