You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/06/02 04:25:04 UTC
[incubator-apisix] branch master updated: test: added test tests
for skywalking. (#1621)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 82f85e5 test: added test tests for skywalking. (#1621)
82f85e5 is described below
commit 82f85e59465c80e27879d9985461d60fe4f77721
Author: Wen Ming <mo...@gmail.com>
AuthorDate: Tue Jun 2 12:24:56 2020 +0800
test: added test tests for skywalking. (#1621)
---
apisix/plugins/skywalking/client.lua | 12 +++--
t/lib/server.lua | 6 ++-
t/plugin/skywalking.t | 94 ++++++++++++++++++++++++++++++++++--
3 files changed, 104 insertions(+), 8 deletions(-)
diff --git a/apisix/plugins/skywalking/client.lua b/apisix/plugins/skywalking/client.lua
index 676735c..f83a6e3 100644
--- a/apisix/plugins/skywalking/client.lua
+++ b/apisix/plugins/skywalking/client.lua
@@ -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
@@ -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 = {
@@ -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
@@ -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)
@@ -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
diff --git a/t/lib/server.lua b/t/lib/server.lua
index 32a419c..fe82408 100644
--- a/t/lib/server.lua
+++ b/t/lib/server.lua
@@ -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()
diff --git a/t/plugin/skywalking.t b/t/plugin/skywalking.t
index 7e448be..fef7b46 100644
--- a/t/plugin/skywalking.t
+++ b/t/plugin/skywalking.t
@@ -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 {
@@ -171,7 +183,7 @@ passed
-=== TEST 4: not tiger skywalking
+=== TEST 5: not tiger skywalking
--- request
GET /opentracing
--- response_body
@@ -181,7 +193,7 @@ push data into skywalking context
-=== TEST 5: disabled
+=== TEST 6: disabled
--- config
location /t {
content_by_lua_block {
@@ -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