Skip to content

out_opensearch_data_stream: honor pipeline - #205

Merged
Watson1978 merged 5 commits into
fluent:mainfrom
lbarrosby:data-stream-pipeline
Nov 25, 2026
Merged

Watson1978 merged 5 commits into
fluent:mainfrom
lbarrosby:data-stream-pipeline

Conversation

@lbarrosby

@lbarrosby lbarrosby commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

opensearch_data_stream inherits the pipeline parameter from opensearch, but its write builds the bulk request with only index and body, so the parameter is ignored and records skip the ingest pipeline with no warning. OpenSearch applies an ingest pipeline given on a _bulk request to data streams too, so nothing on the server side stops this from working.

The output expands a configured pipeline such as pipeline-${tag} after checking the records, and only if at least one record is ready for the bulk request. A non-empty result is sent as the pipeline query parameter. With error events enabled, records rejected during those checks go to @ERROR right away when pipeline is unset. With pipeline set, they go after a successful expansion, or without expansion when all records were rejected. If pipeline is not set, or it is empty after expansion (OpenSearch rejects ?pipeline= for the whole request), the request is unchanged. A short pipeline entry was added to the Data Stream section of the README, like the id_key one added in #200.

Tests added to test/plugin/test_out_opensearch_data_stream.rb:

  • test_record_with_pipeline, with a fixed value and a ${tag} placeholder. The bulk request must carry ?pipeline=mypipeline or ?pipeline=pipeline-test. Both fail on main because the request goes out without the query parameter.
  • test_record_with_empty_pipeline and test_record_with_pipeline_placeholder_expanded_to_empty: no pipeline query parameter is sent.
  • test_invalid_records_go_to_error_when_pipeline_cannot_be_built and test_chunk_with_valid_records_is_not_sent_to_error_when_pipeline_cannot_be_built: with a tag that cannot be used in a placeholder, a chunk with only an invalid record sends it to @ERROR, a chunk with an invalid and a valid record sends nothing to @ERROR, and no bulk request is made in either case.

bundle exec rake test: 466 tests, 0 failures, 0 errors.

Not marked backward compatible: the data stream output now sends the configured pipeline when its expanded value is non-empty.

(check all that apply)

  • tests added
  • tests passing
  • README updated (if needed)
  • README Table of Contents updated (if needed)
  • History.md and version in gemspec are untouched
  • backward compatible

opensearch_data_stream accepts the pipeline parameter from the regular
output but never sends it, so records skip the configured ingest
pipeline without any warning. Add it to the bulk request, with the
chunk placeholders filled in as the regular output does.

Signed-off-by: Lucas Barros <[email protected]>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I checked it with OpenSearch 3.9.0. A pipeline given on the _bulk request is applied to the data stream, and the ${tag} placeholder works too.

Two changes are needed before merging. Details are in the inline comments.

  1. Do not send the pipeline parameter when the expanded value is empty. OpenSearch rejects ?pipeline= for the whole request.
  2. Expand the pipeline at the top of write, before the records are processed.

OpenSearch rejects the whole bulk request for ?pipeline=, so do not
send the parameter when the pipeline is empty or its placeholders
expand to an empty string. Expand the pipeline at the top of write, so
a chunk whose pipeline cannot be built fails before any record is sent
to @error.

Co-authored-by: Shizuo Fujita <[email protected]>
Signed-off-by: Lucas Barros <[email protected]>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Both requested changes are implemented in 81d86dc. Empty pipeline values are no longer sent, and the three new tests fail on 1cef9dd and pass now.

However, my second request introduced a regression, and I am sorry about that. When the pipeline cannot be built, a chunk with only invalid records no longer reaches @ERROR. Details, a possible fix, and tests are in the inline comment.

…pipeline

Expanding the pipeline at the top of write kept a chunk with only
invalid records from reaching @error. Collect the invalid records,
expand the pipeline only when there are valid ones, and then send the
invalid records to @error. When the pipeline cannot be built, a mixed
chunk is still backed up as a whole.

Signed-off-by: Lucas Barros <[email protected]>
@lbarrosby

Copy link
Copy Markdown
Contributor Author

No problem, thanks for the follow-up. Pushed 6aeed9c:

  • The expansion at the top of write is gone. Invalid records are collected in the loop, the pipeline is expanded only when records is not empty, and then the invalid records go to @ERROR. The params[:pipeline] line is unchanged.
  • test_pipeline_is_expanded_before_records_are_processed is replaced by two tests with the same configuration and the tag /badtag, both asserting no bulk request:
    • test_invalid_records_go_to_error_when_pipeline_cannot_be_built: one record with an array req_id, one event in driver.error_events. It fails on 81d86dc.
    • test_chunk_with_valid_records_is_not_sent_to_error_when_pipeline_cannot_be_built: the same record and a valid one, driver.error_events is empty.

TZ=UTC bundle exec rake test: 466 tests, 0 failures, 0 errors. Without TZ=UTC, test_time_placeholder fails here on 81d86dc too, because the local date is not the UTC date.

@Watson1978 Watson1978 added the enhancement New feature or request label Nov 15, 2026
@Watson1978

Copy link
Copy Markdown
Contributor

The Ruby 3.1 jobs on macOS and Windows fail in the new test test_chunk_with_valid_records_is_not_sent_to_error_when_pipeline_cannot_be_built:

<[]> expected but was
<[["/badtag",
  ...,
  {"@timestamp"=>"...", "message"=>"bad", "req_id"=>[1]},
  #<ArgumentError: 'req_id' must not be an object or an array to be used as _id>]]>

The other jobs pass.

The test expects pipe-${tag} to fail to expand for the tag /badtag. That failure comes from the path check that Fluentd added in 1.19.3. With Ruby 3.1, CI installs Fluentd 1.18.0, so the pipeline expands without an error, and the invalid record goes to @ERROR.

Could you make this test pass with Fluentd versions before 1.19.3 too? For example, skip it there, or make the expansion fail in a way that does not depend on that check. The change in out_opensearch_data_stream.rb itself looks good.

@lbarrosby

Copy link
Copy Markdown
Contributor Author

Thanks for checking CI. Pushed 3b1fbac: test_chunk_with_valid_records_is_not_sent_to_error_when_pipeline_cannot_be_built is now omitted when Fluent::VERSION is older than 1.19.3, because only the path check from that version makes pipe-${tag} fail for /badtag. The test file also requires fluent/version for the check. The other test, with only the invalid record, still runs on every version.

  • Fluentd 1.20.1: TZ=UTC bundle exec rake test, 466 tests, 0 failures, 0 omissions.
  • Fluentd 1.18.0 (pinned in a separate Gemfile): test_out_opensearch_data_stream.rb, 77 tests, 0 failures, 1 omission. Without this commit, the same test fails there as in CI.

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. I verified the version check in 3b1fbac locally. I ran the data stream tests with Fluentd 1.18.0, 1.19.2, 1.19.3, and 1.19.4. The mixed-chunk test is omitted before 1.19.3, and it runs and passes from 1.19.3 on.

However, the change I asked for in my second review causes another regression, and I am sorry about that. It also affects configurations without pipeline. Details and a fix are in the inline comment.

The existing tests can stay as they are. A test for the shutdown timing is not needed.

…p without a pipeline

When the output shuts down during a long write, Fluentd sets router to
nil, so emitting the invalid records after the loop raised NoMethodError
and the whole chunk was handled as unrecoverable, also without pipeline.
Keep them for later only when pipeline is set, and with
emit_error_label_event false do not keep them at all.

Signed-off-by: Lucas Barros <[email protected]>

@Watson1978 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for applying the change. I checked b07980a locally.

  • Without pipeline, the shutdown reproduction from my last review now behaves like main.
  • With pipeline set and error events enabled, a record with an invalid ID reached @ERROR when it was alone in the chunk. When I added a valid record and the pipeline could not be built, the rejected record did not reach @ERROR.
  • The full test suite passes, also when merged with main at 76c177e. The data stream tests pass with Fluentd 1.18.0 (one omission) and 1.19.4.

LGTM.

@Watson1978
Watson1978 merged commit 0ba12d5 into fluent:main Nov 25, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants