From 8a3f01c4a403dab499d8a7c611882f0e7c042aae Mon Sep 17 00:00:00 2001 From: "lxy.dev" Date: Tue, 1 Sep 2020 10:59:10 +0800 Subject: [PATCH] add set hostname to service_instance_name --- kong/plugins/skywalking/handler.lua | 5 +++++ kong/plugins/skywalking/schema.lua | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kong/plugins/skywalking/handler.lua b/kong/plugins/skywalking/handler.lua index 6ab3dd8..a8b756a 100644 --- a/kong/plugins/skywalking/handler.lua +++ b/kong/plugins/skywalking/handler.lua @@ -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) diff --git a/kong/plugins/skywalking/schema.lua b/kong/plugins/skywalking/schema.lua index 9ddcfdf..3691eab 100644 --- a/kong/plugins/skywalking/schema.lua +++ b/kong/plugins/skywalking/schema.lua @@ -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 }, }, }, }, },