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

monkeydluffy 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 77585e22d fix(elasticsearch-logger): add compatibility headers (#10828)
77585e22d is described below

commit 77585e22dbcb883ef60b6bd358d7bd1fd40b554d
Author: Lakshya Gupta <[email protected]>
AuthorDate: Thu Feb 1 08:46:59 2024 +0530

    fix(elasticsearch-logger): add compatibility headers (#10828)
---
 apisix/plugins/elasticsearch-logger.lua |  5 +++-
 ci/pod/docker-compose.plugin.yml        |  6 ++--
 t/plugin/elasticsearch-logger.t         | 52 +++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/apisix/plugins/elasticsearch-logger.lua 
b/apisix/plugins/elasticsearch-logger.lua
index de29da2e0..81fdc157d 100644
--- a/apisix/plugins/elasticsearch-logger.lua
+++ b/apisix/plugins/elasticsearch-logger.lua
@@ -138,7 +138,10 @@ local function send_to_elasticsearch(conf, entries)
     end
     local uri = selected_endpoint_addr .. "/_bulk"
     local body = core.table.concat(entries, "")
-    local headers = {["Content-Type"] = "application/x-ndjson"}
+    local headers = {
+        ["Content-Type"] = "application/x-ndjson;compatible-with=7",
+        ["Accept"] = "application/vnd.elasticsearch+json;compatible-with=7"
+    }
     if conf.auth then
         local authorization = "Basic " .. ngx.encode_base64(
             conf.auth.username .. ":" .. conf.auth.password
diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml
index 13a34e390..afdb38175 100644
--- a/ci/pod/docker-compose.plugin.yml
+++ b/ci/pod/docker-compose.plugin.yml
@@ -201,7 +201,7 @@ services:
 
   # Elasticsearch Logger Service
   elasticsearch-noauth:
-    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
+    image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
     restart: unless-stopped
     ports:
       - "9200:9200"
@@ -212,18 +212,16 @@ services:
       xpack.security.enabled: 'false'
 
   elasticsearch-auth:
-    image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
+    image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
     restart: unless-stopped
     ports:
       - "9201:9201"
-      - "9301:9301"
     environment:
       ES_JAVA_OPTS: -Xms512m -Xmx512m
       discovery.type: single-node
       ELASTIC_USERNAME: elastic
       ELASTIC_PASSWORD: 123456
       http.port: 9201
-      transport.tcp.port: 9301
       xpack.security.enabled: 'true'
 
 
diff --git a/t/plugin/elasticsearch-logger.t b/t/plugin/elasticsearch-logger.t
index 1706f5c28..40ac5f2e2 100644
--- a/t/plugin/elasticsearch-logger.t
+++ b/t/plugin/elasticsearch-logger.t
@@ -668,3 +668,55 @@ hello world
 --- wait: 2
 --- error_log
 check elasticsearch custom body success
+
+
+
+=== TEST 17: using unsupported field (type) for elasticsearch v8 should work 
normally
+--- 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 = {
+                    ["elasticsearch-logger"] = {
+                        endpoint_addr = "http://127.0.0.1:9201";,
+                        field = {
+                            index = "services",
+                            type = "collector"
+                        },
+                        auth = {
+                            username = "elastic",
+                            password = "123456"
+                        },
+                        batch_max_size = 1,
+                        inactive_timeout = 1
+                    }
+                }
+            })
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 18: test route (auth success)
+--- request
+GET /hello
+--- wait: 2
+--- response_body
+hello world
+--- no_error_log
+Action/metadata line [1] contains an unknown parameter [_type]

Reply via email to