Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris S. Kim committed Sep 5, 2023
1 parent f3202d7 commit 19be2ce
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
2 changes: 0 additions & 2 deletions acceptance/tests/config-entries/config_entries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ func TestController(t *testing.T) {
require.Equal(r, 100.0, rateLimitIPConfigEntry.KV.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Tenancy.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Tenancy.WriteRate)
// require.Equal(r, 100.0, rateLimitIPConfigEntry.PreparedQuery.ReadRate)
// require.Equal(r, 100.0, rateLimitIPConfigEntry.PreparedQuery.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Session.ReadRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Session.WriteRate)
require.Equal(r, 100.0, rateLimitIPConfigEntry.Txn.ReadRate)
Expand Down
6 changes: 4 additions & 2 deletions acceptance/tests/fixtures/bases/crds-oss/servicedefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ spec:
requestsPerSecond: 1234
requestsMaxBurst: 2345
routes:
- pathExact: "/foo"
- pathExact: "/exact"
requestsPerSecond: 222
requestsMaxBurst: 333
- pathPrefix: "/admin"
- pathPrefix: "/prefix"
requestsPerSecond: 444
- pathRegex: "/regex"
requestsPerSecond: 555
envoyExtensions:
- name: builtin/aws/lambda
required: false
Expand Down
3 changes: 0 additions & 3 deletions charts/consul/templates/crd-servicedefaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ spec:
routes. For a given request, the first matching route will
be applied, if any. Overrides any top-level configuration.
items:
description: InstanceLevelRouteRateLimits represents rate
limit configuration applied to a route matching one of
PathExact/PathPrefix/PathRegex.
properties:
pathExact:
description: Exact path to match. Exactly one of PathExact,
Expand Down
12 changes: 5 additions & 7 deletions control-plane/api/v1alpha1/servicedefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ type ServiceDefaultsDestination struct {

// RateLimits is rate limiting configuration that is applied to
// inbound traffic for a service.
// Rate limiting is a Consul enterprise feature.
// Rate limiting is a Consul Enterprise feature.
type RateLimits struct {
// InstanceLevel represents rate limit configuration
// that is applied per service instance.
Expand Down Expand Up @@ -286,7 +286,7 @@ func (irl InstanceLevelRateLimits) validate(path *field.Path) field.ErrorList {
var allErrs field.ErrorList

// Track if RequestsPerSecond is set in at least one place in the config
isRatelimitSet := irl.RequestsPerSecond > 0
isRateLimitSet := irl.RequestsPerSecond > 0

// Top-level RequestsPerSecond can be 0 (unset) or a positive number.
if irl.RequestsPerSecond < 0 {
Expand All @@ -307,7 +307,7 @@ func (irl InstanceLevelRateLimits) validate(path *field.Path) field.ErrorList {
allErrs = append(allErrs,
field.Invalid(path.Child("requestsMaxBurst"),
irl.RequestsMaxBurst,
"RequestsMaxBurst must be greater than 0"))
"RequestsMaxBurst must be positive"))
}

for i, route := range irl.Routes {
Expand All @@ -330,20 +330,18 @@ func (irl InstanceLevelRateLimits) validate(path *field.Path) field.ErrorList {
if route.RequestsMaxBurst < 0 {
allErrs = append(allErrs, field.Invalid(
path.Child("routes").Index(i).Child("requestsMaxBurst"),
route.RequestsMaxBurst, "RequestsMaxBurst must be greater than 0"))
route.RequestsMaxBurst, "RequestsMaxBurst must be positive"))
}
}

if !isRatelimitSet {
if !isRateLimitSet {
allErrs = append(allErrs, field.Invalid(
path.Child("requestsPerSecond"),
irl.RequestsPerSecond, "At least one of top-level or route-level RequestsPerSecond must be set"))
}
return allErrs
}

// InstanceLevelRouteRateLimits represents rate limit configuration
// applied to a route matching one of PathExact/PathPrefix/PathRegex.
type InstanceLevelRouteRateLimits struct {
// Exact path to match. Exactly one of PathExact, PathPrefix, or PathRegex must be specified.
PathExact string `json:"pathExact,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions control-plane/api/v1alpha1/servicedefaults_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ func TestServiceDefaults_Validate(t *testing.T) {
},
},
},
expectedErrMsg: `servicedefaults.consul.hashicorp.com "my-service" is invalid: spec.rateLimits.instanceLevel.requestsMaxBurst: Invalid value: -1: RequestsMaxBurst must be greater than 0`,
expectedErrMsg: `servicedefaults.consul.hashicorp.com "my-service" is invalid: spec.rateLimits.instanceLevel.requestsMaxBurst: Invalid value: -1: RequestsMaxBurst must be positive`,
},
"rateLimits.instanceLevel.routes (invalid path)": {
input: &ServiceDefaults{
Expand Down Expand Up @@ -1522,7 +1522,7 @@ func TestServiceDefaults_Validate(t *testing.T) {
},
},
},
expectedErrMsg: `servicedefaults.consul.hashicorp.com "my-service" is invalid: spec.rateLimits.instanceLevel.routes[0].requestsMaxBurst: Invalid value: -1: RequestsMaxBurst must be greater than 0`,
expectedErrMsg: `servicedefaults.consul.hashicorp.com "my-service" is invalid: spec.rateLimits.instanceLevel.routes[0].requestsMaxBurst: Invalid value: -1: RequestsMaxBurst must be positive`,
},
"rateLimits.requestsMaxBurst (top-level and route-level unset)": {
input: &ServiceDefaults{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ spec:
type: string
rateLimits:
description: RateLimits is rate limiting configuration that is applied
to inbound traffic for a service. Rate limiting is a Consul Enterprise
to inbound traffic for a service. Rate limiting is a Consul enterprise
feature.
properties:
instanceLevel:
Expand All @@ -211,13 +211,13 @@ spec:
type: integer
routes:
description: Routes is a list of rate limits applied to specific
routes. Overrides any top-level configuration.
routes. For a given request, the first matching route will
be applied, if any. Overrides any top-level configuration.
items:
description: InstanceLevelRouteRateLimits represents rate
limit configuration applied to a route matching one of
PathExact/PathPrefix/PathRegex.
properties:
pathExact:
description: Exact path to match. Exactly one of PathExact,
PathPrefix, or PathRegex must be specified.
type: string
pathPrefix:
description: Prefix to match. Exactly one of PathExact,
Expand Down

0 comments on commit 19be2ce

Please sign in to comment.