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

Handle service_discovery type on fluent-plugin-config-formatter #3178

Merged
merged 4 commits into from
Nov 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/fluent/command/plugin_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class FluentPluginConfigFormatter
AVAILABLE_FORMATS = [:markdown, :txt, :json]
SUPPORTED_TYPES = [
"input", "output", "filter",
"buffer", "parser", "formatter", "storage"
"buffer", "parser", "formatter", "storage",
"service_discovery"
]

DOCS_BASE_URL = "https://docs.fluentd.org/v/1.0"
Expand Down
5 changes: 5 additions & 0 deletions lib/fluent/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ def self.new_sd(type, parent: nil)
new_impl('sd', SD_REGISTRY, type, parent)
end

class << self
# This should be defined for fluent-plugin-config-formatter type arguments.
alias_method :new_service_discovery, :new_sd
end

def self.new_parser(type, parent: nil)
if type[0] == '/' && type[-1] == '/'
# This usage is not recommended for new API... create RegexpParser directly
Expand Down
59 changes: 57 additions & 2 deletions test/command/test_plugin_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ def format(tag, time, record)
end
end

class FakeStorage < ::Fluent::Plugin::Storage
::Fluent::Plugin.register_storage('fake', self)

def get(key)
end

def fetch(key, defval)
end

def put(key, value)
end

def delete(key)
end

def update(key, &block)
end
end

class FakeServiceDiscovery < ::Fluent::Plugin::ServiceDiscovery
::Fluent::Plugin.register_sd('fake', self)

desc "hostname"
config_param :hostname, :string
end

class SimpleInput < ::Fluent::Plugin::Input
::Fluent::Plugin.register_input("simple", self)
helpers :inject, :compat_parameters
Expand Down Expand Up @@ -88,6 +114,13 @@ def process(tag, es)
end
end

class SimpleServiceDiscovery < ::Fluent::Plugin::ServiceDiscovery
::Fluent::Plugin.register_sd('simple', self)

desc "servers"
config_param :servers, :array
end

sub_test_case "json" do
data(input: [FakeInput, "input"],
output: [FakeOutput, "output"],
Expand Down Expand Up @@ -196,6 +229,28 @@ def process(tag, es)
assert_equal(expected, dumped_config)
end

data("abbrev" => "sd",
"normal" => "service_discovery")
test "service_discovery simple" do |data|
plugin_type = data
dumped_config = capture_stdout do
FluentPluginConfigFormatter.new(["--format=markdown", plugin_type, "simple"]).call
end
expected = <<TEXT
* See also: [ServiceDiscovery Plugin Overview](https://docs.fluentd.org/v/1.0/servicediscovery#overview)

## TestFluentPluginConfigFormatter::SimpleServiceDiscovery

### servers (array) (required)

servers


TEXT
assert_equal(expected, dumped_config)
end


test "output complex" do
dumped_config = capture_stdout do
FluentPluginConfigFormatter.new(["--format=markdown", "output", "complex"]).call
Expand Down Expand Up @@ -251,15 +306,15 @@ def process(tag, es)
sub_test_case "arguments" do
data do
hash = {}
["input", "output", "filter", "parser", "formatter"].each do |type|
["input", "output", "filter", "parser", "formatter", "storage", "service_discovery"].each do |type|
["txt", "json", "markdown"].each do |format|
argv = ["--format=#{format}"]
[
["--verbose", "--compact"],
["--verbose"],
["--compact"]
].each do |options|
hash[(argv + options).join(" ")] = argv + options + [type, "fake"]
hash["[#{type}] " + (argv + options).join(" ")] = argv + options + [type, "fake"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this line's hash key was collided due to plugin type ignorance.

end
end
end
Expand Down