feat: implement datastream support on elasticsearch-logger plugin#13102
feat: implement datastream support on elasticsearch-logger plugin#13102jr-instantsystem wants to merge 13 commits intoapache:masterfrom
Conversation
| } | ||
| } | ||
| } | ||
| else if conf.field.datastream then |
There was a problem hiding this comment.
| else if conf.field.datastream then | |
| elseif conf.field.datastream then |
| else | ||
| core.log.error("Unsupported field configuration") | ||
| return nil |
There was a problem hiding this comment.
This check is unnecessary. The schema's oneOf constraint ensures that at least one of the index and datastream is set.
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.
| NOTE: | ||
| - `encrypt_fields = {"auth.password"}` is also defined in the schema, which means that the field will be stored encrypted in etcd. See [encrypted storage fields](../plugin-develop.md#encrypted-storage-fields). | ||
| - One of `field.index` or `field.datastream` must be set. |
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
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