feat: implement datastream support on elasticsearch-logger plugin - #13102
feat: implement datastream support on elasticsearch-logger plugin#13102jr-instantsystem wants to merge 33 commits into
Conversation
…lign with other plugins
# Conflicts: # apisix/plugins/elasticsearch-logger.lua # docs/en/latest/plugins/elasticsearch-logger.md
…e_es_version() call (already called in _M.access)
Baoyuantop
left a comment
There was a problem hiding this comment.
We also need to add tests for this feature.
There was a problem hiding this comment.
Pull request overview
This PR updates the elasticsearch-logger plugin to support writing logs to either a classic Elasticsearch index or a DataStream target, and aligns the plugin documentation with the new configuration options.
Changes:
- Extend the plugin schema to allow configuring either
field.indexorfield.datastream(mutually exclusive). - Update bulk action generation to emit
indexvscreateactions depending on the configured target. - Document the new
field.datastreamattribute and update notes around required field configuration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| docs/en/latest/plugins/elasticsearch-logger.md | Documents field.index / field.datastream options and updates notes about required configuration. |
| apisix/plugins/elasticsearch-logger.lua | Adds schema support and runtime logic to generate bulk entries for index vs datastream targets. |
Comments suppressed due to low confidence (1)
apisix/plugins/elasticsearch-logger.lua:231
- When
field.datastreamis used,bodyis built with acreateaction and has nobody.index, but the ES 5/6 compatibility block unconditionally writesbody.index._type. This will throw a runtime error; set_typeon the actual action present (e.g.,body.indexvsbody.create) or restructure to avoid accessingbody.indexwhen using datastream.
-- for older version type is required
if conf._version == "6" or conf._version == "5" then
body.index._type = "_doc"
end
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…eam-suppot' into feat/elastisearch-logger-datastream-suppot
…eam-suppot' into feat/elastisearch-logger-datastream-suppot
|
|
||
| -- for older version type is required | ||
| if conf._version == "6" or conf._version == "5" then | ||
| body.index._type = "_doc" |
There was a problem hiding this comment.
When datastream is configured, the body only contains the "create" key, not the "index" key. For version compatibility, accessing nil.index with body.index._type = "_doc" will trigger a runtime error: "attempt to index a nil value".
There was a problem hiding this comment.
ho, right... fix pushed
datastreams are available for ES 7+ only
|
Hi @jr-instantsystem, please fix the failed CI |
…rd-from-env' # Conflicts: # apisix/plugins/elasticsearch-logger.lua
|
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions. |
# Conflicts: # apisix/plugins/elasticsearch-logger.lua # docs/en/latest/plugins/elasticsearch-logger.md
|
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions. |
# Conflicts: # docs/en/latest/plugins/elasticsearch-logger.md # t/plugin/elasticsearch-logger.t
Description
The current plugin allows to push messages to raw indices in ElasticSearch, using the "POST _bulk" endpoint, with the "_index" action.
It not compatible with DataSteams according to https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-bulk, where action have to be "_create" to push on DataStream.
The PR add a second plugin param for a datastream name. The user must choose between "index name" or "datastream name" to define the method used to push to ElasticSearch.
Tested on 3.12
Which issue(s) this PR fixes:
N/A
Checklist