Documentation
¶
Overview ¶
Package rate provides an in-memory sliding window counter store for Keep's rateCount() CEL function.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a thread-safe sliding window counter store.
func NewStoreWithClock ¶
NewStoreWithClock creates a store with a custom clock for testing.
func (*Store) GC ¶
GC removes entries older than maxAge from all keys. Removes keys that become empty.
func (*Store) Increment ¶
Increment records a hit for the given key at the current time. If the store has reached maxKeys and the key is new, the increment is skipped. If a key has reached maxTimestampsPerKey, the oldest entries are trimmed.
func (*Store) OnKeyDropped ¶ added in v0.2.0
OnKeyDropped sets a callback that is invoked when a new key is dropped because the store has reached maxKeys capacity. The callback is called outside the store lock, so it is safe to perform logging or metrics collection. The callback MUST NOT call any Store methods.