From c03c8a2c075d25ce161eccf1e38f2d65bc63ee60 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Thu, 26 Sep 2024 15:50:57 +0545 Subject: [PATCH 1/3] feat(splunk-logger): allow configuring keepalive_timeout --- apisix/plugins/splunk-hec-logging.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apisix/plugins/splunk-hec-logging.lua b/apisix/plugins/splunk-hec-logging.lua index 6aa88e298dbb..95aa7c739d97 100644 --- a/apisix/plugins/splunk-hec-logging.lua +++ b/apisix/plugins/splunk-hec-logging.lua @@ -51,6 +51,12 @@ local schema = { type = "integer", minimum = 1, default = 10 + }, + keepalive_timeout = { + type = "integer", + minimum = 1000, + default = 60000, + description = "keepalive timeout in milliseconds", } }, required = { "uri", "token" } From c42b88821b03c89841321fb4a5e48fcea87194a9 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Thu, 26 Sep 2024 16:03:32 +0545 Subject: [PATCH 2/3] doc --- docs/en/latest/plugins/splunk-hec-logging.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/latest/plugins/splunk-hec-logging.md b/docs/en/latest/plugins/splunk-hec-logging.md index 826f41e011f4..565f84e4bc67 100644 --- a/docs/en/latest/plugins/splunk-hec-logging.md +++ b/docs/en/latest/plugins/splunk-hec-logging.md @@ -43,6 +43,7 @@ When the Plugin is enabled, APISIX will serialize the request context informatio | endpoint.token | True | | Splunk HEC authentication token. | | endpoint.channel | False | | Splunk HEC send data channel identifier. Read more: [About HTTP Event Collector Indexer Acknowledgment](https://docs.splunk.com/Documentation/Splunk/8.2.3/Data/AboutHECIDXAck). | | endpoint.timeout | False | 10 | Splunk HEC send data timeout in seconds. | +| endpoint.keepalive_timeout | False | 60000 | Keepalive timeout in milliseconds. | | ssl_verify | False | true | When set to `true` enables SSL verification as per [OpenResty docs](https://github.com/openresty/lua-nginx-module#tcpsocksslhandshake). | | log_format | False | | Log format declared as key value pairs in JSON format. Values only support strings. [APISIX](../apisix-variable.md) or [Nginx](http://nginx.org/en/docs/varindex.html) variables can be used by prefixing the string with `$`. | From 91d9c43c42b1cfb727beaa66ab07d1995aeeb492 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Fri, 27 Sep 2024 13:49:31 +0545 Subject: [PATCH 3/3] test --- apisix/plugins/splunk-hec-logging.lua | 1 + t/plugin/splunk-hec-logging.t | 37 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/apisix/plugins/splunk-hec-logging.lua b/apisix/plugins/splunk-hec-logging.lua index 95aa7c739d97..c93b2736eeea 100644 --- a/apisix/plugins/splunk-hec-logging.lua +++ b/apisix/plugins/splunk-hec-logging.lua @@ -148,6 +148,7 @@ local function send_to_splunk(conf, entries) method = "POST", body = table_concat(t), headers = request_headers, + keepalive_timeout = conf.endpoint.keepalive_timeout }) if not res then diff --git a/t/plugin/splunk-hec-logging.t b/t/plugin/splunk-hec-logging.t index 068b5727fede..3d6b108f2de7 100644 --- a/t/plugin/splunk-hec-logging.t +++ b/t/plugin/splunk-hec-logging.t @@ -426,3 +426,40 @@ passed tail -n 1 ci/pod/vector/splunk.log --- response_body eval qr/.*test batched data.*/ + + + +=== TEST 13: set route with keepalive_timeout (success write) +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT, { + uri = "/hello", + upstream = { + type = "roundrobin", + nodes = { + ["127.0.0.1:1980"] = 1 + } + }, + plugins = { + ["splunk-hec-logging"] = { + endpoint = { + uri = "http://127.0.0.1:18088/services/collector", + token = "BD274822-96AA-4DA6-90EC-18940FB2414C", + keepalive_timeout = 5000 + }, + batch_max_size = 1, + inactive_timeout = 1 + } + } + }) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- response_body +passed