From 5d2eca3660252d8fb56c0706e7e8c6919b1ad0b3 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 2 Dec 2025 15:37:48 +0000 Subject: [PATCH] perf: Cache err.Error() in disk monitoring error handling Compute err.Error() once and reuse errStr instead of calling Error() four times when checking disk monitoring error types. --- internal/monitoring/monitor.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go index 0b1dee1..f944be9 100644 --- a/internal/monitoring/monitor.go +++ b/internal/monitoring/monitor.go @@ -4727,12 +4727,13 @@ func (m *Monitor) pollPVEInstance(ctx context.Context, instanceName string, clie disks, err := client.GetDisks(ctx, node.Node) if err != nil { // Check if it's a permission error or if the endpoint doesn't exist - if strings.Contains(err.Error(), "401") || strings.Contains(err.Error(), "403") { + errStr := err.Error() + if strings.Contains(errStr, "401") || strings.Contains(errStr, "403") { log.Warn(). Str("node", node.Node). Err(err). Msg("Insufficient permissions to access disk information - check API token permissions") - } else if strings.Contains(err.Error(), "404") || strings.Contains(err.Error(), "501") { + } else if strings.Contains(errStr, "404") || strings.Contains(errStr, "501") { log.Info(). Str("node", node.Node). Msg("Disk monitoring not available on this node (may be using non-standard storage)")