Skip to content

filter_record_transformer: drop the new_ostruct_member leftover - #5713

Merged
Watson1978 merged 1 commit into
fluent:masterfrom
amatsuda:record-transformer-drop-ostruct
Dec 2, 2026
Merged

Watson1978 merged 1 commit into
fluent:masterfrom
amatsuda:record-transformer-drop-ostruct

Conversation

@amatsuda

@amatsuda amatsuda commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Which issue(s) this PR fixes:
None.

What this PR does / why we need it:
Drops the new_ostruct_member entry from the cleanroom's list of Object methods it leaves defined in filter_record_transformer. The plugin stopped using OpenStruct in c2abe28 (faster ruby expander), and ostruct never defined that method on Object, so the entry matches nothing.

Per review, the require 'ostruct' and the ostruct runtime dependency stay: third-party plugins and enable_ruby expressions use OpenStruct without requiring it themselves and rely on fluentd loading it (fluent-plugin-record-reformer, fluent-plugin-groupcounter, fluent-plugin-anonymizer).

test/plugin/test_filter_record_transformer.rb: 65 tests, 0 failures.

Docs Changes:
Not needed.

Release Note:
Not needed.

🤖 Generated with Claude Code

@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 cleanup, and for pointing out the enable_ruby case. We would prefer the conservative alternative from the PR description. Please restore require 'ostruct' in filter_record_transformer.rb and the ostruct runtime dependency (~> 0.6) in fluentd.gemspec. The diff against master should then be one change: remove |new_ostruct_member from the cleanroom regular expression. That part is fine. ostruct does not define new_ostruct_member on Object, so the entry is just a leftover.

We tried both removals on Ruby 4.0.10. Each one breaks setups that work on master.

MUST: Keep the ostruct runtime dependency in fluentd.gemspec.

Some third-party plugins require 'ostruct' but do not declare it in their gemspec. Under Bundler (bundle exec or fluentd --gemfile), they rely on fluentd's dependency to put ostruct in the bundle. Without it, Ruby 4.0 raises LoadError, unless another gem in the bundle depends on ostruct. For example, with fluent-plugin-record-reformer 0.9.1:

<match test>
  @type record_reformer
  tag out
</match>
<match out>
  @type null
</match>

On master, fluentd --dry-run finishes. On this PR, it fails with cannot load such file -- ostruct from out_record_reformer/core.rb:1. The config does not need record_transformer. fluent-plugin-statsd-output 1.4.2 and a few older plugins follow the same pattern. Without Bundler, this example works on both.

This also affects the migration in the Release Note. Under Bundler on Ruby 4.0, an enable_ruby expression such as ${require 'ostruct'; OpenStruct.new(record).n} works on master. On this PR, it raises LoadError, and in our test the sample input stopped.

MUST: Keep require 'ostruct' in filter_record_transformer.rb.

Today OpenStruct is defined once record_transformer is loaded. Without the require, and when nothing else has loaded ostruct, two things that work on master break, with or without Bundler:

  • An enable_ruby expression such as ${OpenStruct.new(x: record["a"]).x} fails for every event. The records go to the error stream instead of being transformed.
  • Some plugins use OpenStruct without requiring ostruct. They work when record_transformer is loaded before them. For example, with a record_transformer filter followed by fluent-plugin-groupcounter 0.2.3, fluentd now fails to start with uninitialized constant Fluent::GroupCounterOutput::OpenStruct. fluent-plugin-anonymizer 1.0.0 with ipaddr_mask_keys fails the same way.

Those plugins should require and declare ostruct themselves. Still, users would hit these errors right after upgrading fluentd.

The cleanroom keeps `new_ostruct_member` in the list of Object methods
it leaves defined. The plugin stopped using OpenStruct in c2abe28
(record_transformer: faster implementation of ruby expander), and
ostruct never defined that method on Object, so the entry matches
nothing.

The `require 'ostruct'` and the ostruct runtime dependency stay: some
third-party plugins and `enable_ruby` expressions use OpenStruct
without requiring it themselves, and rely on fluentd loading it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Akira Matsuda <ronnie@dio.jp>
@amatsuda
amatsuda force-pushed the record-transformer-drop-ostruct branch from 7db1dd0 to b051b01 Compare December 2, 2026 08:02
@amatsuda amatsuda changed the title filter_record_transformer: drop the unused ostruct require and dependency filter_record_transformer: drop the new_ostruct_member leftover Dec 2, 2026
@amatsuda

amatsuda commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking this against real plugins. Done as you asked: the require 'ostruct' and the ostruct runtime dependency are back, and the only change against master is removing |new_ostruct_member from the cleanroom regular expression. The commit is amended and force-pushed, and the title and description now match.

@Watson1978 Watson1978 added this to the v1.21.0 milestone Dec 2, 2026

@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. The diff now only removes |new_ostruct_member from the cleanroom regular expression, and both require 'ostruct' and the ostruct runtime dependency stay.

We reran the examples from our previous review on Ruby 4.0.10. The record_reformer dry run under Bundler and the dry run with record_transformer followed by groupcounter both pass, as on master. The anonymizer example and both enable_ruby expressions produce the same records as on master. In our environment, CleanroomExpander also has the same instance methods on both versions. LGTM.

@Watson1978
Watson1978 merged commit 31157cb into fluent:master Dec 2, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants