From d689096f770cb573cb3d826e579ed66da8e9a02b Mon Sep 17 00:00:00 2001 From: Vadym Fedorov Date: Wed, 24 Apr 2024 16:21:21 -0500 Subject: [PATCH] Simplified XID Error code mapping logic Signed-off-by: Vadym Fedorov --- pkg/dcgmexporter/gpu_collector.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/dcgmexporter/gpu_collector.go b/pkg/dcgmexporter/gpu_collector.go index 82335ccb..c63f484e 100644 --- a/pkg/dcgmexporter/gpu_collector.go +++ b/pkg/dcgmexporter/gpu_collector.go @@ -288,9 +288,10 @@ func ToMetric( attrs := map[string]string{} if counter.FieldID == dcgm.DCGM_FI_DEV_XID_ERRORS { - attrs["err_code"] = strconv.Itoa(int(val.Int64())) - if v := int(val.Int64()); 0 < v && v < len(xidErrCodeToText) && xidErrCodeToText[v] != "" { - attrs["err_msg"] = xidErrCodeToText[val.Int64()] + errCode := int(val.Int64()) + attrs["err_code"] = strconv.Itoa(errCode) + if 0 < errCode && errCode < len(xidErrCodeToText) { + attrs["err_msg"] = xidErrCodeToText[errCode] } else { attrs["err_msg"] = "Unknown Error" }