From 492f782d9fae719b3a20e0d65c275962bcdcaab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Sun, 6 Mar 2022 19:01:48 +0800 Subject: [PATCH] fix(tracing): should trace request stopped by extern plugin (#6500) --- apisix/plugins/zipkin.lua | 2 +- conf/config-default.yaml | 2 +- t/admin/plugins.t | 2 +- t/debug/debug-mode.t | 2 +- t/plugin/ext-plugin/http-req-call.t | 67 +++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/apisix/plugins/zipkin.lua b/apisix/plugins/zipkin.lua index 361f2c71ddf8..3fafd29f0e2a 100644 --- a/apisix/plugins/zipkin.lua +++ b/apisix/plugins/zipkin.lua @@ -59,7 +59,7 @@ local schema = { local _M = { version = 0.1, - priority = 11011, + priority = 12011, name = plugin_name, schema = schema, } diff --git a/conf/config-default.yaml b/conf/config-default.yaml index f37758ca4797..bfcf1169d031 100644 --- a/conf/config-default.yaml +++ b/conf/config-default.yaml @@ -326,8 +326,8 @@ plugins: # plugin list (sorted by priority) - real-ip # priority: 23000 - client-control # priority: 22000 - proxy-control # priority: 21990 + - zipkin # priority: 12011 - ext-plugin-pre-req # priority: 12000 - - zipkin # priority: 11011 - request-id # priority: 11010 - fault-injection # priority: 11000 - mocking # priority: 10900 diff --git a/t/admin/plugins.t b/t/admin/plugins.t index 67f6a89bcbb7..2cd06c809029 100644 --- a/t/admin/plugins.t +++ b/t/admin/plugins.t @@ -64,8 +64,8 @@ __DATA__ real-ip client-control proxy-control -ext-plugin-pre-req zipkin +ext-plugin-pre-req request-id fault-injection mocking diff --git a/t/debug/debug-mode.t b/t/debug/debug-mode.t index f5b6e359b50a..d2f629d8edff 100644 --- a/t/debug/debug-mode.t +++ b/t/debug/debug-mode.t @@ -43,8 +43,8 @@ done --- error_log loaded plugin and sort by priority: 23000 name: real-ip loaded plugin and sort by priority: 22000 name: client-control +loaded plugin and sort by priority: 12011 name: zipkin loaded plugin and sort by priority: 12000 name: ext-plugin-pre-req -loaded plugin and sort by priority: 11011 name: zipkin loaded plugin and sort by priority: 11010 name: request-id loaded plugin and sort by priority: 11000 name: fault-injection loaded plugin and sort by priority: 10000 name: serverless-pre-function diff --git a/t/plugin/ext-plugin/http-req-call.t b/t/plugin/ext-plugin/http-req-call.t index f965932a97c1..ded020223648 100644 --- a/t/plugin/ext-plugin/http-req-call.t +++ b/t/plugin/ext-plugin/http-req-call.t @@ -579,3 +579,70 @@ X-Resp: foo X-Req: bar Content-Type: text/plain Content-Encoding: + + + +=== TEST 21: trace stopped request +--- config + location /t { + content_by_lua_block { + local json = require("toolkit.json") + local t = require("lib.test_admin") + + local code, message, res = t.test('/apisix/admin/routes/1', + ngx.HTTP_PUT, + [[{ + "uri": "/hello", + "plugins": { + "zipkin": { + "endpoint": "http://127.0.0.1:1980/mock_zipkin", + "sample_ratio": 1 + }, + "ext-plugin-pre-req": { + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + } + }]] + ) + + if code >= 300 then + ngx.status = code + ngx.say(message) + return + end + + ngx.say(message) + } + } +--- response_body +passed + + + +=== TEST 22: hit +--- extra_init_by_lua + local prev_new = require("opentracing.tracer").new + local function new(...) + ngx.log(ngx.WARN, "tracer attached to stopped request") + return prev_new(...) + end + require("opentracing.tracer").new = new +--- request +GET /hello +--- extra_stream_config + server { + listen unix:$TEST_NGINX_HTML_DIR/nginx.sock; + + content_by_lua_block { + local ext = require("lib.ext-plugin") + ext.go({stop = true}) + } + } +--- error_code: 405 +--- error_log +tracer attached to stopped request