Skip to content

Commit

Permalink
Merge pull request #706 from okkez/show-plugin-config-ancestors
Browse files Browse the repository at this point in the history
Show plugin config ancestors
  • Loading branch information
repeatedly committed Dec 8, 2015
1 parent a6904e3 commit 2b20c3f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/config/configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ def config_section(name, *args, &block)
end

def dump(level = 0)
dumped_config = "\n"
dumped_config = ""
indent = " " * level
@params.each do |name, config|
dumped_config << "#{indent}#{name}: #{config[1][:type]}: <#{@defaults[name].inspect}>"
dumped_config << " # #{@descriptions[name]}" if @descriptions[name]
dumped_config << "\n"
end
@sections.each do |section_name, sub_proxy|
dumped_config << "#{indent}#{section_name}#{sub_proxy.dump(level + 1)}"
dumped_config << "#{indent}#{section_name}\n#{sub_proxy.dump(level + 1)}"
end
dumped_config
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fluent/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def merged_configure_proxy
configurables.map{ |a| a.configure_proxy(a.name || a.object_id.to_s) }.reduce(:merge)
end

def dump
configure_proxy_map[self.to_s].dump
def dump(level = 0)
configure_proxy_map[self.to_s].dump(level)
end
end
end
Expand Down
14 changes: 13 additions & 1 deletion lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,19 @@ def show_plugin_config
$log.info "Show config for #{@show_plugin_config}"
name, type = @show_plugin_config.split(":")
plugin = Plugin.__send__("new_#{name}", type)
$log.info plugin.class.dump
dumped_config = "\n"
level = 0
plugin.class.ancestors.reverse_each do |plugin_class|
if plugin_class.respond_to?(:dump)
$log.on_debug do
dumped_config << plugin_class.name
dumped_config << "\n"
level = 1
end
dumped_config << plugin_class.dump(level)
end
end
$log.info dumped_config
exit 0
rescue => e
$log.error "show config failed: #{e}"
Expand Down
11 changes: 1 addition & 10 deletions test/config/test_configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,19 @@ class TestConfigureProxy < ::Test::Unit::TestCase
end

test 'empty proxy' do
assert_equal("\n", @proxy.dump)
assert_equal("", @proxy.dump)
end

test 'plain proxy w/o default value' do
@proxy.config_param(:name, :string)
assert_equal(<<CONFIG, @proxy.dump)
name: string: <nil>
CONFIG
end

test 'plain proxy w/ default value' do
@proxy.config_param(:name, :string, default: "name1")
assert_equal(<<CONFIG, @proxy.dump)
name: string: <"name1">
CONFIG
end
Expand All @@ -161,7 +159,6 @@ class TestConfigureProxy < ::Test::Unit::TestCase
@proxy.config_param(:name, :string)
@proxy.config_set_default(:name, "name1")
assert_equal(<<CONFIG, @proxy.dump)
name: string: <"name1">
CONFIG
end
Expand All @@ -171,7 +168,6 @@ class TestConfigureProxy < ::Test::Unit::TestCase
config_param(:name, :string, default: "name1")
end
assert_equal(<<CONFIG, @proxy.dump)
sub
name: string: <"name1">
CONFIG
Expand All @@ -187,7 +183,6 @@ class TestConfigureProxy < ::Test::Unit::TestCase
end
end
assert_equal(<<CONFIG, @proxy.dump)
sub
name1: string: <"name1">
name2: string: <"name2">
Expand All @@ -201,7 +196,6 @@ class TestConfigureProxy < ::Test::Unit::TestCase
test 'single proxy' do
@proxy.config_param(:name, :string, desc: "description for name")
assert_equal(<<CONFIG, @proxy.dump)
name: string: <nil> # description for name
CONFIG
end
Expand All @@ -210,7 +204,6 @@ class TestConfigureProxy < ::Test::Unit::TestCase
@proxy.config_param(:name, :string)
@proxy.config_set_desc(:name, "description for name")
assert_equal(<<CONFIG, @proxy.dump)
name: string: <nil> # description for name
CONFIG
end
Expand All @@ -225,7 +218,6 @@ class TestConfigureProxy < ::Test::Unit::TestCase
end
end
assert_equal(<<CONFIG, @proxy.dump)
sub
name1: string: <"name1"> # desc1
name2: string: <"name2"> # desc2
Expand All @@ -247,7 +239,6 @@ class TestConfigureProxy < ::Test::Unit::TestCase
end
end
assert_equal(<<CONFIG, @proxy.dump)
sub
name1: string: <"name1"> # desc1
name2: string: <"name2"> # desc2
Expand Down

0 comments on commit 2b20c3f

Please sign in to comment.