Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Konnect host placeholders in how tos, add missing Konnect validate commands #186

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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" }
Loading