diff --git a/pkg/distcache/olric-logwriter.go b/pkg/distcache/logwriter.go similarity index 100% rename from pkg/distcache/olric-logwriter.go rename to pkg/distcache/logwriter.go diff --git a/pkg/policies/dataplane/actuators/rate/rate-limiter.go b/pkg/policies/dataplane/actuators/rate/rate-limiter.go index 68ff263976..69dc1c8f0e 100644 --- a/pkg/policies/dataplane/actuators/rate/rate-limiter.go +++ b/pkg/policies/dataplane/actuators/rate/rate-limiter.go @@ -216,7 +216,7 @@ func (rateLimiter *rateLimiter) setup(lifecycle fx.Lifecycle) error { label := rateLimiter.rateLimiterProto.GetLabelKey() + ":" + override.GetLabelValue() rateLimiter.rateLimitChecker.AddOverride(label, override.GetLimitScaleFactor()) } - rateLimiter.rateTracker, err = ratetracker.NewOlricRateTracker(rateLimiter.rateLimitChecker, + rateLimiter.rateTracker, err = ratetracker.NewDistCacheRateTracker(rateLimiter.rateLimitChecker, rateLimiter.rateLimiterFactory.distCache, rateLimiter.name, rateLimiter.rateLimiterProto.GetLimitResetInterval().AsDuration()) diff --git a/pkg/policies/dataplane/actuators/rate/ratetracker/olric-rate-tracker.go b/pkg/policies/dataplane/actuators/rate/ratetracker/distcache-rate-tracker.go similarity index 57% rename from pkg/policies/dataplane/actuators/rate/ratetracker/olric-rate-tracker.go rename to pkg/policies/dataplane/actuators/rate/ratetracker/distcache-rate-tracker.go index 47ea70022f..b88519bf8c 100644 --- a/pkg/policies/dataplane/actuators/rate/ratetracker/olric-rate-tracker.go +++ b/pkg/policies/dataplane/actuators/rate/ratetracker/distcache-rate-tracker.go @@ -10,16 +10,16 @@ import ( "github.com/fluxninja/aperture/pkg/distcache" ) -// OlricRateTracker implements Limiter. -type OlricRateTracker struct { +// DistCacheRateTracker implements Limiter. +type DistCacheRateTracker struct { mu sync.RWMutex limitCheck RateLimitChecker dMap *olric.DMap name string } -// NewOlricRateTracker creates a new instance of OlricRateLimiter. -func NewOlricRateTracker(limitCheck RateLimitChecker, dc *distcache.DistCache, name string, ttl time.Duration) (RateTracker, error) { +// NewDistCacheRateTracker creates a new instance of DistCacheRateTracker. +func NewDistCacheRateTracker(limitCheck RateLimitChecker, dc *distcache.DistCache, name string, ttl time.Duration) (RateTracker, error) { dmapConfig := config.DMap{ TTLDuration: ttl, } @@ -33,7 +33,7 @@ func NewOlricRateTracker(limitCheck RateLimitChecker, dc *distcache.DistCache, n } dc.RemoveDMapCustomConfig(name) - ol := &OlricRateTracker{ + ol := &DistCacheRateTracker{ name: name, dMap: dMap, limitCheck: limitCheck, @@ -42,13 +42,13 @@ func NewOlricRateTracker(limitCheck RateLimitChecker, dc *distcache.DistCache, n return ol, nil } -// Name returns the name of the OlricRateLimiter. -func (ol *OlricRateTracker) Name() string { +// Name returns the name of the DistCacheRateTracker. +func (ol *DistCacheRateTracker) Name() string { return ol.name } -// Close cleans up DMap held within the OlricRateLimiter. -func (ol *OlricRateTracker) Close() error { +// Close cleans up DMap held within the DistCacheRateTracker. +func (ol *DistCacheRateTracker) Close() error { ol.mu.Lock() defer ol.mu.Unlock() err := ol.dMap.Destroy() @@ -59,13 +59,13 @@ func (ol *OlricRateTracker) Close() error { } // Take is a wrapper for TakeN(label, 1). -func (ol *OlricRateTracker) Take(label string) (bool, int, int) { +func (ol *DistCacheRateTracker) Take(label string) (bool, int, int) { return ol.TakeN(label, 1) } // TakeN increments value in label by n and returns whether n events should be allowed along with the remaining value (limit - new n) after increment and the current count for the label. // If an error occurred it returns true, 0 and 0 (fail open). -func (ol *OlricRateTracker) TakeN(label string, n int) (bool, int, int) { +func (ol *DistCacheRateTracker) TakeN(label string, n int) (bool, int, int) { ol.mu.RLock() defer ol.mu.RUnlock() newN, err := ol.dMap.Incr(label, n) @@ -76,10 +76,10 @@ func (ol *OlricRateTracker) TakeN(label string, n int) (bool, int, int) { return ok, remaining, newN } -// GetRateLimitChecker returns the RateLimitCheck of the OlricRateLimiter. -func (ol *OlricRateTracker) GetRateLimitChecker() RateLimitChecker { +// GetRateLimitChecker returns the RateLimitCheck of the DistCacheRateTracker. +func (ol *DistCacheRateTracker) GetRateLimitChecker() RateLimitChecker { return ol.limitCheck } -// Make sure OlricRateLimiter implements Limiter interface. -var _ RateTracker = (*OlricRateTracker)(nil) +// Make sure DistCacheRateTracker implements Limiter interface. +var _ RateTracker = (*DistCacheRateTracker)(nil) diff --git a/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go b/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go index 4853e58f05..0264bd5027 100644 --- a/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go +++ b/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go @@ -29,7 +29,7 @@ func newTestLimiter(t *testing.T, distCache *distcache.DistCache, limit int, ttl for label, limit := range overrides { limitCheck.AddOverride(label, limit) } - limiter, err := NewOlricRateTracker(limitCheck, distCache, "Limiter", ttl) + limiter, err := NewDistCacheRateTracker(limitCheck, distCache, "Limiter", ttl) if err != nil { t.Logf("Failed to create OlricLimiter: %v", err) return nil, err