Skip to content

Commit

Permalink
docs: add buffer plugin (#284)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Feb 11, 2024
1 parent 1519036 commit c6cfd61
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 5 deletions.
76 changes: 76 additions & 0 deletions site/content/en/docs/reference/plugins/buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: Buffer
---

## Description

The `buffer` plugin fully buffers the complete request, by leveraging Envoy's `buffer` filter. It can be used for several purposes, like:

* Protecting applications from high network latency.
* Some plugins will buffer the whole request, which may trigger a 413 HTTP status code when the max request body size is met. We can set the `maxRequestBytes` larger than `per_connection_buffer_limit_bytes` to increase the max request body size per route.

## Attribute

| | |
|-------|---------|
| Type | General |
| Order | Outer |

## Configuration

| Name | Type | Required | Validation | Description |
|-----------------|--------|----------|------------|--------------------------------------------------------------------------------------------|
| maxRequestBytes | uint32 | True | | The maximum request body size that the filter will buffer before returning a 413 response. |

## Usage

Assumed we have the HTTPRoute below attached to `localhost:10000`, and a backend server listening to port `8080`:

```yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: default
spec:
parentRefs:
- name: default
namespace: default
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: backend
port: 8080
```
By applying the configuration below, the request to `http://localhost:10000/` is buffered until the body length meets the max requests bytes 4:

```yaml
apiVersion: mosn.io/v1
kind: HTTPFilterPolicy
metadata:
name: policy
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: default
filters:
buffer:
config:
maxRequestBytes: 4
```

We can test it out:

```
$ curl -d "hello" http://localhost:10000/ -i
HTTP/1.1 413 Payload Too Large
```

```
$ curl -d "hell" http://localhost:10000/ -i
HTTP/1.1 200 OK
```
10 changes: 5 additions & 5 deletions site/content/en/docs/reference/plugins/consumer_restriction.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ The `consumerRestriction` plugin determines whether the current consumer has acc

| Name | Type | Required | Validation | Description |
|-------|-------|----------|------------|--------------------------------------|
| allow | Rules | No | | List of rules allowing access access |
| deny | Rules | No | | List of rules denying access access |
| allow | Rules | False | | List of rules allowing access access |
| deny | Rules | False | | List of rules denying access access |

Only one of `allow` or `deny` can be configured.

### Rules

| Name | Type | Required | Validation | Description |
|-------|--------|----------|----------------|--------------------|
| rules | Rule[] | Yes | min_items: 1 | List of rules |
| rules | Rule[] | True | min_items: 1 | List of rules |

## Rule

| Name | Type | Required | Validation | Description |
|------|--------|----------|--------------|----------------------|
| name | string | Yes | min_len: 1 | Name of the Consumer |
| name | string | True | min_len: 1 | Name of the Consumer |


## Usage
Expand Down Expand Up @@ -135,4 +135,4 @@ spec:
deny:
rules:
- name: rick
```
```
75 changes: 75 additions & 0 deletions site/content/zh-hans/docs/reference/plugins/buffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: Buffer
---

## 说明

`buffer` 插件通过利用 Envoy 的 `buffer` 过滤器完全缓冲整个请求。它可以用于几个目的,比如:

* 保护应用程序免受高网络延迟的影响。
* 一些插件会缓冲整个请求。当请求体超过最大长度时,将触发 413 HTTP 状态码。我们可以设置 `maxRequestBytes` 大于 `per_connection_buffer_limit_bytes` 来增加单个路由的最大请求体大小。

## 属性
| | |
|-------|---------|
| Type | General |
| Order | Outer |

## 配置

| 名称 | 类型 | 必选 | 校验规则 | 说明 |
|-----------------|--------|------|----------|-------------------------------------------------------------------------------------|
| maxRequestBytes | uint32 || | 缓冲的请求体最大大小,超过此大小将返回 413 响应。 |

## 用法

假设我们有下面附加到 `localhost:10000` 的 HTTPRoute,并且有一个后端服务器监听端口 `8080`

```yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: default
spec:
parentRefs:
- name: default
namespace: default
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: backend
port: 8080
```
通过应用下面的配置,发送到 `http://localhost:10000/` 的请求会被缓冲,直到请求体长度达到最大请求字节数 4:

```yaml
apiVersion: mosn.io/v1
kind: HTTPFilterPolicy
metadata:
name: policy
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: default
filters:
buffer:
config:
maxRequestBytes: 4
```

我们可以测试一下:

```
$ curl -d "hello" http://localhost:10000/ -i
HTTP/1.1 413 Payload Too Large
```
```
$ curl -d "hell" http://localhost:10000/ -i
HTTP/1.1 200 OK
```

0 comments on commit c6cfd61

Please sign in to comment.