You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/04/30 00:10:18 UTC

[skywalking-kong] branch master updated: to correct peer (#7)

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

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-kong.git


The following commit(s) were added to refs/heads/master by this push:
     new e93667b  to correct peer (#7)
e93667b is described below

commit e93667b02f761308c901f9e3e4a47cd1e0cbb773
Author: Daming <zt...@foxmail.com>
AuthorDate: Fri Apr 30 08:10:12 2021 +0800

    to correct peer (#7)
---
 README.md                                           | 14 +-------------
 kong/plugins/skywalking/handler.lua                 | 21 ++++++++++++++++++++-
 kong/plugins/skywalking/schema.lua                  | 12 +++++-------
 rockspec/kong-plugin-skywalking-0.1.0.rocksepc      |  2 +-
 rockspec/kong-plugin-skywalking-master-0.rockspec   |  2 +-
 .../src/test/resources/expectedData.yaml            |  6 +++---
 6 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/README.md b/README.md
index cee3eea..2ea8293 100644
--- a/README.md
+++ b/README.md
@@ -35,25 +35,13 @@ Restart Kong
 
 2. Enabling & configuring plugin:
 
-Add the plugin to a service:
-
-```bash
-$ curl -i -X POST \
-   --url http://localhost:8001/services/{service_name}/plugins/ \
-   --data 'name=skywalking' \
-   --data 'config.backend_http_uri=http://localhost:12800' \
-   --data 'config.sample_ratio=100' \
-   --data 'config.service_name=kong'
-   --data 'config.service_instance_name=kong-with-skywalking'
-``` 
-
 Add the plugin to global:
 ```bash
 $ curl -X POST --url http://localhost:8001/plugins/ \
    --data 'name=skywalking' \
    --data 'config.backend_http_uri=http://localhost:12800' \
    --data 'config.sample_ratio=100' \
-   --data 'config.service_name=kong'
+   --data 'config.service_name=kong' \
    --data 'config.service_instance_name=kong-with-skywalking'
 ```
 
diff --git a/kong/plugins/skywalking/handler.lua b/kong/plugins/skywalking/handler.lua
index df740ec..688baff 100644
--- a/kong/plugins/skywalking/handler.lua
+++ b/kong/plugins/skywalking/handler.lua
@@ -26,10 +26,12 @@ local SkyWalkingHandler = {
     VERSION = "0.0.1",
 }
 
+
 function SkyWalkingHandler:init_worker()
     require("skywalking.util").set_randomseed()
 end
 
+
 function SkyWalkingHandler:access(config)
     if subsystem == "stream" then
         kong.log.warn("Not supportted to trace \"stream\" request yet.")
@@ -48,10 +50,25 @@ function SkyWalkingHandler:access(config)
             client:startBackendTimer(config.backend_http_uri)
         end
 
-        tracer:start(kong.request.get_forwarded_host())
+        tracer:start(self:get_remote_peer(ngx.ctx.balancer_data))
+    end
+end
+
+
+function SkyWalkingHandler:get_remote_peer(balancer_data)
+    local peer = ''
+    if balancer_data then
+        if balancer_data.host then
+            peer = balancer_data.host
+        else
+            peer = balancer_data.ip
+        end
+        peer = peer .. ':' .. balancer_data.port
     end
+    return peer
 end
 
+
 function SkyWalkingHandler:body_filter(config)
     if ngx.arg[2] and kong.ctx.plugin.skywalking_sample then
         local entrySpan = ngx.ctx.entrySpan
@@ -75,8 +92,10 @@ function SkyWalkingHandler:body_filter(config)
     end
 end
 
+
 function SkyWalkingHandler:log(config)
     tracer:prepareForReport()
 end
 
+
 return SkyWalkingHandler
diff --git a/kong/plugins/skywalking/schema.lua b/kong/plugins/skywalking/schema.lua
index 5f71246..c0e08f0 100644
--- a/kong/plugins/skywalking/schema.lua
+++ b/kong/plugins/skywalking/schema.lua
@@ -20,12 +20,10 @@ local typedefs = require "kong.db.schema.typedefs"
 return {
     name = "skywalking",
     fields = {
-        {
-            consumer = typedefs.no_consumer
-        },
-        {
-            protocols = typedefs.protocols_http
-        },
+        { consumer = typedefs.no_consumer },
+        { service = typedefs.no_service },
+        { route = typedefs.no_route },
+        { protocols = typedefs.protocols_http },
         {
             config = {
                 type = "record",
@@ -66,4 +64,4 @@ return {
         },
     },
     entity_checks = {},
-}
\ No newline at end of file
+}
diff --git a/rockspec/kong-plugin-skywalking-0.1.0.rocksepc b/rockspec/kong-plugin-skywalking-0.1.0.rocksepc
index 7d2d65d..3b667f4 100644
--- a/rockspec/kong-plugin-skywalking-0.1.0.rocksepc
+++ b/rockspec/kong-plugin-skywalking-0.1.0.rocksepc
@@ -12,7 +12,7 @@ description = {
 }
 
 dependencies = {
-   "skywalking-nginx-lua >= 0.4-1"
+   "skywalking-nginx-lua >= 0.5.0"
 }
 
 build = {
diff --git a/rockspec/kong-plugin-skywalking-master-0.rockspec b/rockspec/kong-plugin-skywalking-master-0.rockspec
index d6e1e6f..7e482d1 100644
--- a/rockspec/kong-plugin-skywalking-master-0.rockspec
+++ b/rockspec/kong-plugin-skywalking-master-0.rockspec
@@ -12,7 +12,7 @@ description = {
 }
 
 dependencies = {
-   "skywalking-nginx-lua >= master"
+   "skywalking-nginx-lua >= 0.5.0"
 }
 
 build = {
diff --git a/test/e2e/e2e-test-kong/src/test/resources/expectedData.yaml b/test/e2e/e2e-test-kong/src/test/resources/expectedData.yaml
index a737b33..43f6dac 100644
--- a/test/e2e/e2e-test-kong/src/test/resources/expectedData.yaml
+++ b/test/e2e/e2e-test-kong/src/test/resources/expectedData.yaml
@@ -32,7 +32,7 @@ segmentItems:
             endTime: gt 0
             componentId: '6001'
             spanType: Exit
-            peer: localhost
+            peer: 'mockbin.org:80'
             skipAnalysis: 'false'
           - operationName: "/backend"
             operationId: '0'
@@ -56,7 +56,7 @@ segmentItems:
                 value: '200'
             refs:
               - parentEndpoint: "/mock"
-                networkAddress: localhost
+                networkAddress: 'localhost:8000'
                 refType: CrossProcess
                 parentSpanId: 1
                 parentTraceSegmentId: not null
@@ -83,7 +83,7 @@ segmentItems:
             endTime: gt 0
             componentId: '6001'
             spanType: Exit
-            peer: localhost
+            peer: 'localhost:8000'
             skipAnalysis: 'false'
           - operationName: "/mock"
             operationId: '0'