From 2fdc051c11ee5beafc151ca7beea95a0ec3ef619 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 1 Dec 2025 20:03:05 +0000 Subject: [PATCH] fix: Make parseNVMeTemps deterministic by checking Composite before Sensor 1 Go map iteration order is non-deterministic, causing flaky test failures. This fix ensures "Composite" sensor is always preferred over "Sensor 1" by checking them in separate loops rather than relying on iteration order. --- internal/monitoring/temperature.go | 36 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/internal/monitoring/temperature.go b/internal/monitoring/temperature.go index 340ff38..7a2242a 100644 --- a/internal/monitoring/temperature.go +++ b/internal/monitoring/temperature.go @@ -675,21 +675,39 @@ func (tc *TemperatureCollector) parseNVMeTemps(chipName string, chipMap map[stri // Extract device name from chip name (e.g., "nvme-pci-0400" -> "nvme0") device := "nvme" + strings.TrimPrefix(chipName, "nvme-pci-") + // Try "Composite" first (preferred sensor name for NVMe temps) for sensorName, sensorData := range chipMap { + if !strings.Contains(sensorName, "Composite") { + continue + } sensorMap, ok := sensorData.(map[string]interface{}) if !ok { continue } + if tempVal := extractTempInput(sensorMap); !math.IsNaN(tempVal) && tempVal > 0 { + temp.NVMe = append(temp.NVMe, models.NVMeTemp{ + Device: device, + Temp: tempVal, + }) + return + } + } - // Look for Composite temperature (main NVMe temp) - if strings.Contains(sensorName, "Composite") || strings.Contains(sensorName, "Sensor 1") { - if tempVal := extractTempInput(sensorMap); !math.IsNaN(tempVal) && tempVal > 0 { - temp.NVMe = append(temp.NVMe, models.NVMeTemp{ - Device: device, - Temp: tempVal, - }) - break // Only one temp per NVMe device - } + // Fall back to "Sensor 1" if no valid Composite found + for sensorName, sensorData := range chipMap { + if !strings.Contains(sensorName, "Sensor 1") { + continue + } + sensorMap, ok := sensorData.(map[string]interface{}) + if !ok { + continue + } + if tempVal := extractTempInput(sensorMap); !math.IsNaN(tempVal) && tempVal > 0 { + temp.NVMe = append(temp.NVMe, models.NVMeTemp{ + Device: device, + Temp: tempVal, + }) + return } } }