Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(elasticsearch-logger): add compatibility headers #10828

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Loading