Add transport section config definitions

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-06-19 17:25:57 +09:00
parent 6da22693c2
commit 5f10c5618b
No known key found for this signature in database
GPG Key ID: F9E3E329A5C5E4A1
3 changed files with 53 additions and 38 deletions

View File

@ -22,27 +22,8 @@ class Api::ConfigDefinitionsController < ApplicationController
target_class = Fluentd::Setting.const_get("#{prefix}_#{name}".classify)
target = target_class.new
common_options = target.common_options.map do |key|
h = {
name: key,
type: target.column_type(key),
desc: target.desc(key),
default: target.default(key)
}
h[:list] = target.list_of(key) if target.column_type(key) == :enum
h
end
advanced_options = target.advanced_options.map do |key|
h = {
name: key,
type: target.column_type(key),
desc: target.desc(key),
default: target.default(key)
}
h[:list] = target.list_of(key) if target.column_type(key) == :enum
h
end
common_options = build_options(target, target.common_options)
advanced_options = build_options(target, target.advanced_options)
options = {
type: type,
@ -50,6 +31,31 @@ class Api::ConfigDefinitionsController < ApplicationController
commonOptions: common_options,
advancedOptions: advanced_options
}
if type == "input" && ["forward", "syslog"].include?(name)
transport = target.class._sections[:transport]
transport_common_options = build_options(transport, target.transport_common_options)
transport_advanced_options = build_options(transport, target.transport_advanced_options)
options[:transport] = {
commonOptions: transport_common_options,
advancedOptions: transport_advanced_options
}
end
render json: options
end
private
def build_options(target, keys)
keys.map do |key|
h = {
name: key,
type: target.column_type(key),
desc: target.desc(key),
default: target.default(key)
}
h[:list] = target.list_of(key) if target.column_type(key) == :enum
h
end
end
end

View File

@ -89,6 +89,7 @@ class Fluentd
else
attribute(name, :section)
section_class = Class.new(::Fluentd::Setting::Section)
section_class.include(Fluentd::Setting::PluginParameter)
section_class.section_name = name
section_class.required = options[:required]
section_class.multi = options[:multi]

View File

@ -6,19 +6,19 @@ class Fluentd
include Fluentd::Setting::Configurable
def column_type(name)
self.class._types[name]
self.class.column_type(name)
end
def list_of(name)
self.class._list[name]
self.class.list_of(name)
end
def desc(name)
self.class._descriptions[name]
self.class.desc(name)
end
def default(name)
reformat_value(name, self.class._defaults[name])
self.class.reformat_value(name, self.class.default(name))
end
def common_options
@ -77,19 +77,6 @@ class Fluentd
formatter_class.new(format["0"].except("type"))
end
def reformat_value(name, value)
type = column_type(name)
return value if type.nil? # name == :time_key
return value if type == :enum
return value if type == :regexp
type_name = if type.is_a?(Fluentd::Setting::Type::Time)
:time
else
type
end
Fluent::Config::REFORMAT_VALUE.call(type_name, value)
end
module ClassMethods
def column_type(name)
self._types[name]
@ -99,6 +86,14 @@ class Fluentd
self._list[name]
end
def desc(name)
self._descriptions[name]
end
def default(name)
reformat_value(name, self._defaults[name])
end
def have_buffer_section?
self._sections.key?(:buffer)
end
@ -137,6 +132,19 @@ class Fluentd
end
keys
end
def reformat_value(name, value)
type = column_type(name)
return value if type.nil? # name == :time_key
return value if type == :enum
return value if type == :regexp
type_name = if type.is_a?(Fluentd::Setting::Type::Time)
:time
else
type
end
Fluent::Config::REFORMAT_VALUE.call(type_name, value)
end
end
end
end