diff options
Diffstat (limited to 'internal/ratelimiter/ratelimiter.go')
-rw-r--r-- | internal/ratelimiter/ratelimiter.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/internal/ratelimiter/ratelimiter.go b/internal/ratelimiter/ratelimiter.go index e1cf076d..1359b19c 100644 --- a/internal/ratelimiter/ratelimiter.go +++ b/internal/ratelimiter/ratelimiter.go @@ -36,23 +36,24 @@ type RateLimiter struct { now func() time.Time sourceIPLimitPerSecond float64 sourceIPBurstSize int + sourceIPBlockedCount *prometheus.GaugeVec sourceIPCache *lru.Cache // TODO: add domainCache https://gitlab.com/gitlab-org/gitlab-pages/-/issues/630 } // New creates a new RateLimiter with default values that can be configured via Option functions -func New(opts ...Option) *RateLimiter { +func New(blockCountMetric, cachedEntriesMetric *prometheus.GaugeVec, cacheRequestsMetric *prometheus.CounterVec, opts ...Option) *RateLimiter { rl := &RateLimiter{ now: time.Now, sourceIPLimitPerSecond: DefaultSourceIPLimitPerSecond, sourceIPBurstSize: DefaultSourceIPBurstSize, + sourceIPBlockedCount: blockCountMetric, sourceIPCache: lru.New( "source_ip", defaultSourceIPItems, defaultSourceIPExpirationInterval, - // TODO: @jaime to add proper metrics in subsequent MR - prometheus.NewGaugeVec(prometheus.GaugeOpts{}, []string{"op"}), - prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"op", "cache"}), + cachedEntriesMetric, + cacheRequestsMetric, ), } |