collector/redfish: dedupe model-only GPU rows from graphics controllers
This commit is contained in:
@@ -444,6 +444,9 @@ func (c *RedfishConnector) collectGPUs(ctx context.Context, client *http.Client,
|
||||
|
||||
gpu := parseGPU(doc, functionDocs, idx)
|
||||
idx++
|
||||
if shouldSkipGenericGPUDuplicate(out, gpu) {
|
||||
continue
|
||||
}
|
||||
|
||||
key := gpuDedupKey(gpu)
|
||||
if key == "" {
|
||||
@@ -2034,6 +2037,39 @@ func gpuDedupKey(gpu models.GPU) string {
|
||||
return firstNonEmpty(strings.TrimSpace(gpu.Slot)+"|"+strings.TrimSpace(gpu.Model), strings.TrimSpace(gpu.Slot))
|
||||
}
|
||||
|
||||
func shouldSkipGenericGPUDuplicate(existing []models.GPU, candidate models.GPU) bool {
|
||||
if len(existing) == 0 {
|
||||
return false
|
||||
}
|
||||
if normalizeRedfishIdentityField(candidate.SerialNumber) != "" || strings.TrimSpace(candidate.BDF) != "" {
|
||||
return false
|
||||
}
|
||||
slot := strings.TrimSpace(candidate.Slot)
|
||||
model := strings.TrimSpace(candidate.Model)
|
||||
if slot == "" || model == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
// Typical GraphicsControllers fallback on some BMCs reports only model/name
|
||||
// as slot and lacks stable identifiers. If we already have concrete GPUs of the
|
||||
// same model/manufacturer from PCIe inventory, this candidate is a duplicate.
|
||||
if !strings.EqualFold(slot, model) {
|
||||
return false
|
||||
}
|
||||
for _, gpu := range existing {
|
||||
if !strings.EqualFold(strings.TrimSpace(gpu.Model), model) {
|
||||
continue
|
||||
}
|
||||
if !strings.EqualFold(strings.TrimSpace(gpu.Manufacturer), strings.TrimSpace(candidate.Manufacturer)) {
|
||||
continue
|
||||
}
|
||||
if normalizeRedfishIdentityField(gpu.SerialNumber) != "" || strings.TrimSpace(gpu.BDF) != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func looksLikeGPU(doc map[string]interface{}, functionDocs []map[string]interface{}) bool {
|
||||
deviceType := strings.ToLower(asString(doc["DeviceType"]))
|
||||
if strings.Contains(deviceType, "gpu") || strings.Contains(deviceType, "graphics") || strings.Contains(deviceType, "accelerator") {
|
||||
|
||||
Reference in New Issue
Block a user