mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-15 09:21:26 +08:00
329 lines
9.2 KiB
Perl
329 lines
9.2 KiB
Perl
#
|
|
# 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.
|
|
#
|
|
|
|
BEGIN {
|
|
if ($ENV{TEST_NGINX_CHECK_LEAK}) {
|
|
$SkipReason = "unavailable for the hup tests";
|
|
|
|
} else {
|
|
$ENV{TEST_NGINX_USE_HUP} = 1;
|
|
undef $ENV{TEST_NGINX_USE_STAP};
|
|
}
|
|
}
|
|
|
|
use t::APISIX 'no_plan';
|
|
|
|
repeat_each(1);
|
|
no_long_string();
|
|
no_root_location();
|
|
log_level("debug");
|
|
run_tests;
|
|
|
|
__DATA__
|
|
|
|
=== TEST 1: add plugin
|
|
--- config
|
|
location /t {
|
|
content_by_lua_block {
|
|
local t = require("lib.test_admin").test
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
ngx.HTTP_PUT,
|
|
[[{
|
|
"plugins": {
|
|
"skywalking": {
|
|
"endpoint": "http://127.0.0.1:1982/mock_skywalking",
|
|
"sample_ratio": 1,
|
|
"service_name": "APISIX"
|
|
}
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
}]],
|
|
[[{
|
|
"node": {
|
|
"value": {
|
|
"plugins": {
|
|
"skywalking": {
|
|
"endpoint": "http://127.0.0.1:1982/mock_skywalking",
|
|
"sample_ratio": 1,
|
|
"service_name":"APISIX"
|
|
}
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
},
|
|
"key": "/apisix/routes/1"
|
|
},
|
|
"action": "set"
|
|
}]]
|
|
)
|
|
|
|
if code >= 300 then
|
|
ngx.status = code
|
|
end
|
|
ngx.say(body)
|
|
}
|
|
}
|
|
--- request
|
|
GET /t
|
|
--- response_body
|
|
passed
|
|
--- no_error_log
|
|
[error]
|
|
|
|
|
|
|
|
=== TEST 2: tiger skywalking
|
|
--- request
|
|
GET /opentracing
|
|
--- response_body
|
|
opentracing
|
|
--- no_error_log
|
|
[error]
|
|
--- grep_error_log eval
|
|
qr/skywalking service Instance registered, service instance id: \d+/
|
|
--- grep_error_log_out eval
|
|
qr/skywalking service Instance registered, service instance id: 1/
|
|
|
|
|
|
|
|
=== TEST 3: test heartbeat
|
|
--- request
|
|
GET /opentracing
|
|
--- response_body
|
|
opentracing
|
|
--- no_error_log
|
|
[error]
|
|
--- error_log
|
|
skywalking heartbeat ok
|
|
|
|
|
|
|
|
=== TEST 4: change sample ratio
|
|
--- config
|
|
location /t {
|
|
content_by_lua_block {
|
|
local t = require("lib.test_admin").test
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
ngx.HTTP_PUT,
|
|
[[{
|
|
"plugins": {
|
|
"skywalking": {
|
|
"endpoint": "http://127.0.0.1:1982/mock_skywalking",
|
|
"sample_ratio": 0.00001
|
|
}
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
}]],
|
|
[[{
|
|
"node": {
|
|
"value": {
|
|
"plugins": {
|
|
"skywalking": {
|
|
"endpoint": "http://127.0.0.1:1982/mock_skywalking",
|
|
"sample_ratio": 0.00001
|
|
}
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
},
|
|
"key": "/apisix/routes/1"
|
|
},
|
|
"action": "set"
|
|
}]]
|
|
)
|
|
|
|
if code >= 300 then
|
|
ngx.status = code
|
|
end
|
|
ngx.say(body)
|
|
}
|
|
}
|
|
--- request
|
|
GET /t
|
|
--- response_body
|
|
passed
|
|
--- no_error_log
|
|
[error]
|
|
|
|
|
|
|
|
=== TEST 5: not tiger skywalking
|
|
--- request
|
|
GET /opentracing
|
|
--- response_body
|
|
opentracing
|
|
--- no_error_log
|
|
push data into skywalking context
|
|
|
|
|
|
|
|
=== TEST 6: disabled
|
|
--- config
|
|
location /t {
|
|
content_by_lua_block {
|
|
local t = require("lib.test_admin").test
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
ngx.HTTP_PUT,
|
|
[[{
|
|
"plugins": {
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
}]],
|
|
[[{
|
|
"node": {
|
|
"value": {
|
|
"plugins": {
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
},
|
|
"key": "/apisix/routes/1"
|
|
},
|
|
"action": "set"
|
|
}]]
|
|
)
|
|
|
|
if code >= 300 then
|
|
ngx.status = code
|
|
end
|
|
ngx.say(body)
|
|
}
|
|
}
|
|
--- request
|
|
GET /t
|
|
--- response_body
|
|
passed
|
|
--- no_error_log
|
|
[error]
|
|
|
|
|
|
|
|
=== TEST 7: not tiger skywalking
|
|
--- request
|
|
GET /opentracing
|
|
--- response_body
|
|
opentracing
|
|
--- no_error_log
|
|
rewrite phase of skywalking plugin
|
|
|
|
|
|
|
|
=== TEST 8: enable skywalking
|
|
--- config
|
|
location /t {
|
|
content_by_lua_block {
|
|
local t = require("lib.test_admin").test
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
ngx.HTTP_PUT,
|
|
[[{
|
|
"plugins": {
|
|
"skywalking": {
|
|
"endpoint": "http://127.0.0.1:1982/mock_skywalking",
|
|
"sample_ratio": 1,
|
|
"service_name": "APISIX"
|
|
}
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
}]],
|
|
[[{
|
|
"node": {
|
|
"value": {
|
|
"plugins": {
|
|
"skywalking": {
|
|
"endpoint": "http://127.0.0.1:1982/mock_skywalking",
|
|
"sample_ratio": 1,
|
|
"service_name":"APISIX"
|
|
}
|
|
},
|
|
"upstream": {
|
|
"nodes": {
|
|
"127.0.0.1:1980": 1
|
|
},
|
|
"type": "roundrobin"
|
|
},
|
|
"uri": "/opentracing"
|
|
},
|
|
"key": "/apisix/routes/1"
|
|
},
|
|
"action": "set"
|
|
}]]
|
|
)
|
|
|
|
if code >= 300 then
|
|
ngx.status = code
|
|
end
|
|
ngx.say(body)
|
|
}
|
|
}
|
|
--- request
|
|
GET /t
|
|
--- response_body
|
|
passed
|
|
--- no_error_log
|
|
[error]
|
|
|
|
|
|
|
|
=== TEST 9: test segments report
|
|
--- request
|
|
GET /opentracing
|
|
--- response_body
|
|
opentracing
|
|
--- no_error_log
|
|
[error]
|
|
--- error_log
|
|
skywalking segments reported
|