Skip to content

Commit 347aea6

Browse files
test and document whitelist behavior (#31)
Signed-off-by: Daniel Hochman <[email protected]>
1 parent c36cfee commit 347aea6

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@ descriptors:
9797
```
9898
9999
Each descriptor in a descriptor list must have a key. It can also optionally have a value to enable a more specific
100-
match. The "rate_limit" block is optional and if present sets up an actual rate limit rule. See below for how the rule
101-
is defined. The reason a rule might not be present is typically if a descriptor is a container for a 2nd level
102-
descriptor list. Each descriptor can optionally contain a nested descriptor list that allows for more complex matches
103-
and rate limit scenarios.
100+
match. The "rate_limit" block is optional and if present sets up an actual rate limit rule. See below for how the
101+
rule is defined. If the rate limit is not present and there are no nested descriptors, then the descriptor is
102+
effectively whitelisted. Otherwise, nested descriptors allow more complex matching and rate limiting scenarios.
104103
105104
### Rate limit definition
106105

test/config/basic_config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ descriptors:
3131
unit: minute
3232
requests_per_unit: 30
3333

34+
# First level override with no limit. This effectively whitelists the value.
35+
- key: key2
36+
value: value3
37+
3438
- key: key3
3539
rate_limit:
3640
unit: hour

test/config/config_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func TestBasicConfig(t *testing.T) {
100100
assert.EqualValues(1, stats.NewCounter("test-domain.key2_value2.over_limit").Value())
101101
assert.EqualValues(1, stats.NewCounter("test-domain.key2_value2.near_limit").Value())
102102

103+
rl = rlConfig.GetLimit(
104+
nil, "test-domain",
105+
&pb.RateLimitDescriptor{[]*pb.RateLimitDescriptor_Entry{{"key2", "value3"}}})
106+
assert.Nil(rl)
107+
103108
rl = rlConfig.GetLimit(
104109
nil, "test-domain",
105110
&pb.RateLimitDescriptor{[]*pb.RateLimitDescriptor_Entry{{"key3", "foo"}}})

0 commit comments

Comments
 (0)