mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-02 03:58:02 +08:00
change(serverless): rename "balancer" phase to "before_proxy" (#5992)
This commit is contained in:
parent
70174d58cd
commit
265b06bdd3
@ -35,7 +35,7 @@ return function(plugin_name, priority)
|
|||||||
type = "string",
|
type = "string",
|
||||||
default = "access",
|
default = "access",
|
||||||
enum = {"rewrite", "access", "header_filter", "body_filter",
|
enum = {"rewrite", "access", "header_filter", "body_filter",
|
||||||
"log", "balancer"}
|
"log", "before_proxy"}
|
||||||
},
|
},
|
||||||
functions = {
|
functions = {
|
||||||
type = "array",
|
type = "array",
|
||||||
@ -114,7 +114,7 @@ return function(plugin_name, priority)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _M.before_proxy(conf, ctx)
|
function _M.before_proxy(conf, ctx)
|
||||||
call_funcs('balancer', conf, ctx)
|
call_funcs('before_proxy', conf, ctx)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.header_filter(conf, ctx)
|
function _M.header_filter(conf, ctx)
|
||||||
|
@ -41,7 +41,7 @@ Both plug-ins receive the same parameters.
|
|||||||
|
|
||||||
| Name | Type | Requirement | Default | Valid | Description |
|
| Name | Type | Requirement | Default | Valid | Description |
|
||||||
| --------- | ------------- | ----------- | ---------- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------- | ------------- | ----------- | ---------- | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| phase | string | optional | ["access"] | ["rewrite", "access", "header_filter", "body_filter", "log", "balancer"] | |
|
| phase | string | optional | ["access"] | ["rewrite", "access", "header_filter", "body_filter", "log", "before_proxy"] | |
|
||||||
| functions | array[string] | required | | | A list of functions that are specified to run is an array type, which can contain either one function or multiple functions, executed sequentially. |
|
| functions | array[string] | required | | | A list of functions that are specified to run is an array type, which can contain either one function or multiple functions, executed sequentially. |
|
||||||
|
|
||||||
Note that only function is accepted here, not other types of Lua code. For example, anonymous functions are legal:<br />
|
Note that only function is accepted here, not other types of Lua code. For example, anonymous functions are legal:<br />
|
||||||
@ -71,6 +71,8 @@ ngx.say(count)
|
|||||||
|
|
||||||
Since `v2.6`, we pass the `conf` and `ctx` as the first two arguments to the servelss function, like a regular plugin.
|
Since `v2.6`, we pass the `conf` and `ctx` as the first two arguments to the servelss function, like a regular plugin.
|
||||||
|
|
||||||
|
Prior to `v2.12.0`, the phase `before_proxy` used to be called `balancer`. Considering that this method actually runs after `access` and before the request goes upstream, and has nothing to do with `balancer`, the new naming would be more appropriate.
|
||||||
|
|
||||||
## How To Enable
|
## How To Enable
|
||||||
|
|
||||||
Here's an example, enable the serverless plugin on the specified route:
|
Here's an example, enable the serverless plugin on the specified route:
|
||||||
|
@ -30,7 +30,7 @@ serverless 的插件有两个,分别是 `serverless-pre-function` 和 `serverl
|
|||||||
|
|
||||||
| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
|
| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
|
||||||
| --------- | ------------- | -------- | ---------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
|
| --------- | ------------- | -------- | ---------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
|
||||||
| phase | string | 可选 | ["access"] | ["rewrite", "access", "header_filter", "body_filter", "log", "balancer"] | |
|
| phase | string | 可选 | ["access"] | ["rewrite", "access", "header_filter", "body_filter", "log", "before_proxy"] | |
|
||||||
| functions | array[string] | 必须 | | | 指定运行的函数列表,是数组类型,里面可以包含一个函数,也可以是多个函数,按照先后顺序执行。 |
|
| functions | array[string] | 必须 | | | 指定运行的函数列表,是数组类型,里面可以包含一个函数,也可以是多个函数,按照先后顺序执行。 |
|
||||||
|
|
||||||
需要注意的是,这里只接受函数,而不接受其他类型的 Lua 代码。比如匿名函数是合法的:
|
需要注意的是,这里只接受函数,而不接受其他类型的 Lua 代码。比如匿名函数是合法的:
|
||||||
@ -60,6 +60,8 @@ ngx.say(count)
|
|||||||
|
|
||||||
从 `v2.6` 版本开始,我们会把 `conf` 和 `ctx` 作为头两个参数传递给 serverless 函数,就跟一般的插件一样。
|
从 `v2.6` 版本开始,我们会把 `conf` 和 `ctx` 作为头两个参数传递给 serverless 函数,就跟一般的插件一样。
|
||||||
|
|
||||||
|
`v2.12.0` 版本之前,`before_proxy` 这个 phase 曾被称作 `balancer`。考虑到这一方法事实上运行在 `access` 之后,代理到上游之前,跟 `balancer` 没有关系,新的命名会更加贴切。
|
||||||
|
|
||||||
## 示例
|
## 示例
|
||||||
|
|
||||||
### 启动插件
|
### 启动插件
|
||||||
|
4
t/admin/schema.t
vendored
4
t/admin/schema.t
vendored
@ -143,7 +143,7 @@ location /t {
|
|||||||
[[{
|
[[{
|
||||||
"properties": {
|
"properties": {
|
||||||
"phase": {
|
"phase": {
|
||||||
"enum": ["rewrite", "access", "header_filter", "body_filter", "log", "balancer"],
|
"enum": ["rewrite", "access", "header_filter", "body_filter", "log", "before_proxy"],
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"functions": {
|
"functions": {
|
||||||
@ -183,7 +183,7 @@ location /t {
|
|||||||
[[{
|
[[{
|
||||||
"properties": {
|
"properties": {
|
||||||
"phase": {
|
"phase": {
|
||||||
"enum": ["rewrite", "access", "header_filter", "body_filter", "log", "balancer"],
|
"enum": ["rewrite", "access", "header_filter", "body_filter", "log", "before_proxy"],
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"functions": {
|
"functions": {
|
||||||
|
20
t/plugin/serverless.t
vendored
20
t/plugin/serverless.t
vendored
@ -682,7 +682,7 @@ match uri /hello
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== TEST 23: run in the balancer phase
|
=== TEST 23: run in the before_proxy phase
|
||||||
--- config
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
@ -692,7 +692,7 @@ match uri /hello
|
|||||||
[[{
|
[[{
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"serverless-pre-function": {
|
"serverless-pre-function": {
|
||||||
"phase": "balancer",
|
"phase": "before_proxy",
|
||||||
"functions" : ["return function(conf, ctx) ngx.req.set_header('X-SERVERLESS', ctx.balancer_ip) end"]
|
"functions" : ["return function(conf, ctx) ngx.req.set_header('X-SERVERLESS', ctx.balancer_ip) end"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -736,7 +736,7 @@ x-serverless: 127.0.0.1
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== TEST 25: exit in the balancer phase
|
=== TEST 25: exit in the before_proxy phase
|
||||||
--- config
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
@ -746,7 +746,7 @@ x-serverless: 127.0.0.1
|
|||||||
[[{
|
[[{
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"serverless-pre-function": {
|
"serverless-pre-function": {
|
||||||
"phase": "balancer",
|
"phase": "before_proxy",
|
||||||
"functions" : ["return function(conf, ctx) ngx.exit(403) end"]
|
"functions" : ["return function(conf, ctx) ngx.exit(403) end"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -786,7 +786,7 @@ GET /log_request
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
=== TEST 27: ensure balancer phase run correct time
|
=== TEST 27: ensure before_proxy phase run correct time
|
||||||
--- config
|
--- config
|
||||||
location /t {
|
location /t {
|
||||||
content_by_lua_block {
|
content_by_lua_block {
|
||||||
@ -796,8 +796,8 @@ GET /log_request
|
|||||||
[[{
|
[[{
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"serverless-pre-function": {
|
"serverless-pre-function": {
|
||||||
"phase": "balancer",
|
"phase": "before_proxy",
|
||||||
"functions" : ["return function(conf, ctx) ngx.log(ngx.WARN, 'run balancer phase with ', ctx.balancer_ip) end"]
|
"functions" : ["return function(conf, ctx) ngx.log(ngx.WARN, 'run before_proxy phase with ', ctx.balancer_ip) end"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"upstream": {
|
"upstream": {
|
||||||
@ -831,7 +831,7 @@ passed
|
|||||||
--- request
|
--- request
|
||||||
GET /log_request
|
GET /log_request
|
||||||
--- grep_error_log eval
|
--- grep_error_log eval
|
||||||
qr/(run balancer phase with [\d.]+)/
|
qr/(run before_proxy phase with [\d.]+)/
|
||||||
--- grep_error_log_out
|
--- grep_error_log_out
|
||||||
run balancer phase with 0.0.0.0
|
run before_proxy phase with 0.0.0.0
|
||||||
run balancer phase with 127.0.0.1
|
run before_proxy phase with 127.0.0.1
|
||||||
|
Loading…
Reference in New Issue
Block a user