Skip to content

Commit

Permalink
Fix Konnect host placeholders, add missing Konnect validate commands
Browse files Browse the repository at this point in the history
Signed-off-by: Diana <[email protected]>
  • Loading branch information
cloudjumpercat committed Dec 20, 2024
1 parent 0d72f56 commit cd64b76
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Enable rate limiting for a consumer with {{site.base_gateway}}
title: Rate limit a consumer with {{site.base_gateway}}
content_type: how_to
related_resources:
- text: How to create rate limiting tiers with {{site.base_gateway}}
Expand Down Expand Up @@ -33,7 +33,7 @@ tags:

tldr:
q: How do I rate limit a consumer with {{site.base_gateway}}?
a: Enable an authentication plugin and create a consumer with credentials, then enable the <a href="/plugins/rate-limiting/reference/">Rate Limiting plugin</a> on the new consumer.
a: Enable an authentication plugin and create a consumer with credentials, then enable the <a href="/plugins/rate-limiting/">Rate Limiting plugin</a> on the new consumer.

tools:
- deck
Expand Down Expand Up @@ -116,10 +116,8 @@ for _ in {1..6}; do curl -i http://localhost:8000/anything -H 'apikey:example-ke
{: data-deployment-topology="on-prem" }

```bash
for _ in {1..6}; do curl -i http://{host}/anything -H 'apikey:example-key'; echo; done
for _ in {1..6}; do curl -i $KONNECT_PROXY_URL/anything -H 'apikey:example-key'; echo; done
```
{: data-deployment-topology="konnect" }
Replace `{host}` with the proxy URL for this data plane node.
{: data-deployment-topology="konnect" }

This command sends six consecutive requests to the route. On the last one you should get a `429` error with the message `API rate limit exceeded`.
38 changes: 38 additions & 0 deletions app/_how-tos/add-rate-limiting-tiers-with-kong-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,23 @@ for i in {1..6}; do
sleep 1
done
```
{: data-deployment-topology="on-prem" }

```sh
echo "Testing Free Tier Rate Limit..."

for i in {1..6}; do
curl -I $KONNECT_PROXY_URL/anything -H 'apikey:amal'
echo
sleep 1
done
```
{: data-deployment-topology="konnect" }

For the first few requests (up to the configured limit, which is 3 requests in 30 seconds), you should receive a `200 OK` status code. Once the limit is exceeded, you should receive a `429 Too Many Requests` status code with a message indicating the rate limit has been exceeded.

Test the rate limiting of the Basic tier:

```sh
echo "Testing Basic Tier Rate Limit..."

Expand All @@ -191,10 +204,23 @@ for i in {1..7}; do
sleep 1
done
```
{: data-deployment-topology="on-prem" }

```sh
echo "Testing Basic Tier Rate Limit..."

for i in {1..7}; do
curl -I $KONNECT_PROXY_URL/anything -H 'apikey:dana'
echo
sleep 1
done
```
{: data-deployment-topology="konnect" }

For the first few requests (up to the configured limit, which is 5 requests in 30 seconds), you should receive a `200 OK` status code. After exceeding the limit, you should receive a `429 Too Many Requests` status code with a rate limit exceeded message.

Test the rate limiting of the Premium tier:

```sh
echo "Testing Premium Tier Rate Limit..."

Expand All @@ -204,6 +230,18 @@ for i in {1..11}; do
sleep 1
done
```
{: data-deployment-topology="on-prem" }

```sh
echo "Testing Premium Tier Rate Limit..."

for i in {1..11}; do
curl -I $KONNECT_PROXY_URL/anything -H 'apikey:mahan'
echo
sleep 1
done
```
{: data-deployment-topology="konnect" }

For the initial requests (up to the configured limit, which is 500 requests in 30 seconds), you should receive a `200 OK` status code. After exceeding the limit, you should receive a `429 Too Many Requests` status code.

Expand Down
11 changes: 11 additions & 0 deletions app/_how-tos/add-rate-limiting-to-a-service-with-kong-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,23 @@ entities:
## 2. Validate

After configuring the Rate Limiting plugin, you can verify that it was configured correctly and is working, by sending more requests than allowed in the configured time limit.

```bash
for _ in {1..6}
do
curl http://localhost:8000/example-route/anything/
done
```
{: data-deployment-topology="on-prem" }

```bash
for _ in {1..6}
do
curl $KONNECT_PROXY_URL/example-route/anything/
done
```
{: data-deployment-topology="konnect" }

After the 5th request, you should receive the following `429` error:

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,20 @@ entities:
After configuring the Key Authentication plugin, you can verify that it was configured correctly and is working, by sending requests with and without the API key you created for your consumer.

This request should be successful:

```bash
curl --request GET \
--url http://localhost:8000/example-route/anything \
--header 'apikey: hello_world'
```
{: data-deployment-topology="on-prem" }

```bash
curl --request GET \
--url $KONNECT_PROXY_URL/example-route/anything \
--header 'apikey: hello_world'
```
{: data-deployment-topology="konnect" }

This request should return a `401 Unauthorized` error:

Expand All @@ -84,3 +93,11 @@ curl --request GET \
--url http://localhost:8000/example-route/anything \
--header 'apikey: another_key'
```
{: data-deployment-topology="on-prem" }

```bash
curl --request GET \
--url $KONNECT_PROXY_URL/example-route/anything \
--header 'apikey: another_key'
```
{: data-deployment-topology="konnect" }
10 changes: 10 additions & 0 deletions app/_how-tos/multiple-rate-limits-window-sizes.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ do
curl http://localhost:8000/example-route/anything/
done
```
{: data-deployment-topology="on-prem" }

```bash
for _ in {1..11}
do
curl $KONNECT_PROXY_URL/example-route/anything/
done
```
{: data-deployment-topology="konnect" }

After the 11th request in a minute, you should receive the following `429` error:

```bash
Expand Down
10 changes: 9 additions & 1 deletion app/_includes/how-tos/steps/ai-proxy-validate.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ Send a request to the route to validate.
curl -X POST http://localhost:8000/anything \
-H 'Content-Type: application/json' \
--data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }'
```
```
{: data-deployment-topology="on-prem" }

```sh
curl -X POST $KONNECT_PROXY_URL/anything \
-H 'Content-Type: application/json' \
--data-raw '{ "messages": [ { "role": "system", "content": "You are a mathematician" }, { "role": "user", "content": "What is 1+1?"} ] }'
```
{: data-deployment-topology="konnect" }

0 comments on commit cd64b76

Please sign in to comment.