fluentd-ui 1.0.0.alpha.2 → 1.0.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd-ui might be problematic. Click here for more details.

Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +5 -0
  3. data/Gemfile.lock +56 -1
  4. data/README.md +2 -2
  5. data/app/controllers/api/config_definitions_controller.rb +55 -0
  6. data/app/controllers/api_controller.rb +20 -3
  7. data/app/controllers/concerns/setting_concern.rb +18 -2
  8. data/app/controllers/fluentd/settings/in_tail_controller.rb +13 -5
  9. data/app/controllers/fluentd/settings/out_forward_controller.rb +0 -9
  10. data/app/controllers/fluentd/settings/out_s3_controller.rb +0 -5
  11. data/app/controllers/fluentd/settings/out_tdlog_controller.rb +9 -0
  12. data/app/form_builders/fluentd_form_builder.rb +83 -0
  13. data/app/helpers/settings_helper.rb +81 -18
  14. data/app/javascript/packs/application.js +4 -0
  15. data/app/javascript/packs/in_tail_parse.js +159 -0
  16. data/app/javascript/packs/owned_plugin_form.js +141 -0
  17. data/app/javascript/packs/parser_multiline_form.js +51 -0
  18. data/app/javascript/packs/plugin_setting.js +19 -0
  19. data/app/models/concerns/fluentd/setting/configurable.rb +113 -0
  20. data/app/models/concerns/fluentd/setting/pattern.rb +11 -0
  21. data/app/models/concerns/fluentd/setting/plugin.rb +78 -0
  22. data/app/models/concerns/fluentd/setting/plugin_config.rb +74 -0
  23. data/app/models/concerns/fluentd/setting/plugin_parameter.rb +121 -0
  24. data/app/models/concerns/fluentd/setting/section_parser.rb +36 -0
  25. data/app/models/concerns/fluentd/setting/section_validator.rb +21 -0
  26. data/app/models/fluentd.rb +5 -5
  27. data/app/models/fluentd/setting/buffer_file.rb +23 -0
  28. data/app/models/fluentd/setting/buffer_memory.rb +17 -0
  29. data/app/models/fluentd/setting/formatter_csv.rb +21 -0
  30. data/app/models/fluentd/setting/formatter_hash.rb +19 -0
  31. data/app/models/fluentd/setting/formatter_json.rb +25 -0
  32. data/app/models/fluentd/setting/formatter_ltsv.rb +21 -0
  33. data/app/models/fluentd/setting/formatter_msgpack.rb +13 -0
  34. data/app/models/fluentd/setting/formatter_out_file.rb +21 -0
  35. data/app/models/fluentd/setting/formatter_single_value.rb +20 -0
  36. data/app/models/fluentd/setting/formatter_stdout.rb +19 -0
  37. data/app/models/fluentd/setting/formatter_tsv.rb +21 -0
  38. data/app/models/fluentd/setting/in_forward.rb +7 -17
  39. data/app/models/fluentd/setting/in_http.rb +13 -19
  40. data/app/models/fluentd/setting/in_monitor_agent.rb +6 -19
  41. data/app/models/fluentd/setting/in_syslog.rb +14 -12
  42. data/app/models/fluentd/setting/in_tail.rb +7 -84
  43. data/app/models/fluentd/setting/out_elasticsearch.rb +12 -21
  44. data/app/models/fluentd/setting/out_forward.rb +22 -66
  45. data/app/models/fluentd/setting/out_mongo.rb +20 -26
  46. data/app/models/fluentd/setting/out_s3.rb +18 -30
  47. data/app/models/fluentd/setting/out_stdout.rb +21 -18
  48. data/app/models/fluentd/setting/out_tdlog.rb +35 -0
  49. data/app/models/fluentd/setting/parser_apache.rb +13 -0
  50. data/app/models/fluentd/setting/parser_apache2.rb +13 -0
  51. data/app/models/fluentd/setting/parser_apache_error.rb +13 -0
  52. data/app/models/fluentd/setting/parser_csv.rb +22 -0
  53. data/app/models/fluentd/setting/parser_in_http.rb +13 -0
  54. data/app/models/fluentd/setting/parser_json.rb +25 -0
  55. data/app/models/fluentd/setting/parser_ltsv.rb +30 -0
  56. data/app/models/fluentd/setting/parser_msgpack.rb +13 -0
  57. data/app/models/fluentd/setting/parser_multiline.rb +24 -0
  58. data/app/models/fluentd/setting/parser_nginx.rb +13 -0
  59. data/app/models/fluentd/setting/parser_none.rb +19 -0
  60. data/app/models/fluentd/setting/parser_regexp.rb +26 -0
  61. data/app/models/fluentd/setting/parser_syslog.rb +29 -0
  62. data/app/models/fluentd/setting/parser_tsv.rb +19 -0
  63. data/app/models/fluentd/setting/section.rb +38 -0
  64. data/app/models/fluentd/setting/storage_local.rb +22 -0
  65. data/app/models/fluentd/setting/type/array.rb +17 -0
  66. data/app/models/fluentd/setting/type/bool.rb +18 -0
  67. data/app/models/fluentd/setting/type/enum.rb +17 -0
  68. data/app/models/fluentd/setting/type/hash.rb +17 -0
  69. data/app/models/fluentd/setting/type/regexp.rb +17 -0
  70. data/app/models/fluentd/setting/type/section.rb +17 -0
  71. data/app/models/fluentd/setting/type/size.rb +17 -0
  72. data/app/models/fluentd/setting/type/time.rb +17 -0
  73. data/app/views/api/settings/_element.json.jbuilder +1 -1
  74. data/app/views/fluentd/settings/in_forward/_form.html.haml +16 -0
  75. data/app/views/fluentd/settings/in_tail/_form.html.haml +22 -29
  76. data/app/views/fluentd/settings/in_tail/after_file_choose.html.haml +1 -1
  77. data/app/views/fluentd/settings/in_tail/after_format.html.haml +4 -4
  78. data/app/views/fluentd/settings/in_tail/confirm.html.haml +5 -5
  79. data/app/views/fluentd/settings/source_and_output.html.haml +1 -1
  80. data/app/views/shared/_global_nav.html.erb +8 -8
  81. data/app/views/shared/settings/_form.html.haml +40 -9
  82. data/app/views/shared/settings/show.html.haml +4 -1
  83. data/app/views/shared/vue/_in_tail_parse.html.haml +20 -0
  84. data/app/views/shared/vue/_owned_plugin_form.html.haml +68 -0
  85. data/app/views/shared/vue/_parser_multiline_form.html.haml +19 -0
  86. data/app/views/shared/vue/_setting.html.erb +1 -1
  87. data/config/application.rb +1 -1
  88. data/config/environment.rb +3 -0
  89. data/config/initializers/types.rb +7 -0
  90. data/config/routes.rb +2 -1
  91. data/fluentd-ui.gemspec +5 -0
  92. data/lib/fluentd-ui/version.rb +1 -1
  93. data/lib/regexp_preview.rb +2 -2
  94. data/lib/regexp_preview/multi_line.rb +53 -63
  95. data/lib/regexp_preview/single_line.rb +40 -46
  96. data/spec/features/fluentd/setting/out_forward_spec.rb +1 -1
  97. data/spec/features/fluentd/setting/out_stdout_spec.rb +1 -1
  98. data/spec/features/{out_td_spec.rb → out_tdlog_spec.rb} +3 -3
  99. data/spec/lib/regexp_preview/multi_line_spec.rb +29 -34
  100. data/spec/lib/regexp_preview/single_line_spec.rb +89 -87
  101. data/spec/models/fluentd/setting/in_forward_spec.rb +75 -0
  102. data/spec/models/fluentd/setting/in_http_spec.rb +31 -0
  103. data/spec/models/fluentd/setting/in_monitor_agent_spec.rb +31 -0
  104. data/spec/models/fluentd/setting/in_syslog_spec.rb +65 -7
  105. data/spec/models/fluentd/setting/in_tail_spec.rb +47 -0
  106. data/spec/models/fluentd/setting/out_elasticsearch_spec.rb +31 -0
  107. data/spec/models/fluentd/setting/out_mongo_spec.rb +35 -12
  108. data/spec/models/fluentd/setting/out_s3_spec.rb +128 -0
  109. data/spec/models/fluentd/setting/out_stdout_spec.rb +31 -0
  110. data/spec/models/fluentd/setting/out_tdlog_spec.rb +47 -0
  111. metadata +164 -38
  112. data/app/controllers/fluentd/settings/out_td_controller.rb +0 -18
  113. data/app/helpers/fluentd/settings_helper.rb +0 -2
  114. data/app/javascript/packs/in_tail_format.js +0 -174
  115. data/app/models/fluentd/setting/common.rb +0 -185
  116. data/app/models/fluentd/setting/out_td.rb +0 -48
  117. data/app/views/shared/vue/_in_tail_format.html.erb +0 -43
  118. data/spec/models/fluentd/setting/common_spec.rb +0 -178
  119. data/spec/models/fluentd/setting/out_td_spec.rb +0 -38
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+ import 'lodash/lodash'
3
+ import 'popper.js/dist/popper'
4
+ import 'bootstrap/dist/js/bootstrap'
5
+ import OwnedPluginForm from './owned_plugin_form'
6
+
7
+ window.addEventListener('load', () => {
8
+ new Vue({
9
+ el: '#plugin-setting',
10
+ data: () => {
11
+ return {}
12
+ },
13
+ components: {
14
+ 'owned-plugin-form': OwnedPluginForm
15
+ },
16
+ methods: {
17
+ }
18
+ })
19
+ })
@@ -0,0 +1,113 @@
1
+ class Fluentd
2
+ module Setting
3
+ module Configurable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ class_attribute :_types, :_defaults, :_secrets, :_aliases, :_required
8
+ class_attribute :_deprecated_params, :_obsoleted_params, :_descriptions
9
+ class_attribute :_list, :_value_types, :_symbolize_keys
10
+ class_attribute :_argument_name, :_built_in_params, :_sections, :_section_params
11
+ self._types = {}
12
+ self._defaults = {}
13
+ self._secrets = {}
14
+ self._aliases = {}
15
+ self._required = {}
16
+ self._deprecated_params = {}
17
+ self._obsoleted_params = {}
18
+ self._descriptions = {}
19
+ self._list = {}
20
+ self._value_types = {}
21
+ self._symbolize_keys = {}
22
+ self._argument_name = nil
23
+ self._built_in_params = []
24
+ self._sections = {}
25
+ self._section_params = Hash.new {|h, k| h[k] = [] }
26
+ end
27
+
28
+ def initialize(attributes = {})
29
+ # the superclass does not know specific attributes of the model
30
+ begin
31
+ super
32
+ rescue ActiveModel::UnknownAttributeError => ex
33
+ Rails.logger.warn(ex)
34
+ end
35
+ self.class._sections.each do |name, klass|
36
+ klass.init
37
+ if klass.multi
38
+ next if attributes[name].nil?
39
+ attributes[name].each do |attr|
40
+ next unless attr
41
+ attr.each do |index, _attr|
42
+ self._section_params[name] << klass.new(_attr)
43
+ end
44
+ end
45
+ else
46
+ attr = attributes.dig(name, "0")
47
+ self._section_params[name] << klass.new(attr) if attr
48
+ end
49
+ end
50
+ end
51
+
52
+ module ClassMethods
53
+ # config_param :name, :string, default: "value", secret: true
54
+ def config_param(name, type = ActiveModel::Type::Value.new, **options)
55
+ # NOTE: We cannot overwrite types defined by ActiveModel in config/initializers/types.rb
56
+ if type == :time
57
+ type = Fluentd::Setting::Type::Time.new
58
+ end
59
+ if name.to_s.start_with?("@")
60
+ _name = name.to_s[1..-1]
61
+ config_param(_name.to_sym, type, **options.merge(alias: name))
62
+ self._built_in_params << _name
63
+ elsif ["id", "type", "log_level"].include?(name.to_s)
64
+ self._built_in_params << name
65
+ unless name == "type"
66
+ attribute(name, type, **options.slice(:precision, :limit, :scale))
67
+ validates(name, presence: true) if options[:required]
68
+ end
69
+ else
70
+ attribute(name, type, **options.slice(:precision, :limit, :scale))
71
+ validates(name, presence: true) if options[:required]
72
+ end
73
+ self._types[name] = type
74
+ self._descriptions[name] = options[:desc] if options.key?(:desc)
75
+ self._defaults[name] = options[:default] if options.key?(:default)
76
+ self._secrets[name] = options[:secret] if options.key?(:secret)
77
+ self._aliases[name] = options[:alias] if options.key?(:alias)
78
+ self._required[name] = options[:required] if options.key?(:required)
79
+ self._deprecated_params[name] = options[:deprecated] if options.key?(:deprecated)
80
+ self._obsoleted_params[name] = options[:obsoleted] if options.key?(:obsoleted)
81
+ self._list[name] = options[:list] if options.key?(:list)
82
+ self._value_types[name] = options[:value_types] if options.key?(:value_types)
83
+ self._symbolize_keys = options[:symbolize_keys] if options.key?(:symbolize_keys)
84
+ end
85
+
86
+ def config_section(name, **options, &block)
87
+ if self._sections.key?(name)
88
+ self._sections[name].merge(**options, &block)
89
+ else
90
+ attribute(name, :section)
91
+ section_class = Class.new(::Fluentd::Setting::Section)
92
+ section_class.section_name = name
93
+ section_class.required = options[:required]
94
+ section_class.multi = options[:multi]
95
+ section_class.alias = options[:alias]
96
+ section_class._block = block
97
+ self.const_set(name.to_s.classify, section_class)
98
+ self._sections[name] = section_class
99
+ end
100
+ end
101
+
102
+ def config_argument(name, type = ActiveModel::Type::Value.new, **options)
103
+ config_param(name, **options)
104
+ self._argument_name = name
105
+ end
106
+
107
+ def set_argument_name(name)
108
+ self._argument_name = name
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,11 @@
1
+ class Fluentd
2
+ module Setting
3
+ module Pattern
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ config_argument(:pattern, :string)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,78 @@
1
+ require "fluent/plugin"
2
+
3
+ class Fluentd
4
+ module Setting
5
+ module Plugin
6
+ extend ActiveSupport::Concern
7
+
8
+ include ActiveModel::Model
9
+ include ActiveModel::Attributes
10
+ include Fluentd::Setting::Configurable
11
+ include Fluentd::Setting::PluginConfig
12
+ include Fluentd::Setting::SectionParser
13
+ include Fluentd::Setting::PluginParameter
14
+ include Fluentd::Setting::SectionValidator
15
+
16
+ included do
17
+ cattr_accessor :plugin_type, :plugin_name, :config_definition
18
+ end
19
+
20
+ module ClassMethods
21
+ def register_plugin(type, name)
22
+ self.plugin_type = type
23
+ self.plugin_name = name
24
+
25
+ if ["filter", "output"].include?(type)
26
+ include Fluentd::Setting::Pattern
27
+ end
28
+
29
+ self.load_plugin_config do |_name, params|
30
+ params.each do |param_name, definition|
31
+ if definition[:section]
32
+ parse_section(param_name, definition)
33
+ if %i(buffer storage parse format).include?(param_name)
34
+ attribute("#{param_name}_type", :string)
35
+ end
36
+ else
37
+ config_param(param_name, definition[:type], **definition.except(:type))
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def load_plugin_config
44
+ dumped_config = {}
45
+ plugin_class.ancestors.reverse_each do |klass|
46
+ next unless klass.respond_to?(:dump_config_definition)
47
+ dumped_config_definition = klass.dump_config_definition
48
+ dumped_config[klass.name] = dumped_config_definition unless dumped_config_definition.empty?
49
+ end
50
+ self.config_definition = dumped_config
51
+ dumped_config.each do |name, config|
52
+ yield name, config
53
+ end
54
+ end
55
+
56
+ def plugin_instance
57
+ @plugin_instance ||= Fluent::Plugin.__send__("new_#{plugin_type}", plugin_name)
58
+ end
59
+
60
+ def plugin_class
61
+ @plugin_class ||= plugin_instance.class
62
+ end
63
+
64
+ def plugin_helpers
65
+ @plugin_helpers ||= if plugin_instance.respond_to?(:plugin_helpers)
66
+ plugin_instance.plugin_helpers
67
+ else
68
+ []
69
+ end
70
+ end
71
+
72
+ def section?
73
+ false
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,74 @@
1
+ class Fluentd
2
+ module Setting
3
+ module PluginConfig
4
+ extend ActiveSupport::Concern
5
+
6
+ def to_config
7
+ name = case plugin_type
8
+ when "input"
9
+ "source"
10
+ when "output"
11
+ "match"
12
+ when "filter"
13
+ "filter"
14
+ when "parser"
15
+ "parse"
16
+ when "formatter"
17
+ "format"
18
+ when "buffer"
19
+ "buffer"
20
+ when "storage"
21
+ "storage"
22
+ end
23
+ _attributes = attributes.reject do |key, value|
24
+ %w(parse_type format_type buffer_type storage_type).include?(key.to_s)
25
+ end
26
+ _attributes = { "@type" => self.plugin_name }.merge(_attributes)
27
+ _attributes["@log_level"] = _attributes.delete("log_level")
28
+ argument = case plugin_type
29
+ when "output", "filter", "buffer"
30
+ _attributes.delete(self._argument_name.to_s) || ""
31
+ else
32
+ ""
33
+ end
34
+ attrs, elements = parse_attributes(_attributes)
35
+ config_element(name, argument, attrs, elements)
36
+ end
37
+
38
+ def parse_attributes(attributes)
39
+ base_klasses = config_definition.keys
40
+ sections, params = attributes.partition do |key, _section_attributes|
41
+ base_klasses.any? do |base_klass|
42
+ config_definition.dig(base_klass, key.to_sym, :section) || config_definition.dig(key.to_sym, :section)
43
+ end
44
+ end
45
+ elements = []
46
+ sections.to_h.each do |key, section_params|
47
+ if %w(parse format buffer storage).include?(key)
48
+ section_params["0"] = { "@type" => self.attributes["#{key}_type"] }.merge(section_params["0"])
49
+ end
50
+ next if section_params.blank?
51
+ section_params.each do |index, _section_params|
52
+ sub_attrs, sub_elements = parse_attributes(_section_params)
53
+ elements << config_element(key, "", sub_attrs, sub_elements)
54
+ end
55
+ end
56
+ return params.to_h.reject{|key, value| skip?(key.to_sym, value) }, elements
57
+ end
58
+
59
+ # copy from Fluent::Test::Helpers#config_element
60
+ def config_element(name = 'test', argument = '', params = {}, elements = [])
61
+ Fluent::Config::Element.new(name, argument, params, elements)
62
+ end
63
+
64
+ def skip?(key, value)
65
+ return true if value.blank?
66
+ if self._defaults.key?(key)
67
+ reformat_value(key, self._defaults[key]) == reformat_value(key, value)
68
+ else
69
+ false
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,121 @@
1
+ class Fluentd
2
+ module Setting
3
+ module PluginParameter
4
+ extend ActiveSupport::Concern
5
+
6
+ include Fluentd::Setting::Configurable
7
+
8
+ def column_type(name)
9
+ self.class._types[name]
10
+ end
11
+
12
+ def list_of(name)
13
+ self.class._list[name]
14
+ end
15
+
16
+ def desc(name)
17
+ self.class._descriptions[name]
18
+ end
19
+
20
+ def default(name)
21
+ reformat_value(name, self.class._defaults[name])
22
+ end
23
+
24
+ def common_options
25
+ []
26
+ end
27
+
28
+ def advanced_options
29
+ all_options - common_options - hidden_options
30
+ end
31
+
32
+ def hidden_options
33
+ []
34
+ end
35
+
36
+ def all_options
37
+ self.class._types.keys + self.class._sections.keys
38
+ end
39
+
40
+ def have_buffer_section?
41
+ self.class._sections.key?(:buffer)
42
+ end
43
+
44
+ def have_storage_section?
45
+ self.class._sections.key?(:storage)
46
+ end
47
+
48
+ def have_parse_section?
49
+ self.class._sections.key?(:parse)
50
+ end
51
+
52
+ def have_format_section?
53
+ self.class._sections.key?(:format)
54
+ end
55
+
56
+ def create_buffer
57
+ return unless have_buffer_section?
58
+ buffer_class = Fluentd::Setting.const_get("buffer_#{buffer_type}".classify)
59
+ buffer_class.new(buffer["0"].except("type"))
60
+ end
61
+
62
+ def create_storage
63
+ return unless have_storage_section?
64
+ storage_class = Fluentd::Setting.const_get("storage_#{storage_type}".classify)
65
+ storage_class.new(storage["0"].except("type"))
66
+ end
67
+
68
+ def create_parser
69
+ return unless have_parse_section?
70
+ parser_class = Fluentd::Setting.const_get("parser_#{parse_type}".classify)
71
+ parser_class.new(parse["0"].except("type"))
72
+ end
73
+
74
+ def create_formatter
75
+ return unless have_format_section?
76
+ formatter_class = Fluentd::Setting.const_get("formatter_#{format_type}".classify)
77
+ formatter_class.new(format["0"].except("type"))
78
+ end
79
+
80
+ def reformat_value(name, value)
81
+ type = column_type(name)
82
+ return value if type.nil? # name == :time_key
83
+ return value if type == :enum
84
+ return value if type == :regexp
85
+ type_name = if type.is_a?(Fluentd::Setting::Type::Time)
86
+ :time
87
+ else
88
+ type
89
+ end
90
+ Fluent::Config::REFORMAT_VALUE.call(type_name, value)
91
+ end
92
+
93
+ module ClassMethods
94
+ def column_type(name)
95
+ self._types[name]
96
+ end
97
+
98
+ def list_of(name)
99
+ self._list[name]
100
+ end
101
+
102
+ def permit_params
103
+ self.new # init
104
+ keys = self._types.keys
105
+ self._sections.each do |key, section|
106
+ keys << _permit_section(key, section)
107
+ end
108
+ keys
109
+ end
110
+
111
+ def _permit_section(key, section)
112
+ keys = { key => section._types.keys }
113
+ section._sections.each do |_key, _section|
114
+ keys[key] << _permit_section(_key, _section)
115
+ end
116
+ keys
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,36 @@
1
+ class Fluentd
2
+ module Setting
3
+ module SectionParser
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def parse_section(name, definition)
8
+ config_section(name, **definition.slice(:required, :multi, :alias)) do
9
+ definition.except(:section, :argument, :required, :multi, :alias).each do |_param_name, _definition|
10
+ if _definition[:section]
11
+ parse_section(_param_name, _definition)
12
+ else
13
+ if self._types.key?(_param_name)
14
+ if _definition.key?(:default)
15
+ self._defaults[_param_name] = _definition[:default]
16
+ self._required[_param_name] = false
17
+ self.clear_validators! # We register PresenceValidator only
18
+ end
19
+ self._secrets[_param_name] = _definition[:secret] if _definition.key?(:secret)
20
+ self._aliases[name] = _definition[:alias] if _definition.key?(:alias)
21
+ self._deprecated_params[name] = _definition[:deprecated] if _definition.key?(:deprecated)
22
+ self._obsoleted_params[name] = _definition[:obsoleted] if _definition.key?(:obsoleted)
23
+ self._list[name] = _definition[:list] if _definition.key?(:list)
24
+ self._value_types[name] = _definition[:value_types] if _definition.key?(:value_types)
25
+ self._symbolize_keys = _definition[:symbolize_keys] if _definition.key?(:symbolize_keys)
26
+ else
27
+ config_param(_param_name, _definition[:type], **_definition.except(:type))
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end