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

docs: add plugin docs #41

Merged
merged 3 commits into from
Nov 1, 2022
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
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* [percent-limit](plugin/percent-limit.md)
* [local-limiting](plugin/local-limiting.md)
* [static-downgrade](plugin/static-downgrade.md)
* [circuit-breaker](plugin/circuit-breaker.md)
* [response-header-rewrite](plugin/response-header-rewrite.md)
* [ua-restriction](plugin/ua-restriction.md)
* [header-restriction](plugin/header-restriction.md)
* [referer-restriction](plugin/referer-restriction.md)
* [ip-restriction](plugin/ip-restriction.md)
* [uri-restriction](plugin/uri-restriction.md)

## 问题定位

Expand Down
56 changes: 56 additions & 0 deletions docs/plugin/circuit-breaker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 熔断

## 描述

`circuit-breaker`插件可以对网关流量基于请求错误率或时间窗进行熔断

## 属性

| 名称 | 类型 | 必选项 | 范围 | 描述 |
|----------------------------------|----------|-----|-------------------------------------------------|-------------------------------------------------------------------------------|
| kind | string | 是 | circuit-breaker | 插件类型(值固定) |
| response.headers[].key | string | 否 | length <= 200 | 熔断后请求响应头名称 |
| response.headers[].value | string | 否 | length <= 200 | 熔断后请求响应头值 |
| response.code | integer | 是 | [200, 599] | 熔断后请求响应码 |
| response.body | string | 否 | - | 熔断后请求响应body |
| config.average_response_time | float | 否 | (0, 1000.0] (s) | 慢响应时间阈值 |
| config.error_percent_threshold | float | 否 | (0, 100.0] | 错误百分比阈值 |
| config.consecutive_slow_requests | integer | 否 | [1, 10000] | 连续慢响应次数 |
| config.breakType | []string | 是 | ErrorPercentCircuitbreaker<br/>RTCircuitbreaker | 熔断触发条件类型<br/>ErrorPercentCircuitbreaker: 错误率触发熔断<br/>RTCircuitbreaker: RT触发熔断 |
| config.min_request_amount | integer | 否 | [1, 1000000] | 最小请求次数 |
| config.lookback_duration | integer | 是 | [1, 120] (s) | 最小请求次数 |
| config.break_duration | integer | 是 | [1, 7200] (s) | 惩罚时间 |


## 前置条件

以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换;创建插件命令中`PluginConfiguration`(插件配置)需要根据实际需要进行配置

## 创建

```shell
curl -XPOST -v -H "Content-Type:application/json" -d '{
"BindingObjectId": {{ 路由ID }},
"BindingObjectType": "routeRule",
"GwId": {{ 网关ID }},
"PluginConfiguration": "{\"kind\":\"circuit-breaker\",\"response\":{\"headers\":[{\"key\":\"breakHeader\",\"value\":\"breakHeaderValue\"}],\"code\":\"510\",\"body\":\"breakBody\"},\"config\":{\"average_response_time\":\"60\",\"error_percent_threshold\":\"90.0\",\"consecutive_slow_requests\":\"5\",\"breakType\":[\"ErrorPercentCircuitbreaker\",\"RTCircuitbreaker\"],\"min_request_amount\":\"20\",\"lookback_duration\":\"60\",\"break_duration\":\"10\"}}",
"PluginType": "circuit-breaker"
}' http://{{ hango-portal ip:port }}/gdashboard?Action=BindingPlugin&Version=2019-09-01
```

## 测试

```shell
## 通过改造如下基础curl命令,创造插件中配置数量的错误次数,根据时间窗或错误请求次数验证插件是否造成熔断
curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}"
```

## 删除

```shell
curl -v -H "Content-Type:application/json" http://{{ hango-portal ip:port }}/gdashboard?PluginBindingInfoId={{ 插件ID }}&Action=UnbindingPlugin&Version=2019-09-01
```

## 界面配置方法

[插件界面配置方法引导](plugin-configuring-guide.md)
48 changes: 48 additions & 0 deletions docs/plugin/uri-restriction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# URI黑白名单

## 描述

`uri-restriction`是hango的一款rider插件(用户可基于hango的rider开发手册开发自己的rider插件),该插件可以基于请求的path进行黑白名单限制

## 属性

| 名称 | 类型 | 必选项 | 范围 | 描述 |
|------------------|----------|-----|-----------------|-------------|
| kind | string | 是 | uri-restriction | 插件类型(值固定) |
| type | string | 是 | lua | 插件技术实现(值固定) |
| config.allowlist | []string | 否 | length <= 200 | 白名单path |
| config.denylist | []string | 否 | length <= 200 | 黑名单path |


## 前置条件

以下curl命令中存在变量,使用前需要替换为真实环境数据,变量以`{{}}`符号包裹,例如`{{ 网关ID }}`需要根据网关的实际ID进行替换;创建插件命令中`PluginConfiguration`(插件配置)需要根据实际需要进行配置

## 创建

```shell
curl -XPOST -v -H "Content-Type:application/json" -d '{
"BindingObjectId": {{ 路由ID }},
"BindingObjectType": "routeRule",
"GwId": {{ 网关ID }},
"PluginConfiguration": "{\"kind\":\"uri-restriction\",\"type\":\"lua\",\"config\":{\"allowlist\":[\"/test/blank\"],\"denylist\":[\"/test/black\"]}}",
"PluginType": "uri-restriction"
}' http://{{ hango-portal ip:port }}/gdashboard?Action=BindingPlugin&Version=2019-09-01
```

## 测试

```shell
## 修改如下请求的{{ 路由path }},配置为插件中的黑名单或白名单,观察请求被拦截或放行
curl -v "http://{{ 网关IP }}/{{ 路由path }}" -H "host:{{ 网关关联域名 }}"
```

## 删除

```shell
curl -v -H "Content-Type:application/json" http://{{ hango-portal ip:port }}/gdashboard?PluginBindingInfoId={{ 插件ID }}&Action=UnbindingPlugin&Version=2019-09-01
```

## 界面配置方法

[插件界面配置方法引导](plugin-configuring-guide.md)