Skip to content

Commit f3c7308

Browse files
authored
Tiered Rate limit group maps (#7390)
1 parent ee2e225 commit f3c7308

File tree

3 files changed

+2056
-71
lines changed

3 files changed

+2056
-71
lines changed

internal/configs/version2/http.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package version2
22

3-
import "fmt"
3+
import (
4+
"bytes"
5+
"fmt"
6+
)
47

58
// UpstreamLabels describes the Prometheus labels for an NGINX upstream.
69
type UpstreamLabels struct {
@@ -340,6 +343,16 @@ type Map struct {
340343
Parameters []Parameter
341344
}
342345

346+
func (m *Map) String() string {
347+
buf := &bytes.Buffer{}
348+
fmt.Fprintf(buf, "Source: %s\n", m.Source)
349+
fmt.Fprintf(buf, "Variable: %s\n", m.Variable)
350+
for _, v := range m.Parameters {
351+
fmt.Fprintf(buf, "\t%s: %s\n", v.Value, v.Result)
352+
}
353+
return buf.String()
354+
}
355+
343356
// Parameter defines a Parameter in a Map.
344357
type Parameter struct {
345358
Value string
@@ -360,14 +373,31 @@ type Queue struct {
360373

361374
// LimitReqZone defines a rate limit shared memory zone.
362375
type LimitReqZone struct {
363-
Key string
364-
ZoneName string
365-
ZoneSize string
366-
Rate string
376+
Key string
377+
ZoneName string
378+
ZoneSize string
379+
Rate string
380+
GroupValue string
381+
GroupVariable string
382+
PolicyValue string
383+
PolicyResult string
384+
GroupDefault bool
385+
GroupSource string
367386
}
368387

369388
func (rlz LimitReqZone) String() string {
370-
return fmt.Sprintf("{Key %q, ZoneName %q, ZoneSize %v, Rate %q}", rlz.Key, rlz.ZoneName, rlz.ZoneSize, rlz.Rate)
389+
return fmt.Sprintf("{Key %q, ZoneName %q, ZoneSize %v, Rate %q, GroupValue %q, PolicyValue %q, GroupVariable %q, PolicyResult %q, GroupDefault %t, GroupSource %q}",
390+
rlz.Key,
391+
rlz.ZoneName,
392+
rlz.ZoneSize,
393+
rlz.Rate,
394+
rlz.GroupValue,
395+
rlz.PolicyValue,
396+
rlz.GroupVariable,
397+
rlz.PolicyResult,
398+
rlz.GroupDefault,
399+
rlz.GroupSource,
400+
)
371401
}
372402

373403
// LimitReq defines a rate limit.

0 commit comments

Comments
 (0)