Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
moonming committed May 27, 2020
1 parent 532bad0 commit 4100046
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 60 deletions.
1 change: 1 addition & 0 deletions apisix/plugins/skywalking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ end


function _M.rewrite(conf, ctx)
core.log.debug("rewrite phase of skywalking plugin")
ctx.skywalking_sample = false
if conf.sample_ratio == 1 or math.random() < conf.sample_ratio then
ctx.skywalking_sample = true
Expand Down
2 changes: 2 additions & 0 deletions apisix/plugins/skywalking/tracer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ function _M.start(ctx, endpoint, upstream_name)
ctx.sw_tracing_context = context
ctx.sw_entry_span = entry_span
ctx.sw_exit_span = exit_span

core.log.debug("push data into skywalking context")
end

function _M.finish(ctx)
Expand Down
70 changes: 10 additions & 60 deletions t/plugin/skywalking.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ log_level("debug");
run_tests;

__DATA__
=== TEST 5: add plugin
=== TEST 1: add plugin
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -93,10 +94,10 @@ GET /t
passed
--- no_error_log
[error]
--- LAST
=== TEST 6: tiger skywalking
=== TEST 2: tiger skywalking
--- request
GET /opentracing
--- response_body
Expand All @@ -110,7 +111,7 @@ qr/skywalking service Instance registered, service instance id: 1/
=== TEST 7: change sample ratio
=== TEST 3: change sample ratio
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -170,17 +171,17 @@ passed
=== TEST 8: not tiger skywalking
=== TEST 4: not tiger skywalking
--- request
GET /opentracing
--- response_body
opentracing
--- no_error_log
report2endpoint ok
push data into skywalking context
=== TEST 9: disabled
=== TEST 5: disabled
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -232,61 +233,10 @@ passed
=== TEST 10: not tiger skywalking
=== TEST 6: not tiger skywalking
--- request
GET /opentracing
--- response_body
opentracing
--- no_error_log
report2endpoint ok
=== TEST 11: set plugin with external ip address
--- 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
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/opentracing"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 12: tiger skywalking
--- request
GET /opentracing
--- response_body
opentracing
--- grep_error_log eval
qr/\[info\].*/
--- grep_error_log_out eval
qr{report2endpoint ok}
rewrite phase of skywalking plugin

0 comments on commit 4100046

Please sign in to comment.