feat(apisix): add Cloudron package
- Implements Apache APISIX packaging for Cloudron platform. - Includes Dockerfile, CloudronManifest.json, and start.sh. - Configured to use Cloudron's etcd addon. 🤖 Generated with Gemini CLI Co-Authored-By: Gemini <noreply@google.com>
This commit is contained in:
@@ -0,0 +1,278 @@
|
||||
#
|
||||
# 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';
|
||||
|
||||
repeat_each(1);
|
||||
log_level('info');
|
||||
no_root_location();
|
||||
no_shuffle();
|
||||
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my ($block) = @_;
|
||||
|
||||
my $http_config = $block->http_config // <<_EOC_;
|
||||
|
||||
server {
|
||||
listen 20999;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
ngx.say("missing consul services")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 30511;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 1")
|
||||
}
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 30512;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 2")
|
||||
}
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 30513;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 3")
|
||||
}
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 30514;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 4")
|
||||
}
|
||||
}
|
||||
}
|
||||
_EOC_
|
||||
|
||||
$block->set_value("http_config", $http_config);
|
||||
|
||||
if (!$block->stream_request) {
|
||||
$block->set_value("stream_request", "GET /hello HTTP/1.1\r\nHost: 127.0.0.1:1985\r\nConnection: close\r\n\r\n");
|
||||
}
|
||||
});
|
||||
|
||||
our $yaml_config = <<_EOC_;
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
enable_control: true
|
||||
control:
|
||||
ip: 127.0.0.1
|
||||
port: 9090
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
consul:
|
||||
servers:
|
||||
- "http://127.0.0.1:8500"
|
||||
- "http://127.0.0.1:8600"
|
||||
skip_services:
|
||||
- "service_c"
|
||||
timeout:
|
||||
connect: 1000
|
||||
read: 1000
|
||||
wait: 60
|
||||
weight: 1
|
||||
fetch_interval: 1
|
||||
keepalive: true
|
||||
default_service:
|
||||
host: "127.0.0.1"
|
||||
port: 20999
|
||||
metadata:
|
||||
fail_timeout: 1
|
||||
weight: 1
|
||||
max_fails: 1
|
||||
_EOC_
|
||||
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: prepare consul catalog register nodes
|
||||
--- config
|
||||
location /consul1 {
|
||||
rewrite ^/consul1/(.*) /v1/agent/service/$1 break;
|
||||
proxy_pass http://127.0.0.1:8500;
|
||||
}
|
||||
|
||||
location /consul2 {
|
||||
rewrite ^/consul2/(.*) /v1/agent/service/$1 break;
|
||||
proxy_pass http://127.0.0.1:8600;
|
||||
}
|
||||
--- pipelined_requests eval
|
||||
[
|
||||
"PUT /consul1/deregister/service_a1",
|
||||
"PUT /consul1/deregister/service_b1",
|
||||
"PUT /consul1/deregister/service_a2",
|
||||
"PUT /consul1/deregister/service_b2",
|
||||
"PUT /consul2/deregister/service_a1",
|
||||
"PUT /consul2/deregister/service_b1",
|
||||
"PUT /consul2/deregister/service_a2",
|
||||
"PUT /consul2/deregister/service_b2",
|
||||
"PUT /consul1/register\n" . "{\"ID\":\"service_a1\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30511,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
|
||||
"PUT /consul1/register\n" . "{\"ID\":\"service_a2\",\"Name\":\"service_a\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30512,\"Meta\":{\"service_a_version\":\"4.0\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
|
||||
"PUT /consul1/register\n" . "{\"ID\":\"service_b1\",\"Name\":\"service_b\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30513,\"Meta\":{\"service_b_version\":\"4.1\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
|
||||
"PUT /consul1/register\n" . "{\"ID\":\"service_b2\",\"Name\":\"service_b\",\"Tags\":[\"primary\",\"v1\"],\"Address\":\"127.0.0.1\",\"Port\":30514,\"Meta\":{\"service_b_version\":\"4.1\"},\"EnableTagOverride\":false,\"Weights\":{\"Passing\":10,\"Warning\":1}}",
|
||||
]
|
||||
--- error_code eval
|
||||
[200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: test consul server 1
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: service_a
|
||||
discovery_type: consul
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response eval
|
||||
qr/server [1-2]/
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: test consul server 2
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: service_b
|
||||
discovery_type: consul
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response eval
|
||||
qr/server [3-4]/
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: test mini consul config
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
consul:
|
||||
servers:
|
||||
- "http://127.0.0.1:8500"
|
||||
- "http://127.0.0.1:6500"
|
||||
#END
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: service_a
|
||||
discovery_type: consul
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response eval
|
||||
qr/server [1-2]/
|
||||
--- ignore_error_log
|
||||
|
||||
|
||||
|
||||
=== TEST 5: test invalid service name
|
||||
sometimes the consul key maybe deleted by mistake
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: service_c
|
||||
discovery_type: consul
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response_like
|
||||
missing consul services
|
||||
--- ignore_error_log
|
||||
|
||||
|
||||
|
||||
=== TEST 6: test skip keys
|
||||
skip some services, return default nodes, get response: missing consul services
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
consul:
|
||||
servers:
|
||||
- "http://127.0.0.1:8600"
|
||||
prefix: "upstreams"
|
||||
skip_services:
|
||||
- "service_a"
|
||||
default_service:
|
||||
host: "127.0.0.1"
|
||||
port: 20999
|
||||
metadata:
|
||||
fail_timeout: 1
|
||||
weight: 1
|
||||
max_fails: 1
|
||||
#END
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: service_a
|
||||
discovery_type: consul
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response_like
|
||||
missing consul services
|
||||
--- ignore_error_log
|
@@ -0,0 +1,269 @@
|
||||
#
|
||||
# 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';
|
||||
|
||||
repeat_each(1);
|
||||
log_level('info');
|
||||
no_root_location();
|
||||
no_shuffle();
|
||||
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my ($block) = @_;
|
||||
|
||||
my $http_config = $block->http_config // <<_EOC_;
|
||||
|
||||
server {
|
||||
listen 20999;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
ngx.say("missing consul_kv services")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
listen 30511;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 1")
|
||||
}
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 30512;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 2")
|
||||
}
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 30513;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 3")
|
||||
}
|
||||
}
|
||||
}
|
||||
server {
|
||||
listen 30514;
|
||||
|
||||
location /hello {
|
||||
content_by_lua_block {
|
||||
ngx.say("server 4")
|
||||
}
|
||||
}
|
||||
}
|
||||
_EOC_
|
||||
|
||||
$block->set_value("http_config", $http_config);
|
||||
|
||||
if (!$block->stream_request) {
|
||||
$block->set_value("stream_request", "GET /hello HTTP/1.1\r\nHost: 127.0.0.1:1985\r\nConnection: close\r\n\r\n");
|
||||
}
|
||||
});
|
||||
|
||||
our $yaml_config = <<_EOC_;
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
consul_kv:
|
||||
servers:
|
||||
- "http://127.0.0.1:8500"
|
||||
- "http://127.0.0.1:8600"
|
||||
prefix: "upstreams"
|
||||
skip_keys:
|
||||
- "upstreams/unused_api/"
|
||||
timeout:
|
||||
connect: 1000
|
||||
read: 1000
|
||||
wait: 60
|
||||
weight: 1
|
||||
fetch_interval: 1
|
||||
keepalive: true
|
||||
default_service:
|
||||
host: "127.0.0.1"
|
||||
port: 20999
|
||||
metadata:
|
||||
fail_timeout: 1
|
||||
weight: 1
|
||||
max_fails: 1
|
||||
_EOC_
|
||||
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: prepare consul kv register nodes
|
||||
--- config
|
||||
location /consul1 {
|
||||
rewrite ^/consul1/(.*) /v1/kv/$1 break;
|
||||
proxy_pass http://127.0.0.1:8500;
|
||||
}
|
||||
|
||||
location /consul2 {
|
||||
rewrite ^/consul2/(.*) /v1/kv/$1 break;
|
||||
proxy_pass http://127.0.0.1:8600;
|
||||
}
|
||||
--- pipelined_requests eval
|
||||
[
|
||||
"DELETE /consul1/upstreams/webpages/?recurse=true",
|
||||
"DELETE /consul2/upstreams/webpages/?recurse=true",
|
||||
"PUT /consul1/upstreams/webpages/127.0.0.1:30511\n" . "{\"weight\": 1, \"max_fails\": 2, \"fail_timeout\": 1}",
|
||||
"PUT /consul1/upstreams/webpages/127.0.0.1:30512\n" . "{\"weight\": 1, \"max_fails\": 2, \"fail_timeout\": 1}",
|
||||
"PUT /consul2/upstreams/webpages/127.0.0.1:30513\n" . "{\"weight\": 1, \"max_fails\": 2, \"fail_timeout\": 1}",
|
||||
"PUT /consul2/upstreams/webpages/127.0.0.1:30514\n" . "{\"weight\": 1, \"max_fails\": 2, \"fail_timeout\": 1}",
|
||||
]
|
||||
--- response_body eval
|
||||
["true", "true", "true", "true", "true", "true"]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: test consul server 1
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: http://127.0.0.1:8500/v1/kv/upstreams/webpages/
|
||||
discovery_type: consul_kv
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response eval
|
||||
qr/server [1-2]/
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 3: test consul server 2
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: http://127.0.0.1:8600/v1/kv/upstreams/webpages/
|
||||
discovery_type: consul_kv
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response eval
|
||||
qr/server [3-4]/
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 4: test mini consul_kv config
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
consul_kv:
|
||||
servers:
|
||||
- "http://127.0.0.1:8500"
|
||||
- "http://127.0.0.1:6500"
|
||||
#END
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: http://127.0.0.1:8500/v1/kv/upstreams/webpages/
|
||||
discovery_type: consul_kv
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response eval
|
||||
qr/server [1-2]/
|
||||
--- ignore_error_log
|
||||
|
||||
|
||||
|
||||
=== TEST 5: test invalid service name
|
||||
sometimes the consul key maybe deleted by mistake
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: http://127.0.0.1:8600/v1/kv/upstreams/deleted_keys/
|
||||
discovery_type: consul_kv
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response_like
|
||||
missing consul_kv services
|
||||
--- ignore_error_log
|
||||
|
||||
|
||||
|
||||
=== TEST 6: test skip keys
|
||||
skip some keys, return default nodes, get response: missing consul_kv services
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
consul_kv:
|
||||
servers:
|
||||
- "http://127.0.0.1:8600"
|
||||
prefix: "upstreams"
|
||||
skip_keys:
|
||||
- "upstreams/webpages/"
|
||||
default_service:
|
||||
host: "127.0.0.1"
|
||||
port: 20999
|
||||
metadata:
|
||||
fail_timeout: 1
|
||||
weight: 1
|
||||
max_fails: 1
|
||||
#END
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: http://127.0.0.1:8600/v1/kv/upstreams/webpages/
|
||||
discovery_type: consul_kv
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response_like
|
||||
missing consul_kv services
|
||||
--- ignore_error_log
|
342
CloudronPackages/APISIX/apisix-source/t/discovery/stream/dns.t
Normal file
342
CloudronPackages/APISIX/apisix-source/t/discovery/stream/dns.t
Normal file
@@ -0,0 +1,342 @@
|
||||
#
|
||||
# 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';
|
||||
|
||||
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
|
||||
enable_admin: false
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery: # service discovery center
|
||||
dns:
|
||||
servers:
|
||||
- "127.0.0.1:1053"
|
||||
_EOC_
|
||||
|
||||
$block->set_value("yaml_config", $yaml_config);
|
||||
}
|
||||
|
||||
if ($block->apisix_yaml) {
|
||||
my $upstream = <<_EOC_;
|
||||
stream_routes:
|
||||
- id: 1
|
||||
server_port: 1985
|
||||
upstream_id: 1
|
||||
#END
|
||||
_EOC_
|
||||
|
||||
$block->set_value("apisix_yaml", $block->apisix_yaml . $upstream);
|
||||
}
|
||||
|
||||
if (!$block->stream_request) {
|
||||
$block->set_value("stream_request", "GET /hello HTTP/1.0\r\nHost: 127.0.0.1:1985\r\n\r\n");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: default port to 53
|
||||
--- log_level: debug
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
enable_admin: false
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery: # service discovery center
|
||||
dns:
|
||||
servers:
|
||||
- "127.0.0.1"
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: sd.test.local
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- error_log
|
||||
connect to 127.0.0.1:53
|
||||
|
||||
|
||||
|
||||
=== TEST 2: A
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "sd.test.local:1980"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- grep_error_log eval
|
||||
qr/upstream nodes: \{[^}]+\}/
|
||||
--- grep_error_log_out eval
|
||||
qr/upstream nodes: \{("127.0.0.1:1980":1,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":1)\}/
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 3: AAAA
|
||||
--- listen_ipv6
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "ipv6.sd.test.local:1980"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- stream_response_like
|
||||
hello world
|
||||
--- grep_error_log eval
|
||||
qr/proxy request to \S+/
|
||||
--- grep_error_log_out
|
||||
proxy request to [0:0:0:0:0:0:0:1]:1980
|
||||
|
||||
|
||||
|
||||
=== TEST 4: prefer A to AAAA
|
||||
--- listen_ipv6
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "mix.sd.test.local:1980"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- stream_response_like
|
||||
hello world
|
||||
--- grep_error_log eval
|
||||
qr/proxy request to \S+/
|
||||
--- grep_error_log_out
|
||||
proxy request to 127.0.0.1:1980
|
||||
|
||||
|
||||
|
||||
=== TEST 5: no /etc/hosts
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: test.com
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- error_log
|
||||
failed to query the DNS server
|
||||
|
||||
|
||||
|
||||
=== TEST 6: no /etc/resolv.conf
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
enable_admin: false
|
||||
enable_resolv_search_option: false
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery: # service discovery center
|
||||
dns:
|
||||
servers:
|
||||
- "127.0.0.1:1053"
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: apisix
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- error_log
|
||||
failed to query the DNS server
|
||||
|
||||
|
||||
|
||||
=== TEST 7: SRV
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "srv.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- grep_error_log eval
|
||||
qr/upstream nodes: \{[^}]+\}/
|
||||
--- grep_error_log_out eval
|
||||
qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 8: SRV (RFC 2782 style)
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "_sip._tcp.srv.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- grep_error_log eval
|
||||
qr/upstream nodes: \{[^}]+\}/
|
||||
--- grep_error_log_out eval
|
||||
qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 9: SRV (different port)
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "port.srv.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- grep_error_log eval
|
||||
qr/upstream nodes: \{[^}]+\}/
|
||||
--- grep_error_log_out eval
|
||||
qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1981":20|"127.0.0.2:1981":20,"127.0.0.1:1980":60)\}/
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 10: SRV (zero weight)
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "zero-weight.srv.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- grep_error_log eval
|
||||
qr/upstream nodes: \{[^}]+\}/
|
||||
--- grep_error_log_out eval
|
||||
qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":1|"127.0.0.2:1980":1,"127.0.0.1:1980":60)\}/
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 11: SRV (split weight)
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "split-weight.srv.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- grep_error_log eval
|
||||
qr/upstream nodes: \{[^}]+\}/
|
||||
--- grep_error_log_out eval
|
||||
qr/upstream nodes: \{(,?"127.0.0.(1:1980":200|3:1980":1|4:1980":1)){3}\}/
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 12: SRV (priority)
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "priority.srv.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- stream_response_like
|
||||
hello world
|
||||
--- error_log
|
||||
connect() failed
|
||||
--- grep_error_log eval
|
||||
qr/proxy request to \S+/
|
||||
--- grep_error_log_out
|
||||
proxy request to 127.0.0.1:1979
|
||||
proxy request to 127.0.0.2:1980
|
||||
|
||||
|
||||
|
||||
=== TEST 13: prefer SRV than A
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "srv-a.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- error_log
|
||||
proxy request to 127.0.0.1:1980
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 14: SRV (port is 0)
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "zero.srv.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- error_log
|
||||
no valid upstream node
|
||||
|
||||
|
||||
|
||||
=== TEST 15: SRV (override port)
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "port.srv.test.local:1980"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- grep_error_log eval
|
||||
qr/upstream nodes: \{[^}]+\}/
|
||||
--- grep_error_log_out eval
|
||||
qr/upstream nodes: \{("127.0.0.1:1980":60,"127.0.0.2:1980":20|"127.0.0.2:1980":20,"127.0.0.1:1980":60)\}/
|
||||
--- stream_response_like
|
||||
hello world
|
||||
|
||||
|
||||
|
||||
=== TEST 16: prefer A than SRV when A is ahead of SRV in config.yaml
|
||||
--- yaml_config
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
enable_admin: false
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
dns:
|
||||
servers:
|
||||
- "127.0.0.1:1053"
|
||||
order:
|
||||
- A
|
||||
- SRV
|
||||
--- apisix_yaml
|
||||
upstreams:
|
||||
- service_name: "srv-a.test.local"
|
||||
discovery_type: dns
|
||||
type: roundrobin
|
||||
id: 1
|
||||
--- error_log
|
||||
no valid upstream node
|
@@ -0,0 +1,95 @@
|
||||
#
|
||||
# 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';
|
||||
|
||||
repeat_each(1);
|
||||
log_level('info');
|
||||
no_root_location();
|
||||
no_shuffle();
|
||||
|
||||
our $yaml_config = <<_EOC_;
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
eureka:
|
||||
host:
|
||||
- "http://127.0.0.1:8761"
|
||||
prefix: "/eureka/"
|
||||
fetch_interval: 10
|
||||
weight: 80
|
||||
timeout:
|
||||
connect: 1500
|
||||
send: 1500
|
||||
read: 1500
|
||||
_EOC_
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my ($block) = @_;
|
||||
|
||||
if (!$block->stream_request) {
|
||||
$block->set_value("stream_request", "GET /eureka/apps/APISIX-EUREKA HTTP/1.1\r\nHost: 127.0.0.1:1985\r\nConnection: close\r\n\r\n");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: get APISIX-EUREKA info from EUREKA
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
-
|
||||
id: 1
|
||||
server_port: 1985
|
||||
upstream:
|
||||
service_name: APISIX-EUREKA
|
||||
discovery_type: eureka
|
||||
type: roundrobin
|
||||
|
||||
#END
|
||||
--- stream_response_like
|
||||
.*<name>APISIX-EUREKA</name>.*
|
||||
--- error_log
|
||||
use config_provider: yaml
|
||||
default_weight:80.
|
||||
fetch_interval:10.
|
||||
eureka uri:http://127.0.0.1:8761/eureka/.
|
||||
connect_timeout:1500, send_timeout:1500, read_timeout:1500.
|
||||
|
||||
|
||||
|
||||
=== TEST 2: error service_name name
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
-
|
||||
id: 1
|
||||
server_port: 1985
|
||||
upstream:
|
||||
service_name: APISIX-EUREKA-DEMO
|
||||
discovery_type: eureka
|
||||
type: roundrobin
|
||||
|
||||
#END
|
||||
--- error_log eval
|
||||
qr/.* no valid upstream node.*/
|
@@ -0,0 +1,92 @@
|
||||
#
|
||||
# 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';
|
||||
|
||||
repeat_each(1);
|
||||
log_level('info');
|
||||
worker_connections(256);
|
||||
no_root_location();
|
||||
no_shuffle();
|
||||
workers(4);
|
||||
|
||||
our $yaml_config = <<_EOC_;
|
||||
apisix:
|
||||
node_listen: 1984
|
||||
deployment:
|
||||
role: data_plane
|
||||
role_data_plane:
|
||||
config_provider: yaml
|
||||
discovery:
|
||||
nacos:
|
||||
host:
|
||||
- "http://127.0.0.1:8858"
|
||||
prefix: "/nacos/v1/"
|
||||
fetch_interval: 1
|
||||
weight: 1
|
||||
timeout:
|
||||
connect: 2000
|
||||
send: 2000
|
||||
read: 5000
|
||||
|
||||
_EOC_
|
||||
|
||||
add_block_preprocessor(sub {
|
||||
my ($block) = @_;
|
||||
|
||||
if (!$block->stream_request) {
|
||||
$block->set_value("stream_request", "GET /hello HTTP/1.1\r\nHost: 127.0.0.1:1985\r\nConnection: close\r\n\r\n");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: get APISIX-NACOS info from NACOS - no auth
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: APISIX-NACOS
|
||||
discovery_type: nacos
|
||||
type: roundrobin
|
||||
#END
|
||||
--- stream_response eval
|
||||
qr/server [1-2]/
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 2: error service_name name - no auth
|
||||
--- yaml_config eval: $::yaml_config
|
||||
--- apisix_yaml
|
||||
stream_routes:
|
||||
- server_addr: 127.0.0.1
|
||||
server_port: 1985
|
||||
id: 1
|
||||
upstream:
|
||||
service_name: APISIX-NACOS-DEMO
|
||||
discovery_type: nacos
|
||||
type: roundrobin
|
||||
#END
|
||||
--- error_log
|
||||
no valid upstream node
|
Reference in New Issue
Block a user