This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c976b5  feat(skywalking):  allow destory and configure report 
interval for reporter (#3925)
7c976b5 is described below

commit 7c976b50ab02219bbaccb0602d5357adbba20c32
Author: 罗泽轩 <spacewander...@gmail.com>
AuthorDate: Tue Mar 30 09:54:18 2021 +0800

    feat(skywalking):  allow destory and configure report interval for reporter 
(#3925)
    
    Fix #2895
    
    Signed-off-by: spacewander <spacewander...@gmail.com>
---
 apisix/plugins/skywalking.lua        | 17 ++++++++++++
 docs/en/latest/plugins/skywalking.md |  3 +-
 docs/zh/latest/plugins/skywalking.md |  3 +-
 t/admin/plugins-reload.t             | 54 +++++++++++++++++++++++++++++++++++-
 4 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/apisix/plugins/skywalking.lua b/apisix/plugins/skywalking.lua
index c0f74f3..5d6553a 100644
--- a/apisix/plugins/skywalking.lua
+++ b/apisix/plugins/skywalking.lua
@@ -39,6 +39,9 @@ local metadata_schema = {
             type = "string",
             default = "http://127.0.0.1:12800";,
         },
+        report_interval = {
+            type = "integer",
+        },
     },
     additionalProperties = false,
 }
@@ -127,8 +130,22 @@ function _M.init()
     metadata_shdict:set('serviceInstanceName', 
local_plugin_info.service_instance_name)
 
     local sk_cli = require("skywalking.client")
+    if local_plugin_info.report_interval then
+        sk_cli.backendTimerDelay = local_plugin_info.report_interval
+    end
+
     sk_cli:startBackendTimer(local_plugin_info.endpoint_addr)
 end
 
 
+function _M.destroy()
+    if process.type() ~= "worker" then
+        return
+    end
+
+    local sk_cli = require("skywalking.client")
+    sk_cli:destroyBackendTimer()
+end
+
+
 return _M
diff --git a/docs/en/latest/plugins/skywalking.md 
b/docs/en/latest/plugins/skywalking.md
index 6475fad..b496b84 100644
--- a/docs/en/latest/plugins/skywalking.md
+++ b/docs/en/latest/plugins/skywalking.md
@@ -91,7 +91,8 @@ We can set the endpoint by specified the configuration in 
`conf/config.yaml`.
 | ------------ | ------ | -------- | 
-------------------------------------------------------------------- |
 | service_name | string | "APISIX" | service name for skywalking reporter      
                           |
 |service_instance_name|string|"APISIX Instance Name" | service instance name 
for skywalking reporter |
-| endpoint     | string | "http://127.0.0.1:12800"; | the http endpoint of 
Skywalking, for example: http://127.0.0.1:12800 |
+| endpoint_addr| string | "http://127.0.0.1:12800"; | the http endpoint of 
Skywalking, for example: http://127.0.0.1:12800 |
+| report_interval| integer | use the value in the skywalking client library | 
the report interval, in seconds |
 
 Here is an example:
 
diff --git a/docs/zh/latest/plugins/skywalking.md 
b/docs/zh/latest/plugins/skywalking.md
index 888a0d3..ec5acb6 100644
--- a/docs/zh/latest/plugins/skywalking.md
+++ b/docs/zh/latest/plugins/skywalking.md
@@ -95,7 +95,8 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1  -H 
'X-API-KEY: edd1c9f034335f1
 | ------------ | ------ | -------- | 
----------------------------------------------------- |
 | service_name | string |  "APISIX" | skywalking 上报的 service 名称                
                 |
 |service_instance_name|string| "APISIX Instance Name" | skywalking 上报的 service 
实例名 |
-| endpoint     | string | "http://127.0.0.1:12800"; | Skywalking 的 HTTP 
endpoint 地址,例如:http://127.0.0.1:12800 |
+| endpoint_addr| string | "http://127.0.0.1:12800"; | Skywalking 的 HTTP 
endpoint 地址,例如:http://127.0.0.1:12800 |
+| report_interval| integer | 使用 skywalking 客户端内置的值 | 上报时间间隔,单位是秒|
 
 配置示例:
 
diff --git a/t/admin/plugins-reload.t b/t/admin/plugins-reload.t
index e46b25a..52fb419 100644
--- a/t/admin/plugins-reload.t
+++ b/t/admin/plugins-reload.t
@@ -26,7 +26,9 @@ workers(2);
 add_block_preprocessor(sub {
     my ($block) = @_;
 
-    $block->set_value("no_error_log", "[error]");
+    if (!defined $block->no_error_log) {
+        $block->set_value("no_error_log", "[error]");
+    }
 
     $block;
 });
@@ -249,3 +251,53 @@ GET /t
 404
 done
 200
+
+
+
+=== TEST 5: reload plugins to disable skywalking
+--- yaml_config
+apisix:
+  node_listen: 1984
+  admin_key: null
+plugins:
+  - skywalking
+plugin_attr:
+  skywalking:
+    service_name: APISIX
+    service_instance_name: "APISIX Instance Name"
+    endpoint_addr: http://127.0.0.1:12801
+    report_interval: 1
+--- config
+location /t {
+    content_by_lua_block {
+        local core = require "apisix.core"
+        ngx.sleep(1.2)
+        local t = require("lib.test_admin").test
+
+        local data = [[
+apisix:
+  node_listen: 1984
+  admin_key: null
+plugins:
+  - prometheus
+        ]]
+        require("lib.test_admin").set_config_yaml(data)
+
+        local code, _, org_body = t('/apisix/admin/plugins/reload',
+                                    ngx.HTTP_PUT)
+
+        ngx.say(org_body)
+
+        ngx.sleep(2)
+    }
+}
+--- request
+GET /t
+--- response_body
+done
+--- no_error_log
+[alert]
+--- grep_error_log eval
+qr/Instance report fails/
+--- grep_error_log_out
+Instance report fails

Reply via email to