Skip to content

Commit de80e53

Browse files
committed
Add feedback
1 parent 10238bf commit de80e53

File tree

5 files changed

+37
-35
lines changed

5 files changed

+37
-35
lines changed

examples/snippets-filter/coffee-snippets-filter.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: gateway.nginx.org/v1alpha1
2+
kind: SnippetsFilter
3+
metadata:
4+
name: no-delay-rate-limiting-sf
5+
spec:
6+
snippets:
7+
- context: http
8+
value: limit_req_zone $binary_remote_addr zone=no-delay-rate-limiting-sf:10m rate=1r/s;
9+
- context: http.server.location
10+
value: limit_req zone=no-delay-rate-limiting-sf burst=3 nodelay;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: gateway.nginx.org/v1alpha1
2+
kind: SnippetsFilter
3+
metadata:
4+
name: rate-limiting-sf
5+
spec:
6+
snippets:
7+
- context: http
8+
value: limit_req_zone $binary_remote_addr zone=rate-limiting-sf:10m rate=1r/s;
9+
- context: http.server.location
10+
value: limit_req zone=rate-limiting-sf burst=3;

examples/snippets-filter/tea-snippets-filter.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

site/content/how-to/traffic-management/snippets.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ NGINX configurations that NGINX Gateway Fabric generates.
1717
Snippets are for advanced NGINX users who need more control over the generated NGINX configuration,
1818
and can be used in cases where Gateway API resources or NGINX extension policies don't apply.
1919

20-
Users can configure Snippets through the `SnippetsFilter` API. `SnippetsFilter` is an [HTTPRouteFilter](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteFilter)
21-
that attaches to an HTTP/GRPCRoute rule and is intended to modify NGINX configuration specifically for that Route rule.
20+
Users can configure Snippets through the `SnippetsFilter` API. `SnippetsFilter` can be an [HTTPRouteFilter](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.HTTPRouteFilter) or [GRPCRouteFilter](https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io/v1.GRPCRouteFilter),
21+
that can be defined in an HTTP/GRPCRoute rule and is intended to modify NGINX configuration specifically for that Route rule. `SnippetsFilter` is an `extensionRef` type filter.
2222

2323
---
2424

@@ -37,7 +37,7 @@ Snippets have the following disadvantages:
3737
- _Decreased robustness_. An incorrect Snippet can invalidate NGINX configuration, causing reload failures. Until the snippet is fixed, it will prevent any new configuration updates, including updates for the other Gateway resources.
3838
- _Security implications_. Snippets give access to NGINX configuration primitives, which are not validated by NGINX Gateway Fabric. For example, a Snippet can configure NGINX to serve the TLS certificates and keys used for TLS termination for Gateway resources.
3939

40-
{{< note >}} If the NGINX configuration includes an invalid Snippet, NGINX will continue to operate with the last valid configuration. {{< /note >}}
40+
{{< note >}} If the NGINX configuration includes an invalid Snippet, NGINX will continue to operate with the last valid configuration. No new configuration will be applied until the invalid Snippet is fixed. {{< /note >}}
4141

4242
{{< note >}} If you end up using Snippets and run into situations where an NGINX directive fails to be applied, please create an issue in the
4343
[NGINX Gateway Fabric Github repository](https://github.com/nginxinc/nginx-gateway-fabric). {{< /note >}}
@@ -127,24 +127,26 @@ kubectl apply -f - <<EOF
127127
apiVersion: gateway.nginx.org/v1alpha1
128128
kind: SnippetsFilter
129129
metadata:
130-
name: coffee-rate-limiting-sf
130+
name: no-delay-rate-limiting-sf
131131
spec:
132132
snippets:
133133
- context: http
134-
value: limit_req_zone \$binary_remote_addr zone=coffeezone:10m rate=1r/s;
134+
value: limit_req_zone \$binary_remote_addr zone=no-delay-rate-limiting-sf:10m rate=1r/s;
135135
- context: http.server.location
136-
value: limit_req zone=coffeezone burst=3 nodelay;
136+
value: limit_req zone=no-delay-rate-limiting-sf burst=3 nodelay;
137137
EOF
138138
```
139139

140-
The Snippet uses the NGINX `limit_req_module` to configure rate limiting for this HTTPRoute and the
141-
backend coffee application. This snippet will limit the request processing rate to 1 request per second, and if there
140+
This `SnippetsFilter` defines two Snippets to configure rate limiting for this HTTPRoute and the
141+
backend coffee application. The first one injects the value: `limit_req_zone \$binary_remote_addr zone=no-delay-rate-limiting-sf:10m rate=1r/s;`
142+
into the `http` context. The second one injects the value: `limit_req zone=no-delay-rate-limiting-sf burst=3 nodelay;` into the location(s) for `/coffee`.
143+
This `SnippetsFilter` will limit the request processing rate to 1 request per second, and if there
142144
are more than 3 requests in queue, it will throw a 503 error.
143145

144146
Verify that the `SnippetsFilter` is Accepted:
145147

146148
```shell
147-
kubectl describe snippetsfilters.gateway.nginx.org coffee-rate-limiting-sf
149+
kubectl describe snippetsfilters.gateway.nginx.org no-delay-rate-limiting-sf
148150
```
149151

150152
You should see the following status:
@@ -187,7 +189,7 @@ spec:
187189
extensionRef:
188190
group: gateway.nginx.org
189191
kind: SnippetsFilter
190-
name: coffee-rate-limiting-sf
192+
name: no-delay-rate-limiting-sf
191193
backendRefs:
192194
- name: coffee
193195
port: 80
@@ -265,13 +267,13 @@ kubectl apply -f - <<EOF
265267
apiVersion: gateway.nginx.org/v1alpha1
266268
kind: SnippetsFilter
267269
metadata:
268-
name: tea-rate-limiting-sf
270+
name: rate-limiting-sf
269271
spec:
270272
snippets:
271273
- context: http
272-
value: limit_req_zone \$binary_remote_addr zone=teazone:10m rate=1r/s;
274+
value: limit_req_zone \$binary_remote_addr zone=rate-limiting-sf:10m rate=1r/s;
273275
- context: http.server.location
274-
value: limit_req zone=teazone burst=3;
276+
value: limit_req zone=rate-limiting-sf burst=3;
275277
EOF
276278
```
277279

@@ -281,7 +283,7 @@ on the `limit_req` directive. This forces a delay on the incoming requests to ma
281283
Verify that the `SnippetsFilter` is Accepted:
282284

283285
```shell
284-
kubectl describe snippetsfilters.gateway.nginx.org tea-rate-limiting-sf
286+
kubectl describe snippetsfilters.gateway.nginx.org rate-limiting-sf
285287
```
286288

287289
You should see the following status:
@@ -324,7 +326,7 @@ spec:
324326
extensionRef:
325327
group: gateway.nginx.org
326328
kind: SnippetsFilter
327-
name: tea-rate-limiting-sf
329+
name: rate-limiting-sf
328330
backendRefs:
329331
- name: tea
330332
port: 80

0 commit comments

Comments
 (0)