From f25f2469e38e7c57cd88a4e3dea8ae1d61507b99 Mon Sep 17 00:00:00 2001 From: henrygd Date: Sat, 28 Mar 2026 21:16:26 -0400 Subject: [PATCH] hub: add debug logs for smart behavior (#1800) --- internal/hub/systems/system.go | 2 ++ internal/hub/systems/system_smart.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/hub/systems/system.go b/internal/hub/systems/system.go index 5991db4b..e57b0d39 100644 --- a/internal/hub/systems/system.go +++ b/internal/hub/systems/system.go @@ -145,6 +145,7 @@ func (sys *System) update() error { // update smart interval if it's set on the agent side if data.Details.SmartInterval > 0 { sys.smartInterval = data.Details.SmartInterval + sys.manager.hub.Logger().Info("SMART interval updated from agent details", "system", sys.Id, "interval", sys.smartInterval.String()) // make sure we reset expiration of lastFetch to remain as long as the new smart interval // to prevent premature expiration leading to new fetch if interval is different. sys.manager.smartFetchMap.UpdateExpiration(sys.Id, sys.smartInterval+time.Minute) @@ -157,6 +158,7 @@ func (sys *System) update() error { sys.smartInterval = time.Hour } if sys.shouldFetchSmart() && sys.smartFetching.CompareAndSwap(false, true) { + sys.manager.hub.Logger().Info("SMART fetch", "system", sys.Id, "interval", sys.smartInterval.String()) go func() { defer sys.smartFetching.Store(false) _ = sys.FetchAndSaveSmartDevices() diff --git a/internal/hub/systems/system_smart.go b/internal/hub/systems/system_smart.go index bd6c573b..3ccbb1f1 100644 --- a/internal/hub/systems/system_smart.go +++ b/internal/hub/systems/system_smart.go @@ -28,7 +28,12 @@ func (sys *System) recordSmartFetchResult(err error, deviceCount int) { if sys.manager == nil { return } - sys.manager.smartFetchMap.Set(sys.Id, err == nil && deviceCount > 0, sys.smartFetchInterval()+time.Minute) + interval := sys.smartFetchInterval() + success := err == nil && deviceCount > 0 + if sys.manager.hub != nil { + sys.manager.hub.Logger().Info("SMART fetch result", "system", sys.Id, "success", success, "devices", deviceCount, "interval", interval.String(), "err", err) + } + sys.manager.smartFetchMap.Set(sys.Id, success, interval+time.Minute) } // shouldFetchSmart returns true when there is no active SMART cooldown entry for this system.