From b060c093e6befcbc4302cd75438cbcbd5202a331 Mon Sep 17 00:00:00 2001 From: Ying WANG Date: Thu, 19 Dec 2024 16:23:36 +0100 Subject: [PATCH] remove unnecessary tracker nil checking --- pkg/costattribution/manager.go | 5 +++-- pkg/costattribution/tracker.go | 6 ------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/pkg/costattribution/manager.go b/pkg/costattribution/manager.go index 5c40018f538..5127e991df6 100644 --- a/pkg/costattribution/manager.go +++ b/pkg/costattribution/manager.go @@ -109,12 +109,13 @@ func (m *Manager) deleteTracker(userID string) { } func (m *Manager) updateTracker(userID string) *Tracker { - if !m.EnabledForUser(userID) { + t := m.Tracker(userID) + + if t == nil { m.deleteTracker(userID) return nil } - t := m.Tracker(userID) newTrackedLabels := m.limits.CostAttributionLabels(userID) // sort the labels to ensure the order is consistent diff --git a/pkg/costattribution/tracker.go b/pkg/costattribution/tracker.go index e07e9565b0d..d808ad654c2 100644 --- a/pkg/costattribution/tracker.go +++ b/pkg/costattribution/tracker.go @@ -104,9 +104,6 @@ func newTracker(userID string, trackedLabels []string, limit int, cooldown time. } func (t *Tracker) hasSameLabels(labels []string) bool { - if t == nil { - return len(labels) == 0 - } return slices.Equal(t.labels, labels) } @@ -117,9 +114,6 @@ var bufferPool = sync.Pool{ } func (t *Tracker) cleanupTrackerAttribution(key string) { - if t == nil { - return - } t.obseveredMtx.Lock() defer t.obseveredMtx.Unlock() delete(t.observed, key)