Modulecompute-sdk-go v1.11.0

github.com/fastly/compute-sdk-go/erl

Package erl provides Edge Rate Limiting functionality.

This package includes a RateCounter type that can be used to increment an event counter, and to examine the rate of events per second within a POP over 1, 10, and 60 second windows. It can also estimate the number of events seen over the past minute within a POP in 10 second buckets.

The PenaltyBox type can be used to track entries that should be penalized for a certain amount of time.

The RateLimiter type combines a rate counter and a penalty box to determine whether a given entry should be rate limited based on whether it exceeds a maximum threshold of events per second over a given rate window. Most users can simply use RateLimiter.CheckRate rather than methods on RateCounter and PenaltyBox.

Rate counters and penalty boxes are combined and synchronized within a POP. However, Edge Rate Limiting is not intended to compute counts or rates with high precision and may under count by up to 10%.

Both rate counters and penalty boxes have a fixed capacity for entries. Once a rate counter is full, each new entry evicts the entry that was least recently incremented. Once a penalty box is full, each new entry will evict the entry with the shortest remaining time-to-live (TTL).

Structs

PenaltyBoxPenaltyBox is a type that allows entries to be penalized for a given number of minutes in the future.
PolicyPolicy contains the rules for applying a RateLimiter.
RateCounterRateCounter is a named counter that can be incremented and queried.
RateLimiterRateLimiter combines a RateCounter and a PenaltyBox to provide an easy way to check whether a given entry should be rate limited given a rate window and upper limit.

Type aliases

CounterDurationCounterDuration indicates the estimated number of events in this duration in the current POP. Counts are divided into 10 second buckets, and each bucket represents the estimated number of requests received up to and including that 10 second window.
RateWindowRateWindow indicates the rate of events per second in the current POP over one of a few predefined time windows. See [RateWindow1s], [RateWindow10s], and [RateWindow60s].

Functions

NewRateLimiterNewRateLimiter creates a new rate limiter.
OpenPenaltyBoxOpenPenaltyBox opens a penalty box with the given name, creating it if it doesn't already exist. The penalty box name may be up to 64 characters long. Entry names in this penalty box are also limited to 64 characters.
OpenRateCounterOpenRateCounter opens a rate counter with the given name, creating it if it doesn't already exist. The rate counter name may be up to 64 characters long. Entry names in this counter are also limited to 64 characters.

Variables

CounterDuration10s

fastly.CounterDurationView source

Default: fastly.CounterDuration10s

CounterDuration10s indicates the estimated number of events in the most recent 10 second bucket.

CounterDuration20s

fastly.CounterDurationView source

Default: fastly.CounterDuration20s

CounterDuration20s indicates the estimated number of events in the most recent two 10 second buckets.

CounterDuration30s

fastly.CounterDurationView source

Default: fastly.CounterDuration30s

CounterDuration30s indicates the estimated number of events in the most recent three 10 second buckets.

CounterDuration40s

fastly.CounterDurationView source

Default: fastly.CounterDuration40s

CounterDuration40s indicates the estimated number of events in the most recent four 10 second buckets.

CounterDuration50s

fastly.CounterDurationView source

Default: fastly.CounterDuration50s

CounterDuration50s indicates the estimated number of events in the most recent five 10 second buckets.

CounterDuration60s

fastly.CounterDurationView source

Default: fastly.CounterDuration60s

CounterDuration60s indicates the estimated number of events in the most recent six 10 second buckets.

ErrInvalidArgument

errorView source

Default: errors.New("invalid argument")

ErrInvalidArgument indicates that an invalid argument was passed to one of the edge rate limiter methods.

Most functions and methods have limited ranges for their parameters. See the documentation for each call for more details.

ErrUnexpected

errorView source

Default: errors.New("unexpected error")

ErrUnexpected indicates that an unexpected error occurred.

RateWindow10s

fastly.RateWindowView source

Default: fastly.RateWindow10s

RateWindow10s indicates the rate of events per second over the past 10 seconds.

RateWindow1s

fastly.RateWindowView source

Default: fastly.RateWindow1s

RateWindow1s incidates the rate of events per second over the past second.

RateWindow60s

fastly.RateWindowView source

Default: fastly.RateWindow60s

RateWindow60s indicates the rate of events per second over the past 60 seconds.