From 9f1aeb5d2426d2aa75df80ef38499cf5e24071d3 Mon Sep 17 00:00:00 2001 From: Lakshya Gupta Date: Tue, 16 Jan 2024 08:22:06 +0530 Subject: [PATCH 1/6] changed elasticsearch version --- ci/pod/docker-compose.plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml index 13a34e3908f7..3bb9526e77fa 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.11.3 restart: unless-stopped ports: - "9200:9200" @@ -212,7 +212,7 @@ services: xpack.security.enabled: 'false' elasticsearch-auth: - image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1 + image: docker.elastic.co/elasticsearch/elasticsearch:8.11.3 restart: unless-stopped ports: - "9201:9201" From a3ec2200dde8e4419ee3fbf5fbb17f90ca936f02 Mon Sep 17 00:00:00 2001 From: Lakshya Gupta Date: Tue, 16 Jan 2024 11:02:13 +0530 Subject: [PATCH 2/6] add compatibility headers --- apisix/plugins/elasticsearch-logger.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/elasticsearch-logger.lua b/apisix/plugins/elasticsearch-logger.lua index de29da2e0184..81fdc157d43b 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 From 76b752e6ff10c248e71b49af2fdf35d92f9a5c09 Mon Sep 17 00:00:00 2001 From: Lakshya Gupta Date: Wed, 17 Jan 2024 19:08:04 +0530 Subject: [PATCH 3/6] change the elasticsearch version --- ci/pod/docker-compose.plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml index 3bb9526e77fa..13a34e3908f7 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:8.11.3 + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1 restart: unless-stopped ports: - "9200:9200" @@ -212,7 +212,7 @@ services: xpack.security.enabled: 'false' elasticsearch-auth: - image: docker.elastic.co/elasticsearch/elasticsearch:8.11.3 + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1 restart: unless-stopped ports: - "9201:9201" From d09c9d3166366c6669271200da78c3d7e59eb387 Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Fri, 26 Jan 2024 07:19:32 +0545 Subject: [PATCH 4/6] update version in CI --- ci/pod/docker-compose.plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml index 13a34e3908f7..4ae13e4bb830 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,7 +212,7 @@ 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" From 5d374f5a67dcec78ae383f5efb25a97df099ebab Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Fri, 26 Jan 2024 11:08:58 +0545 Subject: [PATCH 5/6] remove unused port that causes failure --- ci/pod/docker-compose.plugin.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/pod/docker-compose.plugin.yml b/ci/pod/docker-compose.plugin.yml index 4ae13e4bb830..afdb3817554d 100644 --- a/ci/pod/docker-compose.plugin.yml +++ b/ci/pod/docker-compose.plugin.yml @@ -216,14 +216,12 @@ services: 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' From 50c19e99593068e0209fcddb6fe1fd5adfdd946d Mon Sep 17 00:00:00 2001 From: Abhishek Choudhary Date: Fri, 26 Jan 2024 12:16:41 +0545 Subject: [PATCH 6/6] add test case --- t/plugin/elasticsearch-logger.t | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/t/plugin/elasticsearch-logger.t b/t/plugin/elasticsearch-logger.t index ba9b6bfd9c84..2a2d0996dc9e 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]