Skip to content

Commit

Permalink
Including the name in the ratelimit descriptor so that it is returned… (
Browse files Browse the repository at this point in the history
#596)

Signed-off-by: jespersoderlund <[email protected]>
  • Loading branch information
jespersoderlund authored Jun 7, 2024
1 parent 0f73f89 commit f17d88f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/config/config_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func NewRateLimit(requestsPerUnit uint32, unit pb.RateLimitResponse_RateLimit_Un
Limit: &pb.RateLimitResponse_RateLimit{
RequestsPerUnit: requestsPerUnit,
Unit: unit,
Name: name,
},
Unlimited: unlimited,
ShadowMode: shadowMode,
Expand Down
1 change: 1 addition & 0 deletions test/config/basic_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ descriptors:

- key: key4
rate_limit:
name: key4_rate_limit
unit: day
requests_per_unit: 1

Expand Down
2 changes: 2 additions & 0 deletions test/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func TestBasicConfig(t *testing.T) {
rl.Stats.NearLimit.Inc()
rl.Stats.WithinLimit.Inc()
assert.EqualValues(1, rl.Limit.RequestsPerUnit)
assert.Empty(rl.Limit.Name, "No name provided in config")
assert.Equal(pb.RateLimitResponse_RateLimit_HOUR, rl.Limit.Unit)
assert.EqualValues(1, stats.NewCounter("test-domain.key3.total_hits").Value())
assert.EqualValues(1, stats.NewCounter("test-domain.key3.over_limit").Value())
Expand All @@ -165,6 +166,7 @@ func TestBasicConfig(t *testing.T) {
rl.Stats.NearLimit.Inc()
rl.Stats.WithinLimit.Inc()
assert.EqualValues(1, rl.Limit.RequestsPerUnit)
assert.EqualValues("key4_rate_limit", rl.Limit.Name, "Name provided in config")
assert.Equal(pb.RateLimitResponse_RateLimit_DAY, rl.Limit.Unit)
assert.EqualValues(1, stats.NewCounter("test-domain.key4.total_hits").Value())
assert.EqualValues(1, stats.NewCounter("test-domain.key4.over_limit").Value())
Expand Down
2 changes: 1 addition & 1 deletion test/service/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestService(test *testing.T) {
request = common.NewRateLimitRequest(
"different-domain", [][][2]string{{{"foo", "bar"}}, {{"hello", "world"}}}, 1)
limits := []*config.RateLimit{
config.NewRateLimit(10, pb.RateLimitResponse_RateLimit_MINUTE, t.statsManager.NewStats("key"), false, false, "", nil, false),
config.NewRateLimit(10, pb.RateLimitResponse_RateLimit_MINUTE, t.statsManager.NewStats("key"), false, false, "key_name", nil, false),
nil,
}
t.config.EXPECT().GetLimit(context.Background(), "different-domain", request.Descriptors[0]).Return(limits[0])
Expand Down

0 comments on commit f17d88f

Please sign in to comment.