spacewander commented on a change in pull request #2727:
URL: https://github.com/apache/apisix/pull/2727#discussion_r526181235



##########
File path: apisix/plugins/zipkin/reporter.lua
##########
@@ -105,38 +104,68 @@ function _M.report(self, span)
         annotations = span.logs
     }
 
-    local i = self.pending_spans_n + 1
-    self.pending_spans[i] = zipkin_span
-    self.pending_spans_n = i
-end
-
-function _M.flush(self)
-    if self.pending_spans_n == 0 then
-
-        return true
+    self.pending_spans_n = self.pending_spans_n + 1
+    if self.processor then
+        self.processor:push(zipkin_span)
     end
+end
 
-    local pending_spans = cjson.encode(self.pending_spans)
-    self.pending_spans = {}
-    self.pending_spans_n = 0
-
+local function send_span(pending_spans, report)
     local httpc = resty_http.new()
-    local res, err = httpc:request_uri(self.endpoint, {
+    local res = httpc:request_uri(report.endpoint, {
         method = "POST",
         headers = {
             ["content-type"] = "application/json",
         },
         body = pending_spans,
+        keepalive = 5000,
+        keepalive_pool = 5
     })
 
-    -- TODO: on failure, retry?
     if not res then
-        return nil, "failed to request: " .. err
+        return nil, "failed: " .. report.endpoint
     elseif res.status < 200 or res.status >= 300 then
         return nil, "failed: " .. res.status .. " " .. res.reason
     end
 
-    return true
+   return true
+end
+
+function _M.init_processor(self)
+    local process_conf = {
+        name = "zipkin_report",
+        retry_delay = 1,
+        batch_max_size = 1000,
+        max_retry_count = 0,
+        buffer_duration = 60,
+        inactive_timeout = 5
+    }
+
+    local flush = function (entries, batch_max_size)
+        if not entries then
+            return true
+        end
+
+        local pending_spans, err
+        if batch_max_size == 1 then
+            pending_spans, err = cjson.encode(entries[1])

Review comment:
       And, `this entity must be table` doesn't mean ` can not be cause 
exception`. You can see my example above:
   ```lua
   local cjson = require("cjson")
   local x = cjson.new()
   local t = {}
   t[1] = 1
   t[1000] = 1
   print(x.encode({a = t}))
   # ERROR: /tmp/a.lua:7: Cannot serialise table: excessively sparse array
   ```
   
   Please! Please! Please! Be careful and never say something bad won't happen. 
I am tired of telling the same thing too many times.




----------------------------------------------------------------
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:
[email protected]


Reply via email to