Skip to content

Commit

Permalink
Merge pull request #3178 from fluent/handle-service-discovery-on-conf…
Browse files Browse the repository at this point in the history
…ig-formatter

Handle service_discovery type on fluent-plugin-config-formatter
  • Loading branch information
cosmo0920 committed Nov 24, 2020
2 parents 6b35ca0 + 82944b2 commit 47f87cf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
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"]
end
end
end
Expand Down

0 comments on commit 47f87cf

Please sign in to comment.