Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/health/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ nv-redfish = { workspace = true, features = [
] }
rand = { workspace = true }
url = { workspace = true, features = ["serde"] }
uuid = { workspace = true }
x509-parser = { workspace = true }

# [local-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion crates/health/benches/collector_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;
use std::sync::Arc;

use carbide_health::endpoint::{BmcAddr, EndpointMetadata, MachineData};
use carbide_health::endpoint::{BmcAddr, EndpointMetadata, MachineData, SharedSystemUuid};
use carbide_health::metrics::MetricsManager;
use carbide_health::sink::{
CollectorEvent, CompositeDataSink, DataSink, EventContext, FirmwareInfo, LogRecord,
Expand Down Expand Up @@ -59,9 +59,11 @@ fn event_context() -> EventContext {
mac: MacAddress::from_str("42:9e:b1:bd:9d:dd").unwrap(),
},
collector_type: "sensor_collector",
labels: Default::default(),
metadata: Some(EndpointMetadata::Machine(MachineData {
machine_id: Some(MACHINE_ID.parse().expect("valid machine id")),
machine_serial: None,
system_uuid: SharedSystemUuid::default(),
slot_number: None,
tray_index: None,
nvlink_domain_uuid: None,
Expand Down
6 changes: 5 additions & 1 deletion crates/health/benches/processor_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;
use std::sync::Arc;

use carbide_health::endpoint::{BmcAddr, EndpointMetadata, MachineData};
use carbide_health::endpoint::{BmcAddr, EndpointMetadata, MachineData, SharedSystemUuid};
use carbide_health::metrics::MetricsManager;
use carbide_health::processor::{
EventProcessingPipeline, EventProcessor, HealthReportProcessor, LeakEventProcessor,
Expand Down Expand Up @@ -95,9 +95,11 @@ fn event_context() -> EventContext {
mac: MacAddress::from_str("42:9e:b1:bd:9d:dd").unwrap(),
},
collector_type: "sensor_collector",
labels: Default::default(),
metadata: Some(EndpointMetadata::Machine(MachineData {
machine_id: Some(MACHINE_ID.parse().expect("valid machine id")),
machine_serial: None,
system_uuid: SharedSystemUuid::default(),
slot_number: None,
tray_index: None,
nvlink_domain_uuid: None,
Expand Down Expand Up @@ -273,9 +275,11 @@ fn rack_event_contexts(rack_id: &str, tray_count: usize) -> Vec<EventContext> {
mac: MacAddress::from_str(&mac).unwrap(),
},
collector_type: "sensor_collector",
labels: Default::default(),
metadata: Some(EndpointMetadata::Machine(MachineData {
machine_id: Some(MACHINE_ID.parse().expect("valid machine id")),
machine_serial: None,
system_uuid: SharedSystemUuid::default(),
slot_number: None,
tray_index: None,
nvlink_domain_uuid: None,
Expand Down
4 changes: 3 additions & 1 deletion crates/health/benches/sink_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;
use std::sync::Arc;

use carbide_health::endpoint::{BmcAddr, EndpointMetadata, MachineData};
use carbide_health::endpoint::{BmcAddr, EndpointMetadata, MachineData, SharedSystemUuid};
use carbide_health::metrics::MetricsManager;
use carbide_health::sink::{
Classification, CollectorEvent, CompositeDataSink, DataSink, EventContext, HealthReport,
Expand Down Expand Up @@ -69,9 +69,11 @@ fn event_context_for_machine(machine_id: &str) -> EventContext {
mac: MacAddress::from_str("42:9e:b1:bd:9d:dd").unwrap(),
},
collector_type: "sensor_collector",
labels: Default::default(),
metadata: Some(EndpointMetadata::Machine(MachineData {
machine_id: Some(machine_id.parse().expect("valid machine id")),
machine_serial: None,
system_uuid: SharedSystemUuid::default(),
slot_number: None,
tray_index: None,
nvlink_domain_uuid: None,
Expand Down
1 change: 1 addition & 0 deletions crates/health/example/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ port = 443
mac = "aa:bb:cc:dd:ee:ff"
username = "admin"
password = "secret"
labels = { site = "dev", cluster = "cluster-01", environment = "development" }
machine = { id = "fm100htjtiaehv1n5vh67tbmqq4eabcjdng40f7jupsadbedhruh6rag1l0", serial = "MN-001", slot_number = 15, tray_index = 5, nvlink_domain_uuid = "00000000-0000-0000-0000-000000000000" }

[[endpoint_sources.static_bmc_endpoints]]
Expand Down
50 changes: 34 additions & 16 deletions crates/health/src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::HealthError;
use crate::bmc::{BmcClient, BoxFuture, CredentialProvider};
use crate::endpoint::{
BmcAddr, BmcCredentials, BmcEndpoint, EndpointMetadata, EndpointSource, MachineData,
PowerShelfData, SwitchData, SwitchEndpointRole,
PowerShelfData, SharedSystemUuid, SwitchData, SwitchEndpointRole,
};

/// [`ApiEndpointSource`].
Expand Down Expand Up @@ -290,9 +290,11 @@ pub struct ApiEndpointSource {
bmc_client_cache: Mutex<HashMap<MacAddress, CachedBmcClient>>,
}

#[derive(Clone)]
struct CachedBmcClient {
client: Arc<BmcClient>,
kind: ApiCredentialKind,
system_uuid: SharedSystemUuid,
}

impl ApiEndpointSource {
Expand Down Expand Up @@ -484,6 +486,7 @@ impl ApiEndpointSource {
.as_ref()
.and_then(|info| info.dmi_data.as_ref())
.map(|dmi| dmi.chassis_serial.clone()),
system_uuid: SharedSystemUuid::default(),
slot_number: machine
.placement_in_rack
.as_ref()
Expand Down Expand Up @@ -588,7 +591,7 @@ impl ApiEndpointSource {
rack_id: Option<RackId>,
credential_kind: ApiCredentialKind,
) -> Result<Arc<BmcEndpoint>, HealthError> {
let bmc = {
let cached = {
let mut cache = self.bmc_client_cache.lock().expect("cache mutex poisoned");
cache_or_create_bmc_client(&mut cache, addr.mac, credential_kind, |kind| {
let provider: Arc<dyn CredentialProvider> = Arc::new(ApiCredentialProvider {
Expand All @@ -604,11 +607,16 @@ impl ApiEndpointSource {
)?))
})?
};
let mut metadata = metadata;
if let Some(EndpointMetadata::Machine(machine)) = metadata.as_mut() {
machine.system_uuid = cached.system_uuid;
}
Ok(Arc::new(BmcEndpoint {
addr,
metadata,
rack_id,
bmc,
labels: Default::default(),
bmc: cached.client,
}))
}
}
Expand All @@ -618,7 +626,7 @@ fn cache_or_create_bmc_client(
mac: MacAddress,
credential_kind: ApiCredentialKind,
make_client: impl FnOnce(ApiCredentialKind) -> Result<Arc<BmcClient>, HealthError>,
) -> Result<Arc<BmcClient>, HealthError> {
) -> Result<CachedBmcClient, HealthError> {
if let Some(existing) = cache.get(&mac) {
if existing.kind != credential_kind {
return Err(HealthError::GenericError(format!(
Expand All @@ -629,18 +637,17 @@ fn cache_or_create_bmc_client(
credential_kind.tag(),
)));
}
return Ok(existing.client.clone());
return Ok(existing.clone());
}

let client = make_client(credential_kind.clone())?;
cache.insert(
mac,
CachedBmcClient {
client: client.clone(),
kind: credential_kind,
},
);
Ok(client)
let cached = CachedBmcClient {
client,
kind: credential_kind,
system_uuid: SharedSystemUuid::default(),
};
cache.insert(mac, cached.clone());
Ok(cached)
}

/// Returns the machine-level GPU driver version derived from discovery data.
Expand Down Expand Up @@ -840,8 +847,8 @@ mod tests {
);
}

#[test]
fn cache_returns_existing_client_on_matching_kind() {
#[tokio::test]
async fn cache_returns_existing_client_on_matching_kind() {
let mut cache: HashMap<MacAddress, CachedBmcClient> = HashMap::new();
let factory_calls = AtomicUsize::new(0);

Expand All @@ -860,10 +867,21 @@ mod tests {
.expect("cache hit");

assert!(
Arc::ptr_eq(&first, &second),
Arc::ptr_eq(&first.client, &second.client),
"cache hit must reuse the same BmcClient Arc — otherwise every \
iteration of discovery rebuilds the session and re-fetches creds"
);
let system_uuid = uuid::uuid!("4c4c4544-0044-4710-8052-cac04f4b4632");
first
.system_uuid
.get_or_try_init(|| async { Ok::<_, std::convert::Infallible>(Some(system_uuid)) })
.await
.expect("infallible UUID initialization");
assert_eq!(
second.system_uuid.get(),
Some(system_uuid),
"cache hit must reuse machine UUID state across discovery iterations"
);
assert_eq!(
factory_calls.load(Ordering::SeqCst),
1,
Expand Down
4 changes: 3 additions & 1 deletion crates/health/src/collectors/leak_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod tests {
use mac_address::MacAddress;

use super::*;
use crate::endpoint::{BmcAddr, EndpointMetadata, MachineData};
use crate::endpoint::{BmcAddr, EndpointMetadata, MachineData, SharedSystemUuid};
use crate::sink::HealthReportTarget;

#[derive(Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -337,12 +337,14 @@ mod tests {
metadata: Some(EndpointMetadata::Machine(MachineData {
machine_id: None,
machine_serial: None,
system_uuid: SharedSystemUuid::default(),
slot_number: None,
tray_index: None,
nvlink_domain_uuid: None,
driver_version: None,
})),
rack_id: None,
labels: Default::default(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ mod tests {
collector_type,
metadata: None,
rack_id: None,
labels: Default::default(),
}
}

Expand Down Expand Up @@ -779,6 +780,7 @@ mod tests {
mac: MacAddress::from_str("AA:BB:CC:DD:EE:FF").unwrap(),
},
collector_type: ON_CHANGE_STREAM_ID_SYSTEM_EVENTS,
labels: Default::default(),
metadata: Some(EndpointMetadata::Switch(SwitchData {
id: Some(switch_id),
serial: "SN-SWITCH-001".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions crates/health/src/collectors/nvue/gnmi/sample_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ mod tests {
collector_type: NVUE_GNMI_SAMPLE_STREAM_ID,
metadata: None,
rack_id: None,
labels: Default::default(),
};
GnmiSampleProcessor {
data_sink: None,
Expand Down Expand Up @@ -1167,6 +1168,7 @@ mod tests {
mac: MacAddress::from_str("AA:BB:CC:DD:EE:FF").unwrap(),
},
collector_type: NVUE_GNMI_SAMPLE_STREAM_ID,
labels: Default::default(),
metadata: Some(EndpointMetadata::Switch(SwitchData {
id: Some(switch_id),
serial: "SN-SWITCH-001".to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/health/src/collectors/nvue/rest/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ mod tests {
collector_type: COLLECTOR_NAME,
metadata: None,
rack_id: None,
labels: Default::default(),
};

NvueRestCollector {
Expand Down
Loading