Repository navigation
filter_record_transformer: drop the new_ostruct_member leftover - #5713
Conversation
Watson1978
left a comment
There was a problem hiding this comment.
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_rubyexpression 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
OpenStructwithout requiringostruct. They work whenrecord_transformeris loaded before them. For example, with arecord_transformerfilter followed by fluent-plugin-groupcounter 0.2.3, fluentd now fails to start withuninitialized constant Fluent::GroupCounterOutput::OpenStruct. fluent-plugin-anonymizer 1.0.0 withipaddr_mask_keysfails 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>
7db1dd0 to
b051b01
Compare
|
Thanks for checking this against real plugins. Done as you asked: the |
Watson1978
left a comment
There was a problem hiding this comment.
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.
Which issue(s) this PR fixes:
None.
What this PR does / why we need it:
Drops the
new_ostruct_memberentry from the cleanroom's list ofObjectmethods it leaves defined infilter_record_transformer. The plugin stopped using OpenStruct in c2abe28 (faster ruby expander), and ostruct never defined that method onObject, so the entry matches nothing.Per review, the
require 'ostruct'and theostructruntime dependency stay: third-party plugins andenable_rubyexpressions 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