Skip to content

Commit

Permalink
Merge pull request #1015 from fluent/fix-configure-proxy-easier-for-d…
Browse files Browse the repository at this point in the history
…ebug

Fix to overwrite configure_proxy name only for root sections
  • Loading branch information
tagomoris committed Jun 2, 2016
2 parents 6b3187a + 4215844 commit dd0d05f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
26 changes: 23 additions & 3 deletions lib/fluent/config/configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ class ConfigureProxy
# end
# end

def initialize(name, param_name: nil, final: nil, init: nil, required: nil, multi: nil, alias: nil, type_lookup:)
def initialize(name, root: false, param_name: nil, final: nil, init: nil, required: nil, multi: nil, alias: nil, type_lookup:)
@name = name.to_sym
@final = final

# For ConfigureProxy of root section, "@name" should be a class name of plugins.
# Otherwise (like subsections), "@name" should be a name of section, like "buffer", "store".
# For subsections, name will be used as parameter names (unless param_name exists), so overriding proxy's name
# should override "@name".
@root_section = root

@param_name = param_name && param_name.to_sym
@init = init
@required = required
Expand All @@ -67,6 +73,10 @@ def variable_name
@param_name || @name
end

def root?
@root_section
end

def init?
@init.nil? ? false : @init
end
Expand Down Expand Up @@ -105,7 +115,12 @@ def merge(other) # self is base class, other is subclass
options[:final] = @final || other.final
options[:type_lookup] = @type_lookup

merged = self.class.new(@name, options)
merged = if self.root?
options[:root] = true
self.class.new(other.name, options)
else
self.class.new(@name, options)
end

# configured_in MUST be kept
merged.configured_in_section = self.configured_in_section
Expand Down Expand Up @@ -155,7 +170,12 @@ def merge_for_finalized(other)
options[:final] = true
options[:type_lookup] = @type_lookup

merged = self.class.new(@name, options)
merged = if self.root?
options[:root] = true
self.class.new(other.name, options)
else
self.class.new(@name, options)
end

merged.configured_in_section = self.configured_in_section

Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def configure_proxy(mod_name)
map = configure_proxy_map
unless map[mod_name]
type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
proxy = Fluent::Config::ConfigureProxy.new(mod_name, required: true, multi: false, type_lookup: type_lookup)
proxy = Fluent::Config::ConfigureProxy.new(mod_name, root: true, required: true, multi: false, type_lookup: type_lookup)
map[mod_name] = proxy
end
map[mod_name]
Expand Down
15 changes: 15 additions & 0 deletions test/config/test_configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TestConfigureProxy < ::Test::Unit::TestCase
assert_equal(:section, proxy.name)
assert_nil(proxy.param_name)
assert_equal(:section, proxy.variable_name)
assert_false(proxy.root?)
assert_nil(proxy.init)
assert_nil(proxy.required)
assert_false(proxy.required?)
Expand Down Expand Up @@ -94,6 +95,20 @@ class TestConfigureProxy < ::Test::Unit::TestCase
assert_false(proxy.multi?)
assert_equal :subsection, proxy.configured_in_section
end

test "does overwrite name of proxy for root sections which are used for plugins" do
# latest plugin class shows actual plugin implementation
p1 = Fluent::Config::ConfigureProxy.new('Fluent::Plugin::MyP1'.to_sym, root: true, required: true, multi: false, type_lookup: @type_lookup)
p1.config_param :key1, :integer

p2 = Fluent::Config::ConfigureProxy.new('Fluent::Plugin::MyP2'.to_sym, root: true, required: true, multi: false, type_lookup: @type_lookup)
p2.config_param :key2, :string, default: "value2"

merged = p1.merge(p2)

assert_equal 'Fluent::Plugin::MyP2'.to_sym, merged.name
assert_true merged.root?
end
end

sub_test_case '#overwrite_defaults' do
Expand Down

0 comments on commit dd0d05f

Please sign in to comment.