Documentation
¶
Overview ¶
Package eprefusal counts the requests an endpoint refused before its handler ran (#2208): at the bot check, a rate limit, the body limit, the caller's credential, or a cross-origin preflight from an origin the binding does not list. An answered request is audited; a refused one was not, so a flood refused at the bot check, which is what an administrator looks for on a public endpoint, showed nowhere.
A replica counts in memory and adds its counts to the database every few seconds, one row per endpoint, hour and reason: a flood moves a counter rather than writing a row per request, so counting refusals does not make refusing them cost more.
Index ¶
Constants ¶
const ( ReasonBotCheck = "bot_check" ReasonRateLimit = "rate_limit" ReasonCallerRateLimit = "caller_rate_limit" ReasonBodyLimit = "body_limit" ReasonCredential = "credential" ReasonOrigin = "origin" )
The reasons a request is refused before its handler runs.
const DefaultFlush = 10 * time.Second
DefaultFlush is how often a replica adds its counts.
const Retention = 30 * 24 * time.Hour
Retention is how long the counts are kept.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Count ¶
type Count struct {
EndpointID string `json:"-"`
Hour time.Time `json:"hour"`
Reason string `json:"reason"`
Count int64 `json:"count"`
}
Count is how many requests to one endpoint were refused for one reason in one hour.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter counts this replica's refusals in memory and adds them to the store on its loop.
func NewCounter ¶
NewCounter counts into store, adding every flush (DefaultFlush when zero).
func (*Counter) Flush ¶
Flush adds what has been counted since the last flush. A batch the store refuses is put back, to be added on the next flush.
func (*Counter) Refused ¶
Refused counts one refused request. Nil-safe, and never blocks on the database.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps the counts.