spacewander commented on code in PR #8604: URL: https://github.com/apache/apisix/pull/8604#discussion_r1089663145
########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -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. Review Comment: This should be put into the attribute table ########## docs/en/latest/plugins/elasticsearch-logger.md: ########## @@ -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. | Review Comment: Let's add a deprecated mark like https://github.com/apache/apisix/blob/release/2.15/docs/en/latest/plugins/mqtt-proxy.md#attributes ########## t/plugin/elasticsearch-logger.t: ########## @@ -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 Review Comment: We need to add a test to show that different endpoints will be chosen randomly. ########## apisix/plugins/elasticsearch-logger.lua: ########## @@ -23,18 +23,35 @@ local plugin = require("apisix.plugin") local ngx = ngx local str_format = core.string.format +local math_random = math.random +local type = type local plugin_name = "elasticsearch-logger" local batch_processor_manager = bp_manager_mod.new(plugin_name) -local schema = { - type = "object", - properties = { - endpoint_addr = { +local endpoint_schema = { + anyOf = { + { + -- deprecated, use "array" instead type = "string", pattern = "[^/]$", }, + { + type = "array", + minItems = 1, + items = { + type = "string", + pattern = "[^/]$", + }, + } + } +} + +local schema = { + type = "object", + properties = { + endpoint_addr = endpoint_schema, Review Comment: 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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
