-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix(balancer): quote ipv6 address #7594
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -532,7 +532,7 @@ APISIX 的 Upstream 除了基本的负载均衡算法选择外,还支持对上 | |
| 名字 | 可选项 | 类型 | 说明 | 示例 | | ||
| -------------- | ---------------------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ | | ||
| type | 必需 | 枚举 | 负载均衡算法 | | | | ||
| nodes | 必需,不能和 `service_name` 一起用 | Node | 哈希表或数组。当它是哈希表时,内部元素的 key 是上游机器地址列表,格式为`地址 +(可选的)端口`,其中地址部分可以是 IP 也可以是域名,比如 `192.168.1.100:80`、`foo.com:80`等。value 则是节点的权重。当它是数组时,数组中每个元素都是一个哈希表,其中包含 `host`、`weight` 以及可选的 `port`、`priority`。`nodes` 可以为空,这通常用作占位符。客户端命中这样的上游会返回 502。 | `192.168.1.100:80` | | ||
| nodes | 必需,不能和 `service_name` 一起用 | Node | 哈希表或数组。当它是哈希表时,内部元素的 key 是上游机器地址列表,格式为`地址 +(可选的)端口`,其中地址部分可以是 IP 也可以是域名,比如 `192.168.1.100:80`、`foo.com:80`等。如果地址部分是 IPv6 地址,则必须用中括号将其括起来。value 则是节点的权重。当它是数组时,数组中每个元素都是一个哈希表,其中包含 `host`、`weight` 以及可选的 `port`、`priority`。`nodes` 可以为空,这通常用作占位符。客户端命中这样的上游会返回 502。 | `192.168.1.100:80`, `[::1]:80` | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We quote the IPv6 address in the code if it doesn't wrap by the double quotes, but why here do we ask users to add the double quotes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two types of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we can use |
||
| service_name | 必需,不能和 `nodes` 一起用 | string | 服务发现时使用的服务名,见[集成服务发现注册中心](./discovery.md) | `a-bootiful-client` | | ||
| discovery_type | 必需,如果设置了 `service_name` | string | 服务发现类型,见 [集成服务发现注册中心](./discovery.md) | `eureka` | | ||
| key | 条件必需 | 匹配类型 | 该选项只有类型是 `chash` 才有效。根据 `key` 来查找对应的 node `id`,相同的 `key` 在同一个对象中,永远返回相同 id,目前支持的 Nginx 内置变量有 `uri, server_name, server_addr, request_uri, remote_port, remote_addr, query_string, host, hostname, arg_***`,其中 `arg_***` 是来自 URL 的请求参数,[Nginx 变量列表](http://nginx.org/en/docs/varindex.html) | | | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,3 +108,187 @@ GET /hello | |
hello world | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 5: set upstream(id: 1) | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/upstreams/1', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"nodes": [ | ||
{ | ||
"weight": 100, | ||
"priority": 0, | ||
"host": "::1", | ||
"port": 1980 | ||
} | ||
], | ||
"type": "roundrobin", | ||
"desc": "new upstream" | ||
}]] | ||
) | ||
|
||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 6: hit routes | ||
--- request | ||
GET /hello | ||
--- response_body | ||
hello world | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 7: set upstream(id: 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be better to use a precise test name instead of repeating |
||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/upstreams/1', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"nodes": [ | ||
{ | ||
"weight": 100, | ||
"priority": 0, | ||
"host": "[::1]", | ||
"port": 1980 | ||
} | ||
], | ||
"type": "roundrobin", | ||
"desc": "new upstream" | ||
}]] | ||
) | ||
|
||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 8: hit routes | ||
--- request | ||
GET /hello | ||
--- response_body | ||
hello world | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 9: set upstream(id: 1) | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/upstreams/1', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"nodes": { | ||
"::1:1980": 1 | ||
}, | ||
"type": "roundrobin", | ||
"desc": "new upstream" | ||
}]] | ||
) | ||
|
||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 10: hit routes | ||
--- request | ||
GET /hello | ||
--- error_code: 502 | ||
--- error_log | ||
connect() to [::0.1.25.128]:80 failed | ||
|
||
|
||
|
||
=== TEST 11: set upstream(id: 1) with two nodes | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/upstreams/1', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"nodes": [ | ||
{ | ||
"weight": 100, | ||
"priority": 0, | ||
"host": "::1", | ||
"port": 1980 | ||
}, | ||
{ | ||
"weight": 100, | ||
"priority": 0, | ||
"host": "::1", | ||
"port": 1980 | ||
} | ||
], | ||
"type": "roundrobin", | ||
"desc": "new upstream" | ||
}]] | ||
) | ||
|
||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- no_error_log | ||
[error] | ||
|
||
|
||
|
||
=== TEST 12: hit routes | ||
--- request | ||
GET /hello | ||
--- response_body | ||
hello world | ||
--- no_error_log | ||
[error] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The quote is not needed in the array format? Only when using in hash format, and the host contains a port, the quote is required to distinguish it between
::1:1980
and[::1]:1980
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacewander yes.