Give ban causes, limit kinds, alert events, actions and dispositions named types (closes #428)
check / check (push) Failing after 2m34s
check / check (push) Failing after 2m34s
Each fixed set of string constants becomes a named string type in the package that owns it, and the fields and parameters that carry it use the type: bans.Cause, ratelimit.LimitKind, alerts.Event, alerts.DestinationName, rules.Action, requestlog.Action, requestlog.Offence, requestlog.WAFLineKind and waf.Disposition. Every value keeps its string, so the logs, state files, alerts and metrics do not change. The switches exhaustive now checks list their missing cases. Model: opus-5-5
This commit is contained in:
1 parent
433d5cc0a9
commit
93697c452f
41 files changed
+358
-248
No files matched your search
@@ -19,15 +19,19 @@ import (
|
||||
|
||||
const day = 24 * time.Hour
|
||||
|
||||
// LimitKind is what a limit counts: KindRequests, KindBytes or
|
||||
// KindRefusals.
|
||||
type LimitKind string
|
||||
|
||||
// The kinds of limits, as the metrics name them.
|
||||
const (
|
||||
// KindRequests is a rate limit, on a client's requests.
|
||||
KindRequests = "requests"
|
||||
KindRequests LimitKind = "requests"
|
||||
// KindBytes is a byte limit, on a client's bytes.
|
||||
KindBytes = "bytes"
|
||||
KindBytes LimitKind = "bytes"
|
||||
// KindRefusals is the refusal limit, on a client's requests sww
|
||||
// refused after a rule file match or for a missing or wrong token.
|
||||
KindRefusals = "refusals"
|
||||
KindRefusals LimitKind = "refusals"
|
||||
)
|
||||
|
||||
// Limits are the most requests a client may make in a minute, an hour and
|
||||
@@ -188,9 +192,7 @@ func New(limits Limits, maxClients int) *Limiter {
|
||||
// Hit is a request that takes a client over a rate limit or the refusal
|
||||
// limit, or whose bytes take it over a byte limit.
|
||||
type Hit struct {
|
||||
// Kind is KindRequests for a rate limit, KindBytes for a byte limit,
|
||||
// KindRefusals for the refusal limit.
|
||||
Kind string
|
||||
Kind LimitKind
|
||||
// Window is "minute", "hour" or "day".
|
||||
Window string
|
||||
// Limit is the window's limit, as the client's percentage of it.
|
||||
|
||||
@@ -628,7 +628,7 @@ func wantBytesCount(
|
||||
client netip.Prefix,
|
||||
now time.Time,
|
||||
bytes int64,
|
||||
want string,
|
||||
want ratelimit.LimitKind,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in new issue
Block a user