2020-05-27 17:55:47 +08:00
|
|
|
#
|
|
|
|
# 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';
|
|
|
|
|
2020-11-09 08:12:52 +08:00
|
|
|
add_block_preprocessor(sub {
|
|
|
|
my ($block) = @_;
|
|
|
|
|
|
|
|
my $extra_yaml_config = <<_EOC_;
|
|
|
|
plugins:
|
|
|
|
- skywalking
|
|
|
|
_EOC_
|
|
|
|
|
|
|
|
$block->set_value("extra_yaml_config", $extra_yaml_config);
|
|
|
|
|
2021-07-14 10:56:13 +08:00
|
|
|
my $extra_init_by_lua = <<_EOC_;
|
|
|
|
local sw_tracer = require("skywalking.tracer")
|
|
|
|
local inject = function(mod, name)
|
|
|
|
local old_f = mod[name]
|
|
|
|
mod[name] = function (...)
|
|
|
|
ngx.log(ngx.WARN, "skywalking run ", name)
|
|
|
|
return old_f(...)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
inject(sw_tracer, "start")
|
|
|
|
inject(sw_tracer, "finish")
|
|
|
|
inject(sw_tracer, "prepareForReport")
|
|
|
|
_EOC_
|
|
|
|
|
|
|
|
$block->set_value("extra_init_by_lua", $extra_init_by_lua);
|
|
|
|
|
2020-11-09 08:12:52 +08:00
|
|
|
$block;
|
|
|
|
});
|
|
|
|
|
2020-05-27 17:55:47 +08:00
|
|
|
repeat_each(1);
|
|
|
|
no_long_string();
|
|
|
|
no_root_location();
|
|
|
|
log_level("debug");
|
2020-10-29 15:29:52 +08:00
|
|
|
|
2020-05-27 17:55:47 +08:00
|
|
|
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',
|
2020-10-29 15:29:52 +08:00
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"plugins": {
|
|
|
|
"skywalking": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1980": 1
|
2020-05-27 17:55:47 +08:00
|
|
|
},
|
2020-10-29 15:29:52 +08:00
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/opentracing"
|
2020-05-27 17:55:47 +08:00
|
|
|
}]],
|
|
|
|
[[{
|
|
|
|
"node": {
|
|
|
|
"value": {
|
|
|
|
"plugins": {
|
|
|
|
"skywalking": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"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]
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-08 23:16:22 +08:00
|
|
|
=== TEST 2: trigger skywalking
|
2020-05-27 17:55:47 +08:00
|
|
|
--- request
|
|
|
|
GET /opentracing
|
|
|
|
--- response_body
|
|
|
|
opentracing
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
2020-10-29 15:29:52 +08:00
|
|
|
--- error_log
|
|
|
|
segments reported
|
|
|
|
--- wait: 4
|
2020-05-27 17:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 19:14:56 +08:00
|
|
|
=== TEST 3: change sample ratio
|
2020-05-27 17:55:47 +08:00
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
2020-10-29 15:29:52 +08:00
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"plugins": {
|
|
|
|
"skywalking": {
|
|
|
|
"sample_ratio": 0.00001
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1980": 1
|
2020-05-27 17:55:47 +08:00
|
|
|
},
|
2020-10-29 15:29:52 +08:00
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/opentracing"
|
2020-05-27 17:55:47 +08:00
|
|
|
}]],
|
|
|
|
[[{
|
|
|
|
"node": {
|
|
|
|
"value": {
|
|
|
|
"plugins": {
|
|
|
|
"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]
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 19:14:56 +08:00
|
|
|
=== TEST 4: not trigger skywalking
|
2020-05-27 17:55:47 +08:00
|
|
|
--- request
|
|
|
|
GET /opentracing
|
|
|
|
--- response_body
|
|
|
|
opentracing
|
2020-10-29 15:29:52 +08:00
|
|
|
--- error_log
|
|
|
|
miss sampling, ignore
|
2020-05-27 17:55:47 +08:00
|
|
|
--- no_error_log
|
2020-10-29 15:29:52 +08:00
|
|
|
[error]
|
2020-05-27 17:55:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 19:14:56 +08:00
|
|
|
=== TEST 5: disabled
|
2020-05-27 17:55:47 +08:00
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
2020-10-29 15:29:52 +08:00
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"plugins": {
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1980": 1
|
2020-05-27 17:55:47 +08:00
|
|
|
},
|
2020-10-29 15:29:52 +08:00
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/opentracing"
|
2020-05-27 17:55:47 +08:00
|
|
|
}]],
|
|
|
|
[[{
|
|
|
|
"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]
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 19:14:56 +08:00
|
|
|
=== TEST 6: not trigger skywalking
|
2020-05-27 17:55:47 +08:00
|
|
|
--- request
|
|
|
|
GET /opentracing
|
|
|
|
--- response_body
|
|
|
|
opentracing
|
|
|
|
--- no_error_log
|
|
|
|
rewrite phase of skywalking plugin
|
2020-06-02 12:24:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 19:14:56 +08:00
|
|
|
=== TEST 7: enable skywalking(sample_ratio=1)
|
2020-06-02 12:24:56 +08:00
|
|
|
--- 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": {
|
2020-10-29 15:29:52 +08:00
|
|
|
"sample_ratio": 1
|
2020-06-02 12:24:56 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
},
|
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/opentracing"
|
|
|
|
}]],
|
|
|
|
[[{
|
|
|
|
"node": {
|
|
|
|
"value": {
|
|
|
|
"plugins": {
|
|
|
|
"skywalking": {
|
2020-10-29 15:29:52 +08:00
|
|
|
"sample_ratio": 1
|
2020-06-02 12:24:56 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"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]
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-20 19:14:56 +08:00
|
|
|
=== TEST 8: test segments report
|
2020-06-02 12:24:56 +08:00
|
|
|
--- request
|
|
|
|
GET /opentracing
|
|
|
|
--- response_body
|
|
|
|
opentracing
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
2020-10-29 15:29:52 +08:00
|
|
|
--- wait: 4
|
2021-07-14 10:56:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 9: enable at both global and route levels
|
|
|
|
--- 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": {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
},
|
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/opentracing"
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/global_rules/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"plugins": {
|
|
|
|
"skywalking": {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
return
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 10: run once
|
|
|
|
--- request
|
|
|
|
GET /opentracing
|
|
|
|
--- response_body
|
|
|
|
opentracing
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
--- grep_error_log eval
|
|
|
|
qr/skywalking run \w+/
|
|
|
|
--- grep_error_log_out
|
|
|
|
skywalking run start
|
|
|
|
skywalking run finish
|
|
|
|
skywalking run prepareForReport
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 11: enable at global but disable at route levels
|
|
|
|
--- 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": {
|
|
|
|
"disable": 1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
},
|
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/opentracing"
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/global_rules/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"plugins": {
|
|
|
|
"skywalking": {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
return
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 12: run once
|
|
|
|
--- request
|
|
|
|
GET /opentracing
|
|
|
|
--- response_body
|
|
|
|
opentracing
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
--- grep_error_log eval
|
|
|
|
qr/skywalking run \w+/
|
|
|
|
--- grep_error_log_out
|
|
|
|
skywalking run start
|
|
|
|
skywalking run finish
|
|
|
|
skywalking run prepareForReport
|