Skip to content

Commit

Permalink
add set hostname to service_instance_name
Browse files Browse the repository at this point in the history
  • Loading branch information
polaris-liu committed Sep 1, 2020
1 parent db223f2 commit 8a3f01c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions kong/plugins/skywalking/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ local SkyWalkingHandler = {
function SkyWalkingHandler:access(config)
kong.log.info('access phase of skywalking plugin')
kong.ctx.plugin.skywalking_sample = false
-- set hostname to service_instance_name
local hostname = os.getenv("HOSTNAME")
if config.cluster_flag and hostname ~= nil then
config.service_instance_name = hostname
end
if config.sample_ratio == 1 or math.random() * 10000 < config.sample_ratio then
kong.ctx.plugin.skywalking_sample = true
sw_client:startBackendTimer(config)
Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/skywalking/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ return {
fields = {
{ backend_http_uri = typedefs.url({ required = true }) },
{ service_name = { type = "string", default = "Kong Service", }, },
{ cluster_flag = { type = "boolean", default = false }, },
{ service_instance_name = { type = "string", default = "Kong Service Instance", }, },
{ sample_ratio = { type = "number", between = { 1 , 10000 }, default = 1 }, },
{ sample_ratio = { type = "number", between = { 1 , 10000 }, default = 1 }, },
},
},
},
Expand Down

0 comments on commit 8a3f01c

Please sign in to comment.