Skip to content

Commit

Permalink
fix: allow timer to restart by APISIX (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreemaan-abhishek authored Sep 24, 2024
1 parent 63debcb commit 56e09ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/skywalking/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ local initialized = false
-- After report instance properties successfully, it sends keep alive packages.
function Client:startBackendTimer(backend_http_uri)
initialized = true
self.stopped = false
local metadata_buffer = ngx.shared.tracing_buffer

-- The codes of timer setup is following the OpenResty timer doc
Expand All @@ -42,6 +43,7 @@ function Client:startBackendTimer(backend_http_uri)

check = function(premature)
if not premature and not self.stopped then
log(ngx.INFO, "running timer")
local instancePropertiesSubmitted = metadata_buffer:get('instancePropertiesSubmitted')
if (instancePropertiesSubmitted == nil or instancePropertiesSubmitted == false) then
self:reportServiceInstance(metadata_buffer, backend_http_uri)
Expand Down
34 changes: 34 additions & 0 deletions t/client.t
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,37 @@ true
--- no_error_log
language: lua
Go keepAlive
=== TEST 3: start backend timer then destory then restart backend timer
--- config
location /t {
content_by_lua_block {
local client = require("skywalking.client")
client.backendTimerDelay = 0.1
client:startBackendTimer("http://127.0.0.1:" .. ngx.var.server_port)
ngx.sleep(0.1)
ngx.say('ok')
local ok, err = client:destroyBackendTimer()
if not err then
ngx.say(ok)
else
ngx.say(err)
end
client:startBackendTimer("http://127.0.0.1:" .. ngx.var.server_port)
ngx.sleep(0.1)
ngx.say('ok')
}
}
--- response_body
ok
true
ok
--- grep_error_log: running timer
--- grep_error_log_out
running timer
running timer
running timer

0 comments on commit 56e09ec

Please sign in to comment.