Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_monitor_agent: enable to select instance variables of plugins #1393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/fluent/plugin/in_monitor_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def build_object(req, res)
opts[:pretty_json] = true
end

if ivars = (qs['with_ivars'] || []).first
opts[:ivars] = ivars.split(',')
end

if with_config = get_search_parameter(qs, 'with_config'.freeze)
opts[:with_config] = Fluent::Config.bool_value(with_config)
end
Expand Down Expand Up @@ -364,6 +368,13 @@ def get_monitor_info(pe, opts={})
}
end
obj['instance_variables'] = iv
elsif ivars = opts[:ivars]
iv = {}
ivars.each {|name|
iname = "@#{name}"
iv[name] = pe.instance_variable_get(iname) if pe.instance_variable_defined?(iname)
}
obj['instance_variables'] = iv
end

obj
Expand Down
33 changes: 33 additions & 0 deletions test/plugin/test_in_monitor_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,39 @@ def get(uri, header = {})
assert_equal(expected_null_response, null_response)
end

test "/api/plugins.json with 'with_ivars'. response contains specified instance variables of each plugin" do
d = create_driver("
@type monitor_agent
bind '127.0.0.1'
port #{@port}
tag monitor
")
d.instance.start
expected_test_in_response = {
"output_plugin" => false,
"plugin_category" => "input",
"plugin_id" => "test_in",
"retry_count" => nil,
"type" => "test_in",
"instance_variables" => {"id" => "test_in"}
}
expected_null_response = {
"buffer_queue_length" => 0,
"buffer_total_queued_size" => 0,
"output_plugin" => true,
"plugin_category" => "output",
"plugin_id" => "null",
"retry_count" => 0,
"type" => "null",
"instance_variables" => {"id" => "null", "num_errors" => 0}
}
response = JSON.parse(get("http://127.0.0.1:#{@port}/api/plugins.json?with_config=no&with_retry=no&with_ivars=id,num_errors"))
test_in_response = response["plugins"][0]
null_response = response["plugins"][5]
assert_equal(expected_test_in_response, test_in_response)
assert_equal(expected_null_response, null_response)
end

test "/api/config" do
d = create_driver("
@type monitor_agent
Expand Down