From 6d0df307e74eb1f52578305c3aef33e042c9e3be Mon Sep 17 00:00:00 2001 From: Zach Reyes Date: Wed, 14 Aug 2024 17:16:11 -0400 Subject: [PATCH] Fix RLS Cache metrics --- balancer/rls/cache.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/balancer/rls/cache.go b/balancer/rls/cache.go index f80750fb34e9..7fe796c9587a 100644 --- a/balancer/rls/cache.go +++ b/balancer/rls/cache.go @@ -180,7 +180,7 @@ type dataCache struct { } func newDataCache(size int64, logger *internalgrpclog.PrefixLogger, metricsRecorder estats.MetricsRecorder, grpcTarget string) *dataCache { - dc := &dataCache{ + return &dataCache{ maxSize: size, keys: newLRU(), entries: make(map[cacheKey]*cacheEntry), @@ -190,9 +190,6 @@ func newDataCache(size int64, logger *internalgrpclog.PrefixLogger, metricsRecor uuid: uuid.New().String(), metricsRecorder: metricsRecorder, } - cacheSizeMetric.Record(dc.metricsRecorder, 0, grpcTarget, "", dc.uuid) - cacheEntriesMetric.Record(dc.metricsRecorder, 0, grpcTarget, "", dc.uuid) - return dc } // updateRLSServerTarget updates the RLS Server Target the RLS Balancer is @@ -330,6 +327,8 @@ func (dc *dataCache) addEntry(key cacheKey, entry *cacheEntry) (backoffCancelled if dc.currentSize > dc.maxSize { backoffCancelled = dc.resize(dc.maxSize) } + cacheSizeMetric.Record(dc.metricsRecorder, dc.currentSize, dc.grpcTarget, dc.rlsServerTarget, dc.uuid) + cacheEntriesMetric.Record(dc.metricsRecorder, int64(len(dc.entries)), dc.grpcTarget, dc.rlsServerTarget, dc.uuid) return backoffCancelled, true }