Skip to content

Commit

Permalink
Merge pull request #1556 from kazegusuri/check-buffer-class
Browse files Browse the repository at this point in the history
check variable buffer is a Buffer instance in MonitorAgentInput
  • Loading branch information
repeatedly authored May 7, 2017
2 parents 94577e2 + 04e61fd commit 182bebd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/fluent/plugin/in_monitor_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ def shutdown

MONITOR_INFO = {
'output_plugin' => ->(){ is_a?(::Fluent::Plugin::Output) },
'buffer_queue_length' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil?; @buffer.queue.size },
'buffer_total_queued_size' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil?; @buffer.stage_size },
'buffer_queue_length' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.queue.size },
'buffer_total_queued_size' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.stage_size },
'retry_count' => ->(){ instance_variable_defined?(:@num_errors) ? @num_errors : nil },
}

Expand Down
54 changes: 54 additions & 0 deletions test/plugin/test_in_monitor_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,58 @@ def write(chunk)
assert_equal("200", get("http://127.0.0.1:#{port}/api/plugins").code)
end
end

sub_test_case "check NoMethodError does not happen" do
class FluentTestBufferVariableOutput < ::Fluent::Plugin::Output
::Fluent::Plugin.register_output('test_out_buffer_variable', self)
def configure(conf)
super
@buffer = []
end

def write(chunk)
end
end
class FluentTestBufferVariableFilter < ::Fluent::Plugin::Filter
::Fluent::Plugin.register_filter("test_filter_buffer_variable", self)
def initialize
super
@buffer = {}
end
def filter(tag, time, record)
record
end
end

setup do
conf = <<-EOC
<match **>
@type test_out_buffer_variable
@id test_out_buffer_variable
</match>
<filter **>
@type test_filter_buffer_variable
@id test_filter_buffer_variable
</filter>
EOC
@ra = Fluent::RootAgent.new(log: $log)
stub(Fluent::Engine).root_agent { @ra }
@ra = configure_ra(@ra, conf)
end

test "plugins have a variable named buffer does not throws NoMethodError" do
port = unused_port
d = create_driver("
@type monitor_agent
bind '127.0.0.1'
port #{port}
include_config no
")
d.instance.start

assert_equal("200", get("http://127.0.0.1:#{port}/api/plugins.json").code)
assert{ d.logs.none?{|log| log.include?("NoMethodError") } }
assert_equal(false, d.instance.instance_variable_get(:@first_warn))
end
end
end

0 comments on commit 182bebd

Please sign in to comment.