Skip to content

Commit

Permalink
fix(elasticsearch-logger): add compatibility headers (#10828)
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshya8066 authored Feb 1, 2024
1 parent 40a4f8a commit 77585e2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
5 changes: 4 additions & 1 deletion apisix/plugins/elasticsearch-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions ci/pod/docker-compose.plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'


Expand Down
52 changes: 52 additions & 0 deletions t/plugin/elasticsearch-logger.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 77585e2

Please sign in to comment.