From cd64b76dbad17e127ab434c56975bbd82de97a0b Mon Sep 17 00:00:00 2001 From: Diana <75819066+cloudjumpercat@users.noreply.github.com> Date: Fri, 20 Dec 2024 08:52:04 -0600 Subject: [PATCH] Fix Konnect host placeholders, add missing Konnect validate commands Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> --- ...miting-for-a-consumer-with-kong-gateway.md | 8 ++-- ...d-rate-limiting-tiers-with-kong-gateway.md | 38 +++++++++++++++++++ ...limiting-to-a-service-with-kong-gateway.md | 11 ++++++ ...tication-on-a-service-with-kong-gateway.md | 17 +++++++++ .../multiple-rate-limits-window-sizes.md | 10 +++++ .../how-tos/steps/ai-proxy-validate.md | 10 ++++- 6 files changed, 88 insertions(+), 6 deletions(-) diff --git a/app/_how-tos/add-rate-limiting-for-a-consumer-with-kong-gateway.md b/app/_how-tos/add-rate-limiting-for-a-consumer-with-kong-gateway.md index 9dd793c9..25c26391 100644 --- a/app/_how-tos/add-rate-limiting-for-a-consumer-with-kong-gateway.md +++ b/app/_how-tos/add-rate-limiting-for-a-consumer-with-kong-gateway.md @@ -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}} @@ -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 Rate Limiting plugin on the new consumer. + a: Enable an authentication plugin and create a consumer with credentials, then enable the Rate Limiting plugin on the new consumer. tools: - deck @@ -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`. diff --git a/app/_how-tos/add-rate-limiting-tiers-with-kong-gateway.md b/app/_how-tos/add-rate-limiting-tiers-with-kong-gateway.md index a858e91d..50de358e 100644 --- a/app/_how-tos/add-rate-limiting-tiers-with-kong-gateway.md +++ b/app/_how-tos/add-rate-limiting-tiers-with-kong-gateway.md @@ -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..." @@ -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..." @@ -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. diff --git a/app/_how-tos/add-rate-limiting-to-a-service-with-kong-gateway.md b/app/_how-tos/add-rate-limiting-to-a-service-with-kong-gateway.md index 72a12090..66226657 100644 --- a/app/_how-tos/add-rate-limiting-to-a-service-with-kong-gateway.md +++ b/app/_how-tos/add-rate-limiting-to-a-service-with-kong-gateway.md @@ -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 diff --git a/app/_how-tos/enable-key-authentication-on-a-service-with-kong-gateway.md b/app/_how-tos/enable-key-authentication-on-a-service-with-kong-gateway.md index 53a19b56..39e95547 100644 --- a/app/_how-tos/enable-key-authentication-on-a-service-with-kong-gateway.md +++ b/app/_how-tos/enable-key-authentication-on-a-service-with-kong-gateway.md @@ -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: @@ -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" } diff --git a/app/_how-tos/multiple-rate-limits-window-sizes.md b/app/_how-tos/multiple-rate-limits-window-sizes.md index afc607b5..634093e9 100644 --- a/app/_how-tos/multiple-rate-limits-window-sizes.md +++ b/app/_how-tos/multiple-rate-limits-window-sizes.md @@ -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 diff --git a/app/_includes/how-tos/steps/ai-proxy-validate.md b/app/_includes/how-tos/steps/ai-proxy-validate.md index 76c8860d..6f0d8009 100644 --- a/app/_includes/how-tos/steps/ai-proxy-validate.md +++ b/app/_includes/how-tos/steps/ai-proxy-validate.md @@ -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?"} ] }' -``` \ No newline at end of file +``` +{: 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" } \ No newline at end of file