mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-05 05:27:35 +08:00
chore: enhance upstream discovery (#3269)
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
parent
9f6e605a15
commit
fcd880f23f
@ -369,9 +369,9 @@ local upstream_schema = {
|
||||
type = "boolean",
|
||||
},
|
||||
},
|
||||
anyOf = {
|
||||
oneOf = {
|
||||
{required = {"type", "nodes"}},
|
||||
{required = {"type", "service_name"}},
|
||||
{required = {"type", "service_name", "discovery_type"}},
|
||||
},
|
||||
additionalProperties = false,
|
||||
}
|
||||
|
@ -512,7 +512,9 @@ In addition to the basic complex equalization algorithm selection, APISIX's Upst
|
||||
|Name |Optional|Description|
|
||||
|------- |-----|------|
|
||||
|type |required|`roundrobin` supports the weight of the load, `chash` consistency hash,`ewma` minimum latency ,pick one of them.see https://en.wikipedia.org/wiki/EWMA_chart for details|
|
||||
|nodes |required|Hash table, the key of the internal element is the upstream machine address list, the format is `Address + Port`, where the address part can be IP or domain name, such as `192.168.1.100:80`, `foo.com:80`, etc. Value is the weight of the node. In particular, when the weight value is `0`, it has a special meaning, which usually means that the upstream node is invalid and never wants to be selected. The `nodes` can be empty, which means it is a placeholder and will be filled later. Clients use such an upstream will get 502 response. |
|
||||
|nodes |required, can't be used with `service_name` |Hash table, the key of the internal element is the upstream machine address list, the format is `Address + Port`, where the address part can be IP or domain name, such as `192.168.1.100:80`, `foo.com:80`, etc. Value is the weight of the node. In particular, when the weight value is `0`, it has a special meaning, which usually means that the upstream node is invalid and never wants to be selected. The `nodes` can be empty, which means it is a placeholder and will be filled later. Clients use such an upstream will get 502 response. |
|
||||
|service_name |required, can't be used with `nodes` |the name of service used in the service discovery, see [discovery](discovery.md) for more details|
|
||||
|discovery_type |required, if `server_name` is used | the type of service discovery, see [discovery](discovery.md) for more details|
|
||||
|hash_on |optional|This option is only valid if the `type` is `chash`. Supported types `vars`(Nginx variables), `header`(custom header), `cookie`, `consumer`, the default value is `vars`.|
|
||||
|key |optional|This option is only valid if the `type` is `chash`. Find the corresponding node `id` according to `hash_on` and `key`. When `hash_on` is set as `vars`, `key` is the required parameter, for now, it support nginx built-in variables like `uri, server_name, server_addr, request_uri, remote_port, remote_addr, query_string, host, hostname, arg_***`, `arg_***` is arguments in the request line, [Nginx variables list](http://nginx.org/en/docs/varindex.html). When `hash_on` is set as `header`, `key` is the required parameter, and `header name` is customized. When `hash_on` is set to `cookie`, `key` is the required parameter, and `cookie name` is customized. When `hash_on` is set to `consumer`, `key` does not need to be set. In this case, the `key` adopted by the hash algorithm is the `consumer_name` authenticated. If the specified `hash_on` and `key` can not fetch values, it will be fetch `remote_addr` by default.|
|
||||
|checks |optional|Configure the parameters of the health check. For details, refer to [health-check](health-check.md).|
|
||||
|
@ -520,7 +520,9 @@ APISIX 的 Upstream 除了基本的复杂均衡算法选择外,还支持对上
|
||||
|
||||
|名字 |可选项 |类型 |说明 |示例|
|
||||
|---------|---------|----|-----------|----|
|
||||
|nodes |必需|Node|哈希表,内部元素的 key 是上游机器地址列表,格式为`地址 + Port`,其中地址部分可以是 IP 也可以是域名,比如 `192.168.1.100:80`、`foo.com:80`等。value 则是节点的权重,特别的,当权重值为 `0` 有特殊含义,通常代表该上游节点失效,永远不希望被选中。`nodes` 可以为空,这通常用作占位符。客户端命中这样的上游会返回 502。|`192.168.1.100:80`|
|
||||
|nodes |必需,不能和 `service_name` 一起用|Node|哈希表,内部元素的 key 是上游机器地址列表,格式为`地址 + Port`,其中地址部分可以是 IP 也可以是域名,比如 `192.168.1.100:80`、`foo.com:80`等。value 则是节点的权重,特别的,当权重值为 `0` 有特殊含义,通常代表该上游节点失效,永远不希望被选中。`nodes` 可以为空,这通常用作占位符。客户端命中这样的上游会返回 502。|`192.168.1.100:80`|
|
||||
|service_name |必需,不能和 `nodes` 一起用|string|服务发现时使用的服务名,见[集成服务发现注册中心](./discovery.md)|`a-bootiful-client`|
|
||||
|discovery_type |必需,如果设置了 `service_name` |string|服务发现类型,见[集成服务发现注册中心](./discovery.md)|`eureka`|
|
||||
|type |必需|枚举|`roundrobin` 支持权重的负载,`chash` 一致性哈希,两者是二选一的|`roundrobin`||
|
||||
|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)||
|
||||
|checks |可选|health_checker|配置健康检查的参数,详细可参考[health-check](../health-check.md)||
|
||||
|
69
t/node/healthcheck2.t
Normal file
69
t/node/healthcheck2.t
Normal file
@ -0,0 +1,69 @@
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership.
|
||||
# The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
# (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
use t::APISIX 'no_plan';
|
||||
|
||||
master_on();
|
||||
repeat_each(1);
|
||||
no_root_location();
|
||||
no_shuffle();
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my ($block) = @_;
|
||||
|
||||
if (!$block->yaml_config) {
|
||||
my $yaml_config = <<_EOC_;
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
config_center: yaml
|
||||
enable_admin: false
|
||||
_EOC_
|
||||
|
||||
$block->set_value("yaml_config", $yaml_config);
|
||||
}
|
||||
|
||||
if (!$block->request) {
|
||||
$block->set_value("request", "GET /hello");
|
||||
}
|
||||
|
||||
if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
|
||||
$block->set_value("no_error_log", "[error]");
|
||||
}
|
||||
});
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: can't use service_name with nodes
|
||||
--- apisix_yaml
|
||||
routes:
|
||||
-
|
||||
uris:
|
||||
- /hello
|
||||
upstream_id: 1
|
||||
upstreams:
|
||||
- service_name: abaaba
|
||||
discovery_type: eureka
|
||||
nodes:
|
||||
"127.0.0.1:80": 1
|
||||
type: roundrobin
|
||||
id: 1
|
||||
#END
|
||||
--- error_log
|
||||
value should match only one schema, but matches both schemas 1 and 2
|
||||
--- error_code: 502
|
Loading…
Reference in New Issue
Block a user