Skip to content

Commit

Permalink
Copyedit Gateway how tos and any how to includes (#188)
Browse files Browse the repository at this point in the history
Signed-off-by: Diana <[email protected]>
Co-authored-by: Angel <[email protected]>
  • Loading branch information
cloudjumpercat and Guaris authored Dec 20, 2024
1 parent 07768f9 commit 01aa1e5
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 65 deletions.
24 changes: 13 additions & 11 deletions app/_how-tos/add-rate-limiting-for-a-consumer-with-kong-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: Rate limit a consumer with {{site.base_gateway}}
content_type: how_to
related_resources:
- text: Rate Limiting
url: /rate-limiting/
- text: How to create rate limiting tiers with {{site.base_gateway}}
url: /how-to/add-rate-limiting-tiers-with-kong-gateway/
- text: Rate Limiting plugin
Expand Down Expand Up @@ -32,8 +34,8 @@ tags:
- rate-limiting

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

tools:
- deck
Expand All @@ -55,12 +57,12 @@ cleanup:
icon_url: /assets/icons/gateway.svg
---

## 1. Create a consumer
## 1. Create a Consumer

Consumers let you identify the client that's interacting with {{site.base_gateway}}.
We're going to use key [authentication](/authentication/) in this tutorial, so the consumer needs an API key to access any {{site.base_gateway}} services.
[Consumers](/gateway/entities/consumer/) let you identify the client that's interacting with {{site.base_gateway}}.
We're going to use key [authentication](/authentication/) in this tutorial, so the Consumer needs an API key to access any {{site.base_gateway}} Services.

Add the following content to `kong.yaml` to create a consumer:
Add the following content to `kong.yaml` to create a Consumer:

{% entity_examples %}
entities:
Expand All @@ -72,10 +74,10 @@ entities:

## 2. Enable authentication

Authentication lets you identify a consumer so that you can apply rate limiting.
Authentication lets you identify a Consumer so that you can apply rate limiting.
This example uses the [Key Authentication](/plugins/key-auth) plugin, but you can use any authentication plugin that you prefer.

Enable the plugin globally, which means it applies to all {{site.base_gateway}} services and routes:
Enable the plugin globally, which means it applies to all {{site.base_gateway}} Services and Routes:

{% entity_examples %}
entities:
Expand All @@ -88,7 +90,7 @@ entities:

## 3. Enable rate limiting

Enable the [Rate Limiting plugin](/plugins/rate-limiting/) for the consumer.
Enable the [Rate Limiting plugin](/plugins/rate-limiting/) for the Consumer.
In this example, the limit is 5 requests per minute and 1000 requests per hour.

{% entity_examples %}
Expand All @@ -108,7 +110,7 @@ append_to_existing_section: true

## 5. Validate

You can run the following command to test the rate limiting as the consumer:
You can run the following command to test the rate limiting as the Consumer:

```bash
for _ in {1..6}; do curl -i http://localhost:8000/anything -H 'apikey:example-key'; echo; done
Expand All @@ -120,4 +122,4 @@ for _ in {1..6}; do curl -i $KONNECT_PROXY_URL/anything -H 'apikey:example-key';
```
{: 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`.
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`.
9 changes: 6 additions & 3 deletions app/_how-tos/add-rate-limiting-tiers-with-kong-gateway.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---
title: Create rate limiting tiers with {{site.base_gateway}}
content_type: how_to

related_resources:
- text: Rate Limiting
url: /rate-limiting/
- text: Rate Limiting Advanced plugin
url: /plugins/rate-limiting-advanced/
- text: Consumer Group API documentation
url: /api/gateway/admin-ee/#/operations/get-consumer_groups

Expand Down Expand Up @@ -41,7 +44,7 @@ tags:

tldr:
q: How do I rate limit different tiers of users, such as free vs. premium subscribers, in my API using {{site.base_gateway}}?
a: To effectively manage API traffic for various user tiers (such as free, basic, and premium subscribers), you can create **Consumer Groups** for each tier and assign individual Consumers to these groups. Then, configure the Rate Limiting Advanced plugin to apply specific rate limits based on these groups. This setup allows you to enforce customized request limits for each tier, ensuring fair usage and optimizing performance for high-value users.
a: To manage API traffic for various user tiers (such as free, basic, and premium subscribers), you can create <a href="/gateway/entities/consumer-group/">Consumer Groups</a> for each tier and assign individual <a href="/gateway/entities/consumer/">Consumers</a> to these groups. Then, configure the <a href="/plugins/rate-limiting-advanced/">Rate Limiting Advanced plugin</a> to apply specific rate limits based on these groups. This setup allows you to enforce customized request limits for each tier, ensuring fair usage and optimizing performance for high-value users.

faqs:
- q: Why can't I use the regular Rate Limiting plugin to rate limit tiers of Consumers?
Expand Down Expand Up @@ -116,7 +119,7 @@ entities:

## 4. Enable rate limiting on each tier

Enable the Rate Limiting Advanced plugin for each tier:
Enable the Rate Limiting Advanced plugin for each tier.

{% entity_examples %}
entities:
Expand Down
12 changes: 8 additions & 4 deletions app/_how-tos/add-rate-limiting-to-a-service-with-kong-gateway.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
---
title: Enable rate limiting on a service with {{site.base_gateway}}
title: Rate limit a Gateway Service with {{site.base_gateway}}
content_type: how_to

related_resources:
- text: Rate Limiting
url: /rate-limiting/
- text: Rate Limiting plugin
url: /plugins/rate-limiting/
- text: How to create rate limiting tiers with {{site.base_gateway}}
url: /how-to/add-rate-limiting-tiers-with-kong-gateway/
- text: Rate Limiting Advanced plugin
Expand All @@ -29,8 +33,8 @@ tags:
- rate-limiting

tldr:
q: How do I rate limit a service with {{site.base_gateway}}?
a: Install the Rate Limiting plugin and enable it on the service.
q: How do I rate limit a Gateway Service with {{site.base_gateway}}?
a: Install the <a href="/plugins/rate-limiting/">Rate Limiting plugin</a> and enable it on the <a href="/gateway/entities/service/">Service</a>.

tools:
- deck
Expand All @@ -54,7 +58,7 @@ cleanup:

## 1. Enable rate limiting

Enable the [Rate Limiting plugin](/plugins/rate-limiting/) for the service.
Enable the [Rate Limiting plugin](/plugins/rate-limiting/) for the Service.
In this example, the limit is 5 requests per second and 1000 requests per hour.

{% entity_examples %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ tags:
- notifications

tldr:
q: How can I create a custom webhook to push information to Slack using Event Hooks.
a: With an application URL from Slack, you can configure an Event Hook using the `webhook-custom` handler that can `POST` event information to Slack.
q: How can I create a custom webhook to push information to Slack using Event Hooks?
a: With an application URL from Slack, you can configure an <a href="/gateway/entities/event-hook/>Event Hook</a> using the `webhook-custom` handler that can `POST` event information to Slack.
prereqs:
inline:
- title: A Slack webhook application
Expand All @@ -42,6 +42,7 @@ related_resources:

## 1. Configure an Event Hook using the `webhook-custom` handler


Using the `webhook-custom` handler, you can configure an Event Hook that listens for events on a source. The `webhook-custom` handler offers a template that you can configure to create a custom webhook. In this tutorial, we will configure an Event Hook that issues a `POST` request when a `crud` event happens on the Consumer entity. That `POST` request will be made to a Slack webhook application containing a custom message describing the event.
```sh
curl -i -X POST http://localhost:8001/event-hooks \
Expand All @@ -58,7 +59,7 @@ curl -i -X POST http://localhost:8001/event-hooks \
Posting this will result in a `200` response. The `config` body in the Event Hook contains information about the webhook that was created:

* **`"method": "POST"`**: The method we are using in the webhook.
* **`"url": "$SLACK_WEBHOOK_URL"`**: The URL of the webhook, in this case we are using the Slack URl that we created and set as an environment variable.
* **`"url": "$SLACK_WEBHOOK_URL"`**: The URL of the webhook. In this case, we are using the Slack URl that we created and set as an environment variable.
* **`"payload"`**: What this webhook will `POST`.


Expand All @@ -69,7 +70,7 @@ Posting this will result in a `200` response. The `config` body in the Event Hoo
> **Important**: Before you can use Event Hooks for the first time, {{site.base_gateway}} needs to be [reloaded](/how-to/restart-kong-gateway-container).

Using the Admin API to create a new Consumer:
Use the Admin API to create a new Consumer:

```sh
curl -i -X POST http://localhost:8001/consumers \
Expand Down
10 changes: 5 additions & 5 deletions app/_how-tos/create-a-lambda-event-hook-with-kong-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ related_resources:

## 1. Create a lambda Event Hook

A `lambda` Event Hook is an Event Hook that utilizes the `lambda` handler to pass custom code to an Event Hook. Depending on the source and individual event, that code can execute during various stages of the lifecycle of an event. In this guide, you will create an `lambda` Event Hook with custom code that logs an error with a specific message every time you create a Consumer.
A `lambda` Event Hook is an Event Hook that utilizes the `lambda` handler to pass custom code to an Event Hook. Depending on the source and individual event, that code can execute during various stages of the lifecycle of an event. In this guide, you will create an `lambda` Event Hook with custom code that logs an error with a specific message every time you create a [Consumer](/gateway/entities/consumer/).

Create a lua script to load into the lambda Event Hook.
Create a Lua script to load into the lambda Event Hook.

```lua
return function (data, event, source, pid)
Expand All @@ -52,7 +52,7 @@ error("Event Hook on consumer " .. user .. "")
end
```

Create a lambda Event Hook on the `consumers` event, with the `crud` source by creating a `POST` request to the Admin API and passing the code in the request body as an array of strings.
Create a `lambda` Event Hook on the `consumers` event, with the `crud` source by creating a `POST` request to the Admin API and passing the code in the request body as an array of strings.

```sh
curl -i -X POST http://localhost:8001/event-hooks \
Expand All @@ -74,7 +74,7 @@ curl -i -X POST http://localhost:8001/event-hooks \
## 2. Validate the webhook

{:.warning}
> **Important**: Before you can use event hooks for the first time, {{site.base_gateway}} needs to be reloaded.
> **Important**: Before you can use Event Hooks for the first time, {{site.base_gateway}} needs to be [reloaded](/how-to/restart-kong-gateway-container).
Using the Admin API create a new Consumer:

Expand All @@ -89,4 +89,4 @@ Review the logs at `/usr/local/kong/logs/error.log` for an update about the crea
2024/12/16 21:52:54 [error] 114#0: *153047 [kong] event_hooks.lua:190 [string "return function (data, event, source, pid)..."]:3: Event Hook on consumer my-consumer, context: ngx.timer, client: 172.19.0.1, server: 0.0.0.0:8001
```

In the error logs, you will see the Event Hook, and the error log that resulted from `error("Event Hook on consumer " .. user .. "")`.
In the error logs, you will see the Event Hook and the error log that resulted from `error("Event Hook on consumer " .. user .. "")`.
8 changes: 4 additions & 4 deletions app/_how-tos/create-a-log-event-hook-with-kong-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ tags:
- webhook
- notifications
tldr:
q: How do I create an Event Hook that logs events on the Consumer entity.
a: The `log` Event Hook handler can write log events. You can configure an Event Hook using the `log` handler to write to the log file every time a CRUD event happens on the Consumer entity by issuing a `POST` request to the `/event-hooks` endpoint.
q: How do I create an Event Hook that logs events on the Consumer entity?
a: The `log` Event Hook handler can write log events. You can configure an Event Hook using the `log` handler to write to the log file every time a CRUD event happens on the <a href="/gateway/entities/consumer/>Consumer entity</a> by issuing a `POST` request to the `/event-hooks` endpoint.

prereqs:
inline:
Expand All @@ -41,7 +41,7 @@ related_resources:

## 1. Create the Event Hook

`log` Event Hook configuration specifies an event and a source. In this guide you will create an Event Hook that listens for CRUD events on the Consumers entity. This Event Hook will create a log entry when a CRUD event occurs.
The `log` Event Hook configuration specifies an event and a source. In this guide you will create an Event Hook that listens for CRUD events on the [Consumers](/gateway/entities/consumer/) entity. This Event Hook will create a log entry when a CRUD event occurs.

Create a long Event Hook on the `consumers` event using the `crud` source:

Expand All @@ -59,7 +59,7 @@ curl -i -X POST http://localhost:8001/event-hooks \
## 2. Validate the webhook

{:.warning}
> **Important**: Before you can use Event Hooks for the first time, {{site.base_gateway}} needs to be reloaded.
> **Important**: Before you can use Event Hooks for the first time, {{site.base_gateway}} needs to be [reloaded](/how-to/restart-kong-gateway-container).
Use the Admin API to create a new Consumer:

Expand Down
6 changes: 3 additions & 3 deletions app/_how-tos/create-a-webhook-with-kong-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ tags:
- webhook
- notifications
tldr:
q: How do I create a webhook using Event Hooks
a: The `webhook` handler can be configured with a URL. When configured the Event Hook will listen on for the event and push information to the configured URL.
q: How do I create a webhook using Event Hooks?
a: The `webhook` handler can be configured with a URL. When configured, the Event Hook will listen for the event and push information to the configured URL.

prereqs:
inline:
Expand Down Expand Up @@ -49,7 +49,7 @@ related_resources:

The `webhook` handler is used to configure webhooks that make a `POST` request to the URL provided during configuration. The Event Hook will push information to this URL with the event data. In this guide you will configure an Event Hook that will issue a `POST` request every time an event type `consumers` has a CRUD event.

Using the Admin API, create an Event Hook on the Consumers event by issuing a `POST` request to the `/event-hooks` endpoint.
Using the Admin API, create an Event Hook on the [Consumers](/gateway/entities/consumer/) event by issuing a `POST` request to the `/event-hooks` endpoint.

```sh
curl -i -X POST http://localhost:8001/event-hooks \
Expand Down
14 changes: 7 additions & 7 deletions app/_how-tos/custom-deck-object-defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ tldr:

You can set custom configuration defaults for the following core
{{site.base_gateway}} objects:
- Service
- Route
- Upstream
- Target
- [Gateway Service](/gateway/entities/service/)
- [Route](/gateway/entities/route/)
- [Upstream](/gateway/entities/upstream/)
- [Target](/gateway/entities/target/)

Default values get applied to both new and existing objects. See the
[order of precedence](/deck/object-defaults/#value-order-of-precedence) for more detail on how they
Expand All @@ -56,9 +56,9 @@ configuration would overwrite the value in your environment.
Define the properties you want to customize for {{site.base_gateway}} objects.
See the [object defaults reference](/deck/object-defaults) for all configurable objects and default values.

In the `deck_files` directory you created in the [prerequisites](#prerequisites), create a `defaults.yaml` file
In the `deck_files` directory you created in the prerequisites, create a `defaults.yaml` file
and add an `_info` section with `defaults`.
You can define a few select properties for a supported entity, such as a service:
You can define a few select properties for a supported entity, such as a Service:

```yaml
_format_version: "3.0"
Expand All @@ -71,7 +71,7 @@ _info:
```
{: data-file="defaults.yaml" }
Or you could define custom default values for all available fields of a service and a route:
Or you could define custom default values for all available fields of a Service and a Route:
```yaml
_format_version: "3.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
---
title: Enable key authentication on a service with {{site.base_gateway}}
title: Enable key authentication on a Gateway Service with {{site.base_gateway}}
content_type: how_to

related_resources:
- text: Authentication
url: /authentication
url: /authentication/
- text: Key Auth plugin
url: /plugins/key-auth/

products:
- gateway

entities:
- service
- consumer
- route

plugins:
- key-auth

Expand All @@ -31,7 +38,7 @@ prereqs:
- example-route
tldr:
q: How do I secure a service with key authentication?
a: Enable the Key Authentication plugin on the service. This plugin will require all requests made to this service to have a valid API key.
a: Enable the Key Authentication plugin on the Gateway Service. This plugin will require all requests made to this Service to have a valid API key.

cleanup:
inline:
Expand All @@ -44,7 +51,9 @@ cleanup:

---

## 1. Enable the Key Authentication plugin on the service:
## 1. Enable the Key Authentication plugin on the Service:

Enable Key Auth for the Service.

{% entity_examples %}
entities:
Expand All @@ -56,7 +65,10 @@ entities:
- apikey
{% endentity_examples %}

## 2. Create a consumer
## 2. Create a Consumer

[Consumers](/gateway/entities/consumer/) let you identify the client that's interacting with {{site.base_gateway}}.
The Consumer needs an API key to access any {{site.base_gateway}} Services.

{% entity_examples %}
entities:
Expand All @@ -66,9 +78,13 @@ entities:
- key: hello_world
{% endentity_examples %}

## 3. Validate
## 3. Apply the configuration

{% include how-tos/steps/apply_config.md %}

## 4. Validate

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.
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:

Expand Down
Loading

0 comments on commit 01aa1e5

Please sign in to comment.