Skip to content
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

test cases: add test tests for skywalking. #1621

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions apisix/plugins/skywalking/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ local function register_service_instance(conf, service_id)
for _, result in ipairs(register_results) do
if result.key == service_instance_name then
instance_id = result.value
core.log.debug("skywalking service Instance registered, ",
"service instance id: ", instance_id)
end
end

Expand All @@ -136,7 +134,7 @@ local function ping(endpoint)
ngx.now() * 1000)

local httpc = http.new()
local _, err = httpc:request_uri(endpoint .. '/v2/instance/heartbeat', {
local res, err = httpc:request_uri(endpoint .. '/v2/instance/heartbeat', {
method = "POST",
body = core.json.encode(ping_pkg),
headers = {
Expand All @@ -146,6 +144,8 @@ local function ping(endpoint)

if err then
core.log.error("skywalking agent ping failed, err: ", err)
else
core.log.debug(res.body)
end
end

Expand Down Expand Up @@ -173,6 +173,7 @@ local function report_traces(endpoint)
break
else
count = count + 1
core.log.debug(res.body)
end
else
core.log.error("skywalking segment report failed, err: ", err)
Expand All @@ -197,11 +198,16 @@ function _M.heartbeat(conf)
return
end

core.log.debug("skywalking service registered, ",
"service id: ", service_id)

local service_instance_id = register_service_instance(conf, service_id)
if not service_instance_id then
return
end

core.log.debug("skywalking service Instance registered, ",
"service instance id: ", service_instance_id)
report_traces(conf.endpoint)
ping(conf.endpoint)
end
Expand Down
6 changes: 5 additions & 1 deletion t/lib/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ function _M.mock_skywalking_v2_instance_register()
end

function _M.mock_skywalking_v2_instance_heartbeat()
ngx.say('ok')
ngx.say('skywalking heartbeat ok')
end

function _M.mock_skywalking_v2_segments()
ngx.say('skywalking segments ok')
end

function _M.mock_zipkin()
Expand Down
94 changes: 90 additions & 4 deletions t/plugin/skywalking.t
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,19 @@ qr/skywalking service Instance registered, service instance id: 1/



=== TEST 3: change sample ratio
=== 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 {
Expand Down Expand Up @@ -171,7 +183,7 @@ passed



=== TEST 4: not tiger skywalking
=== TEST 5: not tiger skywalking
--- request
GET /opentracing
--- response_body
Expand All @@ -181,7 +193,7 @@ push data into skywalking context



=== TEST 5: disabled
=== TEST 6: disabled
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -233,10 +245,84 @@ passed



=== TEST 6: not tiger skywalking
=== 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