You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/17 17:06:00 UTC

[GitHub] [apisix] Firstsawyou commented on a change in pull request #2727: feat: Improve zipkin span reporter performance

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



##########
File path: apisix/plugins/zipkin/reporter.lua
##########
@@ -105,39 +105,72 @@ 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
 

Review comment:
       Two blank lines are required here.

##########
File path: apisix/plugins/zipkin/reporter.lua
##########
@@ -105,39 +105,72 @@ 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, err = 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
+        -- for zipkin test
+        core.log.error("report zipkin span failed")
+        return nil, "failed: " .. err .. ", url: " .. report.endpoint
     elseif res.status < 200 or res.status >= 300 then
-        return nil, "failed: " .. res.status .. " " .. res.reason
+        return nil, "failed: " .. report.endpoint .. " "
+               .. res.status .. " " .. res.reason
     end
 
     return true
 end
 

Review comment:
       ditto.




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