Skip to content

Commit

Permalink
feat(skywalking): allow destory and configure report interval for rep…
Browse files Browse the repository at this point in the history
…orter (apache#3925)

Fix apache#2895

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored and defp committed Apr 3, 2021
1 parent 54af10d commit f9c4986
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
17 changes: 17 additions & 0 deletions apisix/plugins/skywalking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ local metadata_schema = {
type = "string",
default = "http://127.0.0.1:12800",
},
report_interval = {
type = "integer",
},
},
additionalProperties = false,
}
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion docs/en/latest/plugins/skywalking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 2 additions & 1 deletion docs/zh/latest/plugins/skywalking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 客户端内置的值 | 上报时间间隔,单位是秒|

配置示例:

Expand Down
54 changes: 53 additions & 1 deletion t/admin/plugins-reload.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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

0 comments on commit f9c4986

Please sign in to comment.