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 2020/02/21 16:11:26 UTC
[skywalking-nginx-lua] branch master updated: Set up the basic
example for Nginx setup.
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-nginx-lua.git
The following commit(s) were added to refs/heads/master by this push:
new 6ff9e8f Set up the basic example for Nginx setup.
6ff9e8f is described below
commit 6ff9e8f5b7b0bd3d2ffb61b5c649310dfdead28d
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Sat Feb 22 00:11:16 2020 +0800
Set up the basic example for Nginx setup.
---
examples/nginx.conf | 77 ++++++++++++++++++++++++++++++++++++++
lib/skywalking/buffer.lua | 17 ---------
lib/skywalking/segment_ref.lua | 2 +-
lib/skywalking/span.lua | 4 +-
lib/skywalking/span_layer.lua | 2 +-
lib/skywalking/tracing_context.lua | 37 +++++++++---------
lib/skywalking/util.lua | 8 ++--
7 files changed, 105 insertions(+), 42 deletions(-)
diff --git a/examples/nginx.conf b/examples/nginx.conf
new file mode 100644
index 0000000..8540267
--- /dev/null
+++ b/examples/nginx.conf
@@ -0,0 +1,77 @@
+# 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.
+
+# This nginx.conf is designed and written for local dev environments
+# It will use the blocking startup mode and console logging
+worker_processes 1;
+daemon off;
+error_log /dev/stdout debug;
+
+events {
+ worker_connections 1024;
+}
+http {
+ lua_package_path "/Users/wusheng/Documents/GitHub/skywalking-nginx-lua/lib/skywalking/?.lua;;";
+ # Put the finished segment into this buffer as a queue
+ lua_shared_dict segment_buffer 100m;
+ lua_shared_dict metadata_buffer 1m;
+
+ server {
+ listen 8080;
+
+ location /ingress {
+ default_type text/html;
+ rewrite_by_lua_block {
+ local TC = require('tracing_context')
+
+ local metadata_buffer = ngx.shared.metadata_buffer
+ -- Mock the service instance id
+ metadata_buffer['serviceInstId'] = 1
+
+ local tracingContext
+ if metadata_buffer['serviceInstId'] ~= nil then
+ tracingContext = TC:new(metadata_buffer['serviceInstId'])
+ else
+ tracingContext = TC:newNoOP()
+ end
+
+ local contextCarrier = {}
+ local exitSpan = tracingContext:createExitSpan("exit_op", nil, "127.0.0.1", contextCarrier)
+ for name, value in pairs(contextCarrier) do
+ ngx.req.set_header(name, value)
+ end
+
+ -- Push the data in the context
+ ngx.ctx.exitSpan = exitSpan
+ }
+
+ proxy_pass http://127.0.0.1:8080/backend;
+
+ body_filter_by_lua_block {
+ ngx.log(ngx.ERR, 'span exist? ' .. ngx.ctx.exitSpan.span_id)
+ }
+ }
+
+ location /backend {
+ default_type text/html;
+ content_by_lua_block {
+ ngx.say("<p>Backend service for testing only.</p>")
+ ngx.say("<p>Backend sw6 received headers: " .. ngx.req.get_headers()["sw6"] .. "</p>")
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/skywalking/buffer.lua b/lib/skywalking/buffer.lua
deleted file mode 100644
index 6245b76..0000000
--- a/lib/skywalking/buffer.lua
+++ /dev/null
@@ -1,17 +0,0 @@
---
--- 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.
---
-
diff --git a/lib/skywalking/segment_ref.lua b/lib/skywalking/segment_ref.lua
index bc35ad6..7e801eb 100644
--- a/lib/skywalking/segment_ref.lua
+++ b/lib/skywalking/segment_ref.lua
@@ -18,7 +18,7 @@
local Util = require('util')
local Base64 = require('dependencies/base64')
-SegmentRef = {
+local SegmentRef = {
-- There is no multiple-threads scenario in the LUA, no only hard coded as CROSS_PROCESS
type = 'CROSS_PROCESS',
trace_id,
diff --git a/lib/skywalking/span.lua b/lib/skywalking/span.lua
index 0cf9eab..9f66ec2 100644
--- a/lib/skywalking/span.lua
+++ b/lib/skywalking/span.lua
@@ -19,9 +19,9 @@ local spanLayer = require("span_layer")
local Util = require('util')
local SegmentRef = require("segment_ref")
-CONTEXT_CARRIER_KEY = 'sw6'
+local CONTEXT_CARRIER_KEY = 'sw6'
-Span = {
+local Span = {
span_id,
parent_span_id,
operation_name,
diff --git a/lib/skywalking/span_layer.lua b/lib/skywalking/span_layer.lua
index 7cdec08..a82e543 100644
--- a/lib/skywalking/span_layer.lua
+++ b/lib/skywalking/span_layer.lua
@@ -15,7 +15,7 @@
-- limitations under the License.
--
-Layer = {
+local Layer = {
NONE = {name = "NONE", value=0},
DB = {name = "DB", value=1},
RPC_FRAMEWORK = {name = "RPC_FRAMEWORK", value=2},
diff --git a/lib/skywalking/tracing_context.lua b/lib/skywalking/tracing_context.lua
index a659eb4..c4dcc3d 100644
--- a/lib/skywalking/tracing_context.lua
+++ b/lib/skywalking/tracing_context.lua
@@ -18,7 +18,7 @@
local Util = require('util')
local Span = require('span')
-TracingContext = {
+local TracingContext = {
trace_id,
segment_id,
service_inst_id,
@@ -28,6 +28,25 @@ TracingContext = {
internal,
}
+-------------- Internal Object-------------
+-- Internal Object hosts the methods for SkyWalking LUA internal APIs only.
+local Internal = {
+ self_generated_trace_id,
+ -- span id starts from 0
+ span_id_seq,
+ -- Owner means the Context instance holding this Internal object.
+ owner,
+ -- The first created span.
+ first_span,
+ -- The first ref injected in this context
+ first_ref,
+ -- Created span and still active
+ active_spans,
+ active_count,
+ -- Finished spans
+ finished_spans,
+}
+
function TracingContext:new(serviceInstID)
local o = {}
setmetatable(o, self)
@@ -91,22 +110,6 @@ end
-------------- Internal Object-------------
-- Internal Object hosts the methods for SkyWalking LUA internal APIs only.
-Internal = {
- self_generated_trace_id,
- -- span id starts from 0
- span_id_seq,
- -- Owner means the Context instance holding this Internal object.
- owner,
- -- The first created span.
- first_span,
- -- The first ref injected in this context
- first_ref,
- -- Created span and still active
- active_spans,
- active_count,
- -- Finished spans
- finished_spans,
-}
-- Create an internal instance
function Internal:new()
diff --git a/lib/skywalking/util.lua b/lib/skywalking/util.lua
index d2192ed..27c1886 100644
--- a/lib/skywalking/util.lua
+++ b/lib/skywalking/util.lua
@@ -15,10 +15,10 @@
-- limitations under the License.
--
-Util = {}
-MAX_ID_PART2 = 1000000000
-MAX_ID_PART3 = 100000
-SEQ = 1
+local Util = {}
+local MAX_ID_PART2 = 1000000000
+local MAX_ID_PART3 = 100000
+local SEQ = 1
function Util:newID()
SEQ = SEQ + 1