diff --git a/pkg/middlewares/canary/canary.go b/pkg/middlewares/canary/canary.go index 64a341c0a1..d67e377f5b 100644 --- a/pkg/middlewares/canary/canary.go +++ b/pkg/middlewares/canary/canary.go @@ -48,7 +48,6 @@ type Canary struct { // New returns a Canary instance. func New(ctx context.Context, next http.Handler, cfg dynamic.Canary, name string) (*Canary, error) { logger := log.FromContext(middlewares.GetLoggerCtx(ctx, name, typeName)) - logger.Debug("Add canary middleware") if cfg.Product == "" { return nil, fmt.Errorf("product name required for Canary middleware") @@ -79,6 +78,7 @@ func New(ctx context.Context, next http.Handler, cfg dynamic.Canary, name string if c.loadLabels { c.ls = NewLabelStore(logger, cfg, expiration, cacheCleanDuration) } + logger.Infof("Add canary middleware: %v, %v, %v", cfg, expiration, cacheCleanDuration) return c, nil } diff --git a/pkg/middlewares/canary/label.go b/pkg/middlewares/canary/label.go index 8205b620b8..cea2e980b9 100644 --- a/pkg/middlewares/canary/label.go +++ b/pkg/middlewares/canary/label.go @@ -111,9 +111,9 @@ func (s *LabelStore) MustLoadLabels(ctx context.Context, uid, requestID string) func (s *LabelStore) mustLoadEntry(key string, now time.Time) *entry { s.mu.RLock() e, ok := s.liveMap[key] + shouldRound := len(s.liveMap) > s.maxCacheSize || s.shouldRound.Before(now) s.mu.RUnlock() - shouldRound := len(s.liveMap) > s.maxCacheSize || s.shouldRound.Before(now) if ok && !shouldRound { return e } @@ -134,8 +134,9 @@ func (s *LabelStore) mustLoadEntry(key string, now time.Time) *entry { s.liveMap[key] = e } - if shouldRound || len(s.liveMap) > s.maxCacheSize { - s.logger.Infof("Round cache, stale cache size: %d, live cache size: %d", len(s.staleMap), len(s.liveMap)) + if len(s.liveMap) > s.maxCacheSize || s.shouldRound.Before(now) { + s.logger.Infof("Round cache, stale cache size: %d, live cache size: %d, trigger: %s, shouldRound: %s", + len(s.staleMap), len(s.liveMap), key, s.shouldRound.Format(time.RFC3339)) s.shouldRound = now.Add(s.cacheCleanDuration) // make a round: drop staleMap and create new liveMap s.staleMap = s.liveMap