Skip to content

Commit e76ed1d

Browse files
fix per-route ratelimit option (Kuadrant#93)
* fix per-route ratelimit option * add more context into the comment * update example vHost EnvoyFilter comment
1 parent 62f8261 commit e76ed1d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

controllers/apim/ratelimitpolicy_controller.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,6 @@ func routeRateLimitsPatch(vHostName string, routeName string, rateLimits []*apim
442442
"operation": "MERGE",
443443
"value": map[string]interface{}{
444444
"route": map[string]interface{}{
445-
"typed_per_filter_config": map[string]interface{}{
446-
"envoy.filters.http.ratelimit": map[string]interface{}{
447-
"@type": "type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimitPerRoute",
448-
"vh_rate_limits": "include",
449-
},
450-
},
451445
"rate_limits": common.EnvoyFilterRatelimitsUnstructured(rateLimits),
452446
},
453447
},
@@ -502,10 +496,23 @@ func virtualHostRateLimitsPatch(vHostName string, rateLimits []*apimv1alpha1.Rat
502496
// - request_headers:
503497
// header_name: ":method"
504498
// descriptor_key: "req.method"
499+
// typed_per_filter_config:
500+
// envoy.filters.http.ratelimit:
501+
// @type: "type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimitPerRoute"
502+
// vh_rate_limits: INCLUDE
505503
patchUnstructured := map[string]interface{}{
506504
"operation": "MERGE",
507505
"value": map[string]interface{}{
508506
"rate_limits": common.EnvoyFilterRatelimitsUnstructured(rateLimits),
507+
"typed_per_filter_config": map[string]interface{}{
508+
// Note the following name is different from what we have given to our pre/post-auth
509+
// ratelimit filters. It's because you refer to the type of filter and not the name field
510+
// of the filter. This infers it's configured for both filters in our case.
511+
"envoy.filters.http.ratelimit": map[string]interface{}{
512+
"@type": "type.googleapis.com/envoy.extensions.filters.http.ratelimit.v3.RateLimitPerRoute",
513+
"vh_rate_limits": "INCLUDE",
514+
},
515+
},
509516
},
510517
}
511518

0 commit comments

Comments
 (0)