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 2020/04/13 02:00:19 UTC

[GitHub] [skywalking-nginx-lua] wu-sheng commented on a change in pull request #35: Implement correlation protocol

wu-sheng commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407284255
 
 

 ##########
 File path: lib/skywalking/correlation_context.lua
 ##########
 @@ -0,0 +1,119 @@
+--
+-- 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.
+--
+
+-- limit define
+local ELEMENT_MAX_NUMBER = 3;
+local VALUE_MAX_LENGTH = 128;
+
+local Util = require('util')
+local Base64 = require('dependencies/base64')
+local encode_base64 = Base64.encode
+local decode_base64 = Base64.decode
+
+if Util.is_ngx_lua then
+    encode_base64 = ngx.encode_base64
+    decode_base64 = ngx.decode_base64
+end
+
+local _M = {}
+
+function _M.new()
+    return {}
+end
+
+-- Deserialze value from the correlation context and initalize the context
+function _M.fromSW8Value(value)
+    local context = _M.new()
+
+    if value == nil then
+        return context
+    end
+
+    local data = Util.split(value, ',')
+    if #data == 0 then
+        return context
+    end
+
+    for i, per_data in ipairs(data)
+    do
+        if #data > ELEMENT_MAX_NUMBER then
+            return context
+        end
+
+        local parts = Util.split(per_data, ':')
+        local key = decode_base64(parts[1])
+        local value = #parts > 1 and decode_base64(parts[2]) or ""
 
 Review comment:
   Reading the `#serialize`, I didn't see it coming.

----------------------------------------------------------------
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


With regards,
Apache Git Services