You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/04/15 07:32:40 UTC

[GitHub] [skywalking-nginx-lua] fffonion commented on a change in pull request #70: kong plugin

fffonion commented on a change in pull request #70:
URL: https://github.com/apache/skywalking-nginx-lua/pull/70#discussion_r613815976



##########
File path: kong/README.md
##########
@@ -0,0 +1,51 @@
+Apache SkyWalking Nginx Agent For Kong
+==========
+
+This plugin base on Apache SkyWalking Nginx Agent for the Kong API gateway to integrate with the Apache SkyWalking distributed tracing system.
+
+## Usage
+
+1. Install the plugin on Kong:
+
+To install kong-plugin-skywalking:
+```bash
+$ luarocks install kong-plugin-skywalking --local
+```
+
+Edit kong.conf:
+```
+plugins = bundled,skywalking
+
+lua_package_path = ${user.home}/.luarocks/share/lua/5.1/?.lua;;
+```
+
+Set environment:
+```bash
+$ export KONG_NGINX_HTTP_LUA_SHARED_DICT="tracing_buffer 128m"
+```
+
+Restart Kong
+
+2. Enabling & configuring plugin:
+
+Add the plugin to an API:
+
+```bash
+$ curl -i -X POST \
+   --url http://localhost:8001/apis/{api_name}/plugins/ \

Review comment:
       `API` entity has been deprecated and removed in recent version of Kong, we can use `Services` here
   ```
   --url http://localhost:8001/services/{service_name}/plugins/ \
   ```

##########
File path: kong/plugins/skywalking/handler.lua
##########
@@ -0,0 +1,80 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--    http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local tracer = require("skywalking.tracer")
+local client = require("skywalking.client")
+local Span = require('skywalking.span')
+
+local subsystem = ngx.config.subsystem
+
+local SkyWalkingHandler = {
+    PRIORITY = 100001,
+    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.")
+        return
+    end
+
+    if config.sample_ratio == 1 or math.random() * 100 < config.sample_ratio then
+        kong.ctx.plugin.skywalking_sample = true
+
+        if not client:isInitialized() then
+            local metadata_buffer = ngx.shared.tracing_buffer

Review comment:
       This if block can moved to plugin's `init_worker` phase, as it seems is doing a per worker timer spawning. So we can avoid suprises when serving request as well as long tail latencies.
   
   And we are writing to the same key in shared dict below, this will break the use case when there's multiple skywalking plugins being created in Kong. If this is not desired, 

##########
File path: kong/plugins/skywalking/handler.lua
##########
@@ -0,0 +1,80 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more
+-- contributor license agreements.  See the NOTICE file distributed with
+-- this work for additional information regarding copyright ownership.
+-- The ASF licenses this file to You under the Apache License, Version 2.0
+-- (the "License"); you may not use this file except in compliance with
+-- the License.  You may obtain a copy of the License at
+--
+--    http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+local tracer = require("skywalking.tracer")
+local client = require("skywalking.client")
+local Span = require('skywalking.span')
+
+local subsystem = ngx.config.subsystem
+
+local SkyWalkingHandler = {
+    PRIORITY = 100001,
+    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.")
+        return
+    end
+
+    if config.sample_ratio == 1 or math.random() * 100 < config.sample_ratio then

Review comment:
       Should this be `config.sample_ratio == 100 or ....`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org