chore(io-metrics): make the server label injected, drop two leaf-violating deps (#6051)

This commit is contained in:
Zhengchao An
2026-08-13 11:20:18 +08:00
committed by GitHub
parent 3a0dbccc2e
commit db4707f187
5 changed files with 45 additions and 25 deletions
Generated
-2
View File
@@ -9620,9 +9620,7 @@ dependencies = [
"metrics",
"metrics-util",
"num_cpus",
"rustfs-common",
"rustfs-s3-ops",
"rustfs-utils",
"sysinfo",
"thiserror 2.0.20",
"tokio",
+3
View File
@@ -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;
}
-8
View File
@@ -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"] }
+12 -15
View File
@@ -196,22 +196,19 @@ pub const INTERNODE_OPERATION_METRICS: &[InternodeOperationMetricDescriptor] = &
},
];
static STABLE_SERVER_LABEL: OnceLock<String> = 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<String>) {
let _ = STABLE_SERVER_LABEL.set(label.into());
}
fn current_server_label() -> &'static str {
static STABLE_SERVER_LABEL: OnceLock<String> = OnceLock::new();
static FALLBACK_SERVER_LABEL: LazyLock<String> = 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)]
@@ -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