Skip to content

Commit 5f159e5

Browse files
committed
Add docs suggestions
1 parent f0654b3 commit 5f159e5

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

examples/snippets-filter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SnippetsFilter
22

3-
This directory contains the YAML files used in the [SnippetsFilter](https://docs.nginx.com/nginx-gateway-fabric/how-to/traffic-management/snippets-filters/) guide.
3+
This directory contains the YAML files used in the [Use the SnippetsFilter API](https://docs.nginx.com/nginx-gateway-fabric/how-to/traffic-management/snippets-filters/) guide.

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

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
---
2-
title: "Snippets Filters"
2+
title: "Use the SnippetsFilter API"
33
weight: 800
44
toc: true
55
docs: "DOCS-000"
66
---
77

8-
Learn how to use Snippets with the `SnippetsFilter` API.
8+
This topic introduces Snippets and how to implement them using the `SnippetsFilter` API. It provides an example of how to use a Snippet for rate limiting, and how to investigate errors caused by misconfiguration.
9+
10+
---
911

1012
## Overview
1113

@@ -15,6 +17,8 @@ NGINX configurations that NGINX Gateway Fabric generates.
1517
Snippets are for advanced NGINX users who need more control over the generated NGINX configuration,
1618
and can be used in cases where Gateway API resources or NGINX extensions don't apply.
1719

20+
---
21+
1822
## Disadvantages of Snippets
1923

2024
Snippets are configured using the `SnippetsFilter` API, but are disabled by default due to their complexity and security implications.
@@ -23,11 +27,11 @@ To use Snippets, set the `nginxGateway.snippetsFilters.enable` command line argu
2327

2428
Snippets have the following disadvantages:
2529

26-
- *Complexity*. Snippets require you to:
27-
- Understand NGINX Configuration primitives and implement a correct NGINX configuration.
30+
- _Complexity_. Snippets require you to:
31+
- Understand NGINX configuration primitives to implement correct NGINX configuration.
2832
- Understand how NGINX Gateway Fabric generates NGINX configuration so that a Snippet doesn’t interfere with the other features in the configuration.
29-
- *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.
30-
- *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.
33+
- _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.
34+
- _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.
3135

3236
{{< note >}} If the NGINX configuration includes an invalid Snippet, NGINX will continue to operate with the last valid configuration. {{< /note >}}
3337

@@ -47,7 +51,7 @@ Due to the described disadvantages of Snippets, we recommend exhausting all othe
4751
GW_PORT=<port number>
4852
```
4953

50-
{{< note >}}In a production environment, you should have a DNS record for the external IP address that is exposed, and it should refer to the hostname that the gateway will forward for.{{< /note >}}
54+
{{< note >}} In a production environment, you should have a DNS record for the external IP address that is exposed, and it should refer to the hostname that the gateway will forward for. {{< /note >}}
5155

5256
- Create the coffee and tea example applications:
5357

@@ -77,7 +81,7 @@ Due to the described disadvantages of Snippets, we recommend exhausting all othe
7781
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee
7882
```
7983

80-
Send a request to tea
84+
Send a request to tea:
8185

8286
```shell
8387
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/tea
@@ -95,7 +99,7 @@ Due to the described disadvantages of Snippets, we recommend exhausting all othe
9599
</html>
96100
```
97101

98-
Lets check out our HTTPRoutes to see what's causing this error:
102+
Use `kubectl describe` to investigate HTTPRoutes for the error:
99103

100104
```shell
101105
kubectl describe httproutes.gateway.networking.k8s.io
@@ -135,13 +139,15 @@ Due to the described disadvantages of Snippets, we recommend exhausting all othe
135139
Type: ResolvedRefs
136140
```
137141

138-
This is because in the HTTPRoutes we created earlier, they both reference `SnippetsFilter` resources that do not currently
139-
exist, and thus a 500 error code response will be returned on requests that are processed by these HTTPRoutes.
140-
We will solve this in the next section when we add SnippetsFilters.
142+
The HTTPRoutes created earlier both reference `SnippetsFilter` resources that do not currently
143+
exist, creating a 500 error code response returned on requests that are processed by these HTTPRoutes.
144+
This issue will be resolved using SnippetsFilters.
145+
146+
---
141147

142148
## Configure rate limiting to the coffee application
143149

144-
Lets configure rate limiting to our coffee application by adding the following `SnippetsFilter`:
150+
Configure rate limiting to the coffee application by adding the following `SnippetsFilter`:
145151

146152
```yaml
147153
kubectl apply -f - <<EOF
@@ -158,7 +164,7 @@ spec:
158164
EOF
159165
```
160166

161-
This `SnippetsFilter` is already referenced by the HTTPRoute we created in the setup, so it will immediately apply
167+
This `SnippetsFilter` is already referenced by the HTTPRoute created during setup, so it will immediately apply
162168
to the HTTPRoute. The Snippet uses the NGINX `limit_req_module` to configure rate limiting for this HTTPRoute and the
163169
backend coffee application. This snippet will limit the request processing rate to 1 request per second, and if there
164170
are more than 3 requests in queue, it will throw a 503 error.
@@ -209,7 +215,7 @@ Conditions:
209215
Type: ResolvedRefs
210216
```
211217

212-
Next, test that the `SnippetsFilter` is configured and has successfully applied the rate limiting NGINX configuration changes.
218+
Test that the `SnippetsFilter` is configured and has successfully applied the rate limiting NGINX configuration changes.
213219

214220
Send a request to coffee:
215221

@@ -224,14 +230,14 @@ Server address: 10.244.0.9:8080
224230
Server name: coffee-76c7c85bbd-cf8nz
225231
```
226232

227-
When processing a single request, the rate limiting configuration has no noticeable effect. Now lets try to exceed the
228-
set rate limit by using a simple script to send multiple requests.
233+
When processing a single request, the rate limiting configuration has no noticeable effect. Try to exceed the
234+
set rate limit with a script that sends multiple requests.
229235

230236
```shell
231237
for i in `seq 1 10`; do curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee; done
232238
```
233239

234-
You should see some successful responses from the coffee Pod, however you should see multiple responses like the following:
240+
You should see some successful responses from the coffee Pod, however there should be multiple `503` responses such as:
235241

236242
```text
237243
Request ID: 890c17df930ef1ef573feed3c6e81290
@@ -249,7 +255,7 @@ correctly applied our rate limiting NGINX configuration changes.
249255

250256
## Configure rate limiting to the tea application
251257

252-
Now, lets configure a different set of rate limiting rules to our tea application by adding the following `SnippetsFilter`:
258+
Configure a different set of rate limiting rules to the tea application by adding the following `SnippetsFilter`:
253259

254260
```yaml
255261
kubectl apply -f - <<EOF
@@ -315,7 +321,7 @@ Conditions:
315321
Type: ResolvedRefs
316322
```
317323

318-
Next, test that the `SnippetsFilter` is configured and has successfully applied the rate limiting NGINX configuration changes.
324+
Test that the `SnippetsFilter` is configured and has successfully applied the rate limiting NGINX configuration changes.
319325

320326
Send a request to tea:
321327

@@ -330,15 +336,17 @@ Server address: 10.244.0.7:8080
330336
Server name: tea-76c7c85bbd-cf8nz
331337
```
332338

333-
When processing a single request, the rate limiting configuration has no noticeable effect. Now, lets try sending
339+
When processing a single request, the rate limiting configuration has no noticeable effect. Try sending
334340
multiple requests.
335341

336342
```shell
337343
for i in `seq 1 10`; do curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/tea; done
338344
```
339345

340346
You should see all successful responses from the tea Pod, but they should be spaced apart roughly one second each as
341-
expected through our rate limiting configuration.
347+
expected through the rate limiting configuration.
348+
349+
---
342350

343351
## Further reading
344352

0 commit comments

Comments
 (0)