This is an automated email from the ASF dual-hosted git repository.

shreemaan-abhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 475642852 perf(loggly): hoist per-request closure out of log phase 
(#13648)
475642852 is described below

commit 4756428522cd23f26c1aa7bd07e9573be218f120
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Mon Jul 6 19:25:54 2026 +0800

    perf(loggly): hoist per-request closure out of log phase (#13648)
---
 apisix/plugins/loggly.lua | 24 ++++++++--------
 t/plugin/loggly.t         | 72 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 13 deletions(-)

diff --git a/apisix/plugins/loggly.lua b/apisix/plugins/loggly.lua
index 112f72e12..a0bf9cfac 100644
--- a/apisix/plugins/loggly.lua
+++ b/apisix/plugins/loggly.lua
@@ -309,9 +309,7 @@ local function send_bulk_over_http(message, metadata, conf)
 end
 
 
-local handle_http_payload
-
-local function handle_log(entries)
+local function handle_log(entries, conf)
     local metadata = plugin.plugin_metadata(plugin_name)
     core.log.info("metadata: ", core.json.delay_encode(metadata))
 
@@ -330,11 +328,12 @@ local function handle_log(entries)
                 return false, err, i
             end
         end
-    else
-        return handle_http_payload(entries, metadata)
+        return true
     end
 
-    return true
+    -- loggly bulk endpoint expects entries concatenated in newline("\n")
+    local message = tab_concat(entries, "\n")
+    return send_bulk_over_http(message, metadata, conf)
 end
 
 
@@ -344,17 +343,16 @@ function _M.log(conf, ctx)
         return
     end
 
-    handle_http_payload = function (entries, metadata)
-        -- loggly bulk endpoint expects entries concatenated in newline("\n")
-        local message = tab_concat(entries, "\n")
-        return send_bulk_over_http(message, metadata, conf)
-    end
-
     if batch_processor_manager:add_entry(conf, log_data) then
         return
     end
 
-    batch_processor_manager:add_entry_to_new_processor(conf, log_data, ctx, 
handle_log)
+    -- bind conf once per batch processor instead of per request
+    local function func(entries)
+        return handle_log(entries, conf)
+    end
+
+    batch_processor_manager:add_entry_to_new_processor(conf, log_data, ctx, 
func)
 end
 
 
diff --git a/t/plugin/loggly.t b/t/plugin/loggly.t
index d19186445..c81206f16 100644
--- a/t/plugin/loggly.t
+++ b/t/plugin/loggly.t
@@ -908,3 +908,75 @@ true
 true
 --- no_error_log
 [alert]
+
+
+
+=== TEST 22: http bulk sends each batch with its own conf (regression)
+--- http_config
+    server {
+        listen 10420;
+
+        location ~ ^/loggly/bulk/(?<token>[^/]+)/tag/bulk$ {
+            content_by_lua_block {
+                ngx.req.read_body()
+                local headers = ngx.req.get_headers()
+                ngx.log(ngx.ERR, "loggly-recv token: ", ngx.var.token,
+                        " tags: ", 
require("toolkit.json").encode(headers["X-LOGGLY-TAG"]))
+                ngx.say("ok")
+            }
+        }
+    }
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+
+            local code = t('/apisix/admin/plugin_metadata/loggly', 
ngx.HTTP_PUT, [[{
+                "host": "127.0.0.1:10420/loggly",
+                "protocol": "http"
+            }]])
+            if code >= 300 then ngx.say("metadata failed: ", code); return end
+
+            local code = t('/apisix/admin/routes/1', ngx.HTTP_PUT, [[{
+                "plugins": {
+                    "loggly": {
+                        "customer_token": "token-a",
+                        "tags": ["aaa"],
+                        "inactive_timeout": 1
+                    }
+                },
+                "upstream": {"nodes": {"127.0.0.1:1980": 1}, "type": 
"roundrobin"},
+                "host": "127.0.0.1",
+                "uri": "/route_a"
+            }]])
+            if code >= 300 then ngx.say("route_a failed: ", code); return end
+
+            local code = t('/apisix/admin/routes/2', ngx.HTTP_PUT, [[{
+                "plugins": {
+                    "loggly": {
+                        "customer_token": "token-b",
+                        "tags": ["bbb"],
+                        "inactive_timeout": 1
+                    }
+                },
+                "upstream": {"nodes": {"127.0.0.1:1980": 1}, "type": 
"roundrobin"},
+                "host": "127.0.0.1",
+                "uri": "/route_b"
+            }]])
+            if code >= 300 then ngx.say("route_b failed: ", code); return end
+
+            -- buffer one entry per config before either batch flushes, so the
+            -- old shared closure would send both with the last conf's token
+            t("/route_a", ngx.HTTP_GET)
+            t("/route_b", ngx.HTTP_GET)
+            ngx.say("done")
+        }
+    }
+--- wait: 3
+--- response_body
+done
+--- error_log
+loggly-recv token: token-a tags: "aaa"
+loggly-recv token: token-b tags: "bbb"
+--- no_error_log
+[alert]

Reply via email to