-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(elasticsearch-logger): support multi elasticsearch endpoints #8604
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ When the Plugin is enabled, APISIX will serialize the request context informatio | |
|
||
| Name | Type | Required | Default | Description | | ||
| ------------- | ------- | -------- | --------------------------- | ------------------------------------------------------------ | | ||
| endpoint_addr | string | True | | Elasticsearch API. | | ||
| endpoint_addr | string/array | True | | Elasticsearch API. | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a deprecated mark like https://github.com/apache/apisix/blob/release/2.15/docs/en/latest/plugins/mqtt-proxy.md#attributes |
||
| field | array | True | | Elasticsearch `field` configuration. | | ||
| field.index | string | True | | Elasticsearch [_index field](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html#mapping-index-field). | | ||
| field.type | string | False | Elasticsearch default value | Elasticsearch [_type field](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-type-field.html#mapping-type-field). | | ||
|
@@ -53,6 +53,8 @@ This Plugin supports using batch processors to aggregate and process entries (lo | |
|
||
## Enabling the Plugin | ||
|
||
If multiple endpoints are configured, they will be written randomly. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be put into the attribute table |
||
|
||
### Full configuration | ||
|
||
The example below shows a complete configuration of the Plugin on a specific Route: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ passed | |
property "endpoint_addr" is required | ||
property "field" is required | ||
property "field" validation failed: property "index" is required | ||
property "endpoint_addr" validation failed: failed to match pattern "\[\^/\]\$" with "http://127.0.0.1:9200/" | ||
property "endpoint_addr" validation failed: object matches none of the required | ||
|
||
|
||
|
||
|
@@ -515,3 +515,39 @@ apisix: | |
--- response_body | ||
123456 | ||
PTQvJEaPcNOXcOHeErC0XQ== | ||
|
||
|
||
|
||
=== TEST 13: add plugin on routes using multi elasticsearch-logger | ||
--- 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:9200", "http://127.0.0.1:9201"}, | ||
field = { | ||
index = "services" | ||
}, | ||
batch_max_size = 1, | ||
inactive_timeout = 1 | ||
} | ||
} | ||
}) | ||
|
||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- response_body | ||
passed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to add a test to show that different endpoints will be chosen randomly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you, but I don't know how. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about hitting the path multiple times and triggering multiple sending? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @spacewander. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use
endpoint_addrs
with the new type.Using different types in the same field brings us lots of trouble when we need to work with static-type language, like writing a Go client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @spacewander , thank you for your reply.
In my opinion, to use endpoint_addrs will cause trouble, this change is not backward compatible.
The code submitted for the first time is modified as follows:
I fixed the code according to @soulbird's suggestion.
#8604 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep endpoint_addr, add a new field endpoint_addrs to support both string and array better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused. People can still use the old endpoint_addr configuration.
It is not a good idea to have a field of multiple types. The upstream's nodes field is an example. People keep complaining that this field doesn't have a consistent type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. So we need to keep both endpoint_addr and endpoint_addrs, where endpoint_addrs is only specified as array type, is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes