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/12 11:53:20 UTC

[GitHub] [skywalking-nginx-lua] mrproliu opened a new pull request #35: [WIP] Implement correlation protocol

mrproliu opened a new pull request #35: [WIP] Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35
 
 
   implement [correlation protocol](https://github.com/apache/skywalking/blob/master/docs/en/protocols/Skywalking-Cross-Process-Correlation-Headers-Protocol-v1.md), support transport and adding custom data.

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

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

Posted by GitBox <gi...@apache.org>.
mrproliu commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407287465
 
 

 ##########
 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 ""
+
+        context[key] = value
+    end
+
+    return context
+end
+
+-- Return string to represent this correlation context
+function _M.serialize(context)
+    local encoded = ''
+    for name, value in pairs(context) do
+        if #encoded > 0 then
+            encoded = encoded .. ','
+        end
+
+        encoded = encoded .. encode_base64(name) .. ':' .. encode_base64(value)
 
 Review comment:
   it's safe. I have tested in the correlation_context_test.lua file. 

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

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

Posted by GitBox <gi...@apache.org>.
moonming commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407455220
 
 

 ##########
 File path: lib/skywalking/correlation_context.lua
 ##########
 @@ -0,0 +1,121 @@
+--
+-- 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;
 
 Review comment:
   code style: remove the `;`

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

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

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407304597
 
 

 ##########
 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:
   Thanks.

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

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

Posted by GitBox <gi...@apache.org>.
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

[GitHub] [skywalking-nginx-lua] mrproliu merged pull request #35: Implement correlation protocol

Posted by GitBox <gi...@apache.org>.
mrproliu merged pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35
 
 
   

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

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

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407283978
 
 

 ##########
 File path: README.md
 ##########
 @@ -118,7 +120,7 @@ The following APIs are for developers or using this lib out of the Nginx case.
 
 ## Nginx APIs
 - **startTimer**, `require("client"):startBackendTimer("http://127.0.0.1:8080")`. Start the backend timer. This timer register the metadata and report traces to the backend.
-- **start**, `require("tracer"):start("upstream service")`. Begin the tracing before the upstream begin.
+- **start**, `require("tracer"):start("upstream service", correlation)`. Begin the tracing before the upstream begin. The custom data (table type) can be passed in the second parameter, and then you can correlate the data to the downstream service.
 
 Review comment:
   ```suggestion
   - **start**, `require("tracer"):start("upstream service", correlation)`. Begin the tracing before the upstream begin. The custom data (table type) can be injected as the second parameter, and then they will be propagated to the downstream service.
   ```

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

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

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407299188
 
 

 ##########
 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:
   My question is more about, should we abandon this whole section, as the format is illegal.

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

[GitHub] [skywalking-nginx-lua] mrproliu commented on issue #35: Implement correlation protocol

Posted by GitBox <gi...@apache.org>.
mrproliu commented on issue #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#issuecomment-612713666
 
 
   @wu-sheng @moonming I have finished the document and tests, please help to review.

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

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

Posted by GitBox <gi...@apache.org>.
mrproliu commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407303120
 
 

 ##########
 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:
   Ok, I think we should abandon it, let me fix it and java implementation. 

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

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

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407284181
 
 

 ##########
 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:
   `#parts > 1` is a legal/expected case? Do we do this in Java agent implementation?

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

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

Posted by GitBox <gi...@apache.org>.
mrproliu commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407287037
 
 

 ##########
 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:
   In [java agent implementation](https://github.com/apache/skywalking/blob/569baf3236226b17c3b40e376e5681b5623abf38/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CorrelationContext.java#L112), it still has an empty check.

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

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

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on a change in pull request #35: Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#discussion_r407284340
 
 

 ##########
 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 ""
+
+        context[key] = value
+    end
+
+    return context
+end
+
+-- Return string to represent this correlation context
+function _M.serialize(context)
+    local encoded = ''
+    for name, value in pairs(context) do
+        if #encoded > 0 then
+            encoded = encoded .. ','
+        end
+
+        encoded = encoded .. encode_base64(name) .. ':' .. encode_base64(value)
 
 Review comment:
   Is `encode_base64` safe for empty string?

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

[GitHub] [skywalking-nginx-lua] mrproliu commented on issue #35: [WIP] Implement correlation protocol

Posted by GitBox <gi...@apache.org>.
mrproliu commented on issue #35: [WIP] Implement correlation protocol
URL: https://github.com/apache/skywalking-nginx-lua/pull/35#issuecomment-612603068
 
 
   After I add the document, it can start to review.

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