fluentd 1.11.2-x64-mingw32 → 1.12.1-x64-mingw32

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

Potentially problematic release.


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

Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  3. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  4. data/.github/workflows/build.yaml +29 -0
  5. data/.github/workflows/stale-actions.yml +22 -0
  6. data/.travis.yml +22 -2
  7. data/CHANGELOG.md +114 -0
  8. data/README.md +2 -2
  9. data/appveyor.yml +3 -0
  10. data/bin/fluent-cap-ctl +7 -0
  11. data/bin/fluent-ctl +7 -0
  12. data/fluentd.gemspec +8 -8
  13. data/lib/fluent/capability.rb +87 -0
  14. data/lib/fluent/command/ca_generate.rb +6 -3
  15. data/lib/fluent/command/cap_ctl.rb +174 -0
  16. data/lib/fluent/command/ctl.rb +177 -0
  17. data/lib/fluent/command/fluentd.rb +4 -0
  18. data/lib/fluent/command/plugin_config_formatter.rb +17 -2
  19. data/lib/fluent/config/section.rb +1 -1
  20. data/lib/fluent/env.rb +4 -0
  21. data/lib/fluent/log.rb +33 -3
  22. data/lib/fluent/plugin.rb +5 -0
  23. data/lib/fluent/plugin/buffer.rb +27 -57
  24. data/lib/fluent/plugin/buffer/chunk.rb +2 -1
  25. data/lib/fluent/plugin/formatter.rb +24 -0
  26. data/lib/fluent/plugin/formatter_csv.rb +1 -1
  27. data/lib/fluent/plugin/formatter_hash.rb +3 -1
  28. data/lib/fluent/plugin/formatter_json.rb +3 -1
  29. data/lib/fluent/plugin/formatter_ltsv.rb +5 -3
  30. data/lib/fluent/plugin/formatter_out_file.rb +6 -4
  31. data/lib/fluent/plugin/formatter_single_value.rb +4 -2
  32. data/lib/fluent/plugin/formatter_tsv.rb +4 -2
  33. data/lib/fluent/plugin/in_exec.rb +4 -2
  34. data/lib/fluent/plugin/in_http.rb +23 -2
  35. data/lib/fluent/plugin/in_tail.rb +109 -41
  36. data/lib/fluent/plugin/in_tail/position_file.rb +39 -14
  37. data/lib/fluent/plugin/in_tcp.rb +1 -0
  38. data/lib/fluent/plugin/out_http.rb +29 -4
  39. data/lib/fluent/plugin/output.rb +15 -6
  40. data/lib/fluent/plugin/parser_json.rb +5 -2
  41. data/lib/fluent/plugin_helper/http_server/compat/server.rb +1 -1
  42. data/lib/fluent/plugin_helper/inject.rb +4 -1
  43. data/lib/fluent/plugin_helper/retry_state.rb +4 -0
  44. data/lib/fluent/supervisor.rb +162 -51
  45. data/lib/fluent/system_config.rb +4 -2
  46. data/lib/fluent/time.rb +1 -0
  47. data/lib/fluent/version.rb +1 -1
  48. data/lib/fluent/winsvc.rb +22 -4
  49. data/templates/plugin_config_formatter/param.md-table.erb +10 -0
  50. data/test/command/test_binlog_reader.rb +22 -6
  51. data/test/command/test_cap_ctl.rb +100 -0
  52. data/test/command/test_ctl.rb +57 -0
  53. data/test/command/test_fluentd.rb +30 -0
  54. data/test/command/test_plugin_config_formatter.rb +124 -2
  55. data/test/plugin/in_tail/test_position_file.rb +46 -26
  56. data/test/plugin/test_buffer.rb +4 -0
  57. data/test/plugin/test_filter_stdout.rb +6 -1
  58. data/test/plugin/test_formatter_hash.rb +6 -3
  59. data/test/plugin/test_formatter_json.rb +14 -4
  60. data/test/plugin/test_formatter_ltsv.rb +13 -5
  61. data/test/plugin/test_formatter_out_file.rb +35 -14
  62. data/test/plugin/test_formatter_single_value.rb +12 -6
  63. data/test/plugin/test_formatter_tsv.rb +12 -4
  64. data/test/plugin/test_in_exec.rb +18 -0
  65. data/test/plugin/test_in_http.rb +25 -0
  66. data/test/plugin/test_in_tail.rb +433 -30
  67. data/test/plugin/test_out_file.rb +23 -18
  68. data/test/plugin/test_out_http.rb +19 -0
  69. data/test/plugin/test_output.rb +12 -0
  70. data/test/plugin/test_parser_syslog.rb +2 -2
  71. data/test/plugin/test_sd_file.rb +1 -1
  72. data/test/plugin_helper/test_compat_parameters.rb +7 -2
  73. data/test/plugin_helper/test_http_server_helper.rb +8 -1
  74. data/test/plugin_helper/test_inject.rb +42 -0
  75. data/test/plugin_helper/test_server.rb +18 -5
  76. data/test/test_capability.rb +74 -0
  77. data/test/test_formatter.rb +34 -10
  78. data/test/test_log.rb +44 -0
  79. data/test/test_output.rb +6 -1
  80. data/test/test_supervisor.rb +150 -1
  81. metadata +49 -37
@@ -75,6 +75,8 @@ HELP
75
75
 
76
76
  digest = OpenSSL::Digest::SHA256.new
77
77
 
78
+ factory = OpenSSL::X509::ExtensionFactory.new
79
+
78
80
  cert = OpenSSL::X509::Certificate.new
79
81
  cert.not_before = Time.at(0)
80
82
  cert.not_after = Time.now + 5 * 365 * 86400 # 5 years after
@@ -82,7 +84,7 @@ HELP
82
84
  cert.serial = 1
83
85
  cert.issuer = issuer
84
86
  cert.subject = subject
85
- cert.add_extension OpenSSL::X509::Extension.new('basicConstraints', OpenSSL::ASN1.Sequence([OpenSSL::ASN1::Boolean(true)]))
87
+ cert.add_extension(factory.create_extension('basicConstraints', 'CA:TRUE'))
86
88
  cert.sign(key, digest)
87
89
 
88
90
  return cert, key
@@ -111,8 +113,9 @@ HELP
111
113
  cert.issuer = issuer
112
114
  cert.subject = subject
113
115
 
114
- cert.add_extension OpenSSL::X509::Extension.new('basicConstraints', OpenSSL::ASN1.Sequence([OpenSSL::ASN1::Boolean(false)]))
115
- cert.add_extension OpenSSL::X509::Extension.new('nsCertType', 'server')
116
+ factory = OpenSSL::X509::ExtensionFactory.new
117
+ server_cert.add_extension(factory.create_extension('basicConstraints', 'CA:FALSE'))
118
+ server_cert.add_extension(factory.create_extension('nsCertType', 'server'))
116
119
 
117
120
  cert.sign ca_key, digest
118
121
 
@@ -0,0 +1,174 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'optparse'
18
+ require 'fluent/log'
19
+ require 'fluent/env'
20
+ require 'fluent/capability'
21
+
22
+ module Fluent
23
+ class CapCtl
24
+ def prepare_option_parser
25
+ @op = OptionParser.new
26
+
27
+ @op.on('--clear', "Clear Fluentd Ruby capability") {|s|
28
+ @opts[:clear_capabilities] = true
29
+ }
30
+
31
+ @op.on('--add [CAPABILITITY1,CAPABILITY2, ...]', "Add capabilities into Fluentd Ruby") {|s|
32
+ @opts[:add_capabilities] = s
33
+ }
34
+
35
+ @op.on('--drop [CAPABILITITY1,CAPABILITY2, ...]', "Drop capabilities from Fluentd Ruby") {|s|
36
+ @opts[:drop_capabilities] = s
37
+ }
38
+
39
+ @op.on('--get', "Get capabilities for Fluentd Ruby") {|s|
40
+ @opts[:get_capabilities] = true
41
+ }
42
+
43
+ @op.on('-f', '--file FILE', "Specify target file to add Linux capabilities") {|s|
44
+ @opts[:target_file] = s
45
+ }
46
+ end
47
+
48
+ def usage(msg)
49
+ puts @op.to_s
50
+ puts "error: #{msg}" if msg
51
+ exit 1
52
+ end
53
+
54
+ def initialize(argv = ARGV)
55
+ @opts = {}
56
+ @argv = argv
57
+
58
+ if Fluent.linux?
59
+ begin
60
+ require 'capng'
61
+
62
+ @capng = CapNG.new
63
+ rescue LoadError
64
+ puts "Error: capng_c is not loaded. Please install it first."
65
+ exit 1
66
+ end
67
+ else
68
+ puts "Error: This environment is not supported."
69
+ exit 2
70
+ end
71
+
72
+ prepare_option_parser
73
+ end
74
+
75
+ def call
76
+ parse_options!(@argv)
77
+
78
+ target_file = if !!@opts[:target_file]
79
+ @opts[:target_file]
80
+ else
81
+ File.readlink("/proc/self/exe")
82
+ end
83
+
84
+ if @opts[:clear_capabilities]
85
+ clear_capabilities(@opts, target_file)
86
+ elsif @opts[:add_capabilities]
87
+ add_capabilities(@opts, target_file)
88
+ elsif @opts[:drop_capabilities]
89
+ drop_capabilities(@opts, target_file)
90
+ end
91
+ if @opts[:get_capabilities]
92
+ get_capabilities(@opts, target_file)
93
+ end
94
+ end
95
+
96
+ def clear_capabilities(opts, target_file)
97
+ if !!opts[:clear_capabilities]
98
+ @capng.clear(:caps)
99
+ ret = @capng.apply_caps_file(target_file)
100
+ puts "Clear capabilities #{ret ? 'done' : 'fail'}."
101
+ end
102
+ end
103
+
104
+ def add_capabilities(opts, target_file)
105
+ if add_caps = opts[:add_capabilities]
106
+ @capng.clear(:caps)
107
+ @capng.caps_file(target_file)
108
+ capabilities = add_caps.split(/\s*,\s*/)
109
+ check_capabilities(capabilities, get_valid_capabilities)
110
+ ret = @capng.update(:add,
111
+ CapNG::Type::EFFECTIVE | CapNG::Type::INHERITABLE | CapNG::Type::PERMITTED,
112
+ capabilities)
113
+ puts "Updating #{add_caps} #{ret ? 'done' : 'fail'}."
114
+ ret = @capng.apply_caps_file(target_file)
115
+ puts "Adding #{add_caps} #{ret ? 'done' : 'fail'}."
116
+ end
117
+ end
118
+
119
+ def drop_capabilities(opts, target_file)
120
+ if drop_caps = opts[:drop_capabilities]
121
+ @capng.clear(:caps)
122
+ @capng.caps_file(target_file)
123
+ capabilities = drop_caps.split(/\s*,\s*/)
124
+ check_capabilities(capabilities, get_valid_capabilities)
125
+ ret = @capng.update(:drop,
126
+ CapNG::Type::EFFECTIVE | CapNG::Type::INHERITABLE | CapNG::Type::PERMITTED,
127
+ capabilities)
128
+ puts "Updating #{drop_caps} #{ret ? 'done' : 'fail'}."
129
+ @capng.apply_caps_file(target_file)
130
+ puts "Dropping #{drop_caps} #{ret ? 'done' : 'fail'}."
131
+ end
132
+ end
133
+
134
+ def get_capabilities(opts, target_file)
135
+ if opts[:get_capabilities]
136
+ @capng.caps_file(target_file)
137
+ print = CapNG::Print.new
138
+ puts "Capabilities in '#{target_file}',"
139
+ puts "Effective: #{print.caps_text(:buffer, :effective)}"
140
+ puts "Inheritable: #{print.caps_text(:buffer, :inheritable)}"
141
+ puts "Permitted: #{print.caps_text(:buffer, :permitted)}"
142
+ end
143
+ end
144
+
145
+ def get_valid_capabilities
146
+ capabilities = []
147
+ cap = CapNG::Capability.new
148
+ cap.each do |_code, capability|
149
+ capabilities << capability
150
+ end
151
+ capabilities
152
+ end
153
+
154
+ def check_capabilities(capabilities, valid_capabilities)
155
+ capabilities.each do |capability|
156
+ unless valid_capabilities.include?(capability)
157
+ raise ArgumentError, "'#{capability}' is not valid capability. Valid Capabilities are: #{valid_capabilities.join(", ")}"
158
+ end
159
+ end
160
+ end
161
+
162
+ def parse_options!(argv)
163
+ begin
164
+ rest = @op.parse(argv)
165
+
166
+ if rest.length != 0
167
+ usage nil
168
+ end
169
+ rescue
170
+ usage $!.to_s
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,177 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'optparse'
18
+ require 'fluent/env'
19
+ require 'fluent/version'
20
+ if Fluent.windows?
21
+ require 'win32/event'
22
+ require 'win32/service'
23
+ end
24
+
25
+ module Fluent
26
+ class Ctl
27
+ DEFAULT_OPTIONS = {}
28
+
29
+ if Fluent.windows?
30
+ include Windows::ServiceConstants
31
+ include Windows::ServiceStructs
32
+ include Windows::ServiceFunctions
33
+
34
+ COMMAND_MAP = {
35
+ shutdown: "",
36
+ restart: "HUP",
37
+ flush: "USR1",
38
+ reload: "USR2",
39
+ }
40
+ WINSVC_CONTROL_CODE_MAP = {
41
+ shutdown: SERVICE_CONTROL_STOP,
42
+ # 128 - 255: user-defined control code
43
+ # See https://docs.microsoft.com/en-us/windows/win32/api/winsvc/nf-winsvc-controlservice
44
+ restart: 128,
45
+ flush: 129,
46
+ reload: SERVICE_CONTROL_PARAMCHANGE,
47
+ }
48
+ else
49
+ COMMAND_MAP = {
50
+ shutdown: :TERM,
51
+ restart: :HUP,
52
+ flush: :USR1,
53
+ reload: :USR2,
54
+ }
55
+ end
56
+
57
+ def initialize(argv = ARGV)
58
+ @argv = argv
59
+ @options = {}
60
+ @opt_parser = OptionParser.new
61
+ configure_option_parser
62
+ @options.merge!(DEFAULT_OPTIONS)
63
+ parse_options!
64
+ end
65
+
66
+ def help_text
67
+ text = "\n"
68
+ if Fluent.windows?
69
+ text << "Usage: #{$PROGRAM_NAME} COMMAND [PID_OR_SVCNAME]\n"
70
+ else
71
+ text << "Usage: #{$PROGRAM_NAME} COMMAND PID\n"
72
+ end
73
+ text << "\n"
74
+ text << "Commands: \n"
75
+ COMMAND_MAP.each do |key, value|
76
+ text << " #{key}\n"
77
+ end
78
+ text
79
+ end
80
+
81
+ def usage(msg = nil)
82
+ puts help_text
83
+ if msg
84
+ puts
85
+ puts "Error: #{msg}"
86
+ end
87
+ exit 1
88
+ end
89
+
90
+ def call
91
+ if Fluent.windows?
92
+ if @pid_or_svcname =~ /^[0-9]+$/
93
+ # Use as PID
94
+ return call_windows_event(@command, "fluentd_#{@pid_or_svcname}")
95
+ end
96
+
97
+ unless call_winsvc_control_code(@command, @pid_or_svcname)
98
+ puts "Cannot send control code to #{@pid_or_svcname} service, try to send an event with this name ..."
99
+ call_windows_event(@command, @pid_or_svcname)
100
+ end
101
+ else
102
+ call_signal(@command, @pid_or_svcname)
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ def call_signal(command, pid)
109
+ signal = COMMAND_MAP[command.to_sym]
110
+ Process.kill(signal, pid.to_i)
111
+ end
112
+
113
+ def call_winsvc_control_code(command, pid_or_svcname)
114
+ status = SERVICE_STATUS.new
115
+
116
+ begin
117
+ handle_scm = OpenSCManager(nil, nil, SC_MANAGER_CONNECT)
118
+ FFI.raise_windows_error('OpenSCManager') if handle_scm == 0
119
+
120
+ handle_scs = OpenService(handle_scm, "fluentdwinsvc", SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_USER_DEFINED_CONTROL)
121
+ FFI.raise_windows_error('OpenService') if handle_scs == 0
122
+
123
+ control_code = WINSVC_CONTROL_CODE_MAP[command.to_sym]
124
+
125
+ unless ControlService(handle_scs, control_code, status)
126
+ FFI.raise_windows_error('ControlService')
127
+ end
128
+ rescue => e
129
+ puts e
130
+ state = status[:dwCurrentState]
131
+ return state == SERVICE_STOPPED || state == SERVICE_STOP_PENDING
132
+ ensure
133
+ CloseServiceHandle(handle_scs)
134
+ CloseServiceHandle(handle_scm)
135
+ end
136
+
137
+ return true
138
+ end
139
+
140
+ def call_windows_event(command, pid_or_svcname)
141
+ prefix = pid_or_svcname
142
+ event_name = COMMAND_MAP[command.to_sym]
143
+ suffix = event_name.empty? ? "" : "_#{event_name}"
144
+
145
+ begin
146
+ event = Win32::Event.open("#{prefix}#{suffix}")
147
+ event.set
148
+ event.close
149
+ rescue Errno::ENOENT => e
150
+ puts "Error: Cannot find the fluentd process with the event name: \"#{prefix}\""
151
+ end
152
+ end
153
+
154
+ def configure_option_parser
155
+ @opt_parser.banner = help_text
156
+ @opt_parser.version = Fluent::VERSION
157
+ end
158
+
159
+ def parse_options!
160
+ @opt_parser.parse!(@argv)
161
+
162
+ @command = @argv[0]
163
+ @pid_or_svcname = @argv[1] || "fluentdwinsvc"
164
+
165
+ usage("Command isn't specified!") if @command.nil? || @command.empty?
166
+ usage("Unknown command: #{@command}") unless COMMAND_MAP.has_key?(@command.to_sym)
167
+
168
+ if Fluent.windows?
169
+ usage("PID or SVCNAME isn't specified!") if @pid_or_svcname.nil? || @pid_or_svcname.empty?
170
+ else
171
+ usage("PID isn't specified!") if @pid_or_svcname.nil? || @pid_or_svcname.empty?
172
+ usage("Invalid PID: #{pid}") unless @pid_or_svcname =~ /^[0-9]+$/
173
+ end
174
+ end
175
+ end
176
+ end
177
+
@@ -163,6 +163,10 @@ op.on('--conf-encoding ENCODING', "specify configuration file encoding") { |s|
163
163
  opts[:conf_encoding] = s
164
164
  }
165
165
 
166
+ op.on('--disable-shared-socket', "Don't open shared socket for multiple workers") { |b|
167
+ opts[:disable_shared_socket] = b
168
+ }
169
+
166
170
  if Fluent.windows?
167
171
  require 'windows/library'
168
172
  include Windows::Library
@@ -29,7 +29,8 @@ class FluentPluginConfigFormatter
29
29
  AVAILABLE_FORMATS = [:markdown, :txt, :json]
30
30
  SUPPORTED_TYPES = [
31
31
  "input", "output", "filter",
32
- "buffer", "parser", "formatter", "storage"
32
+ "buffer", "parser", "formatter", "storage",
33
+ "service_discovery"
33
34
  ]
34
35
 
35
36
  DOCS_BASE_URL = "https://docs.fluentd.org/v/1.0"
@@ -161,9 +162,20 @@ class FluentPluginConfigFormatter
161
162
  else
162
163
  sections, params = base_section.partition {|_name, value| value[:section] }
163
164
  end
165
+ if @table and not params.empty?
166
+ dumped << "### Configuration\n\n"
167
+ dumped << "|parameter|type|description|default|\n"
168
+ dumped << "|---|---|---|---|\n"
169
+ end
164
170
  params.each do |name, config|
165
171
  next if name == :section
166
- template_name = @compact ? "param.md-compact.erb" : "param.md.erb"
172
+ template_name = if @compact
173
+ "param.md-compact.erb"
174
+ elsif @table
175
+ "param.md-table.erb"
176
+ else
177
+ "param.md.erb"
178
+ end
167
179
  template = template_path(template_name).read
168
180
  dumped <<
169
181
  if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
@@ -256,6 +268,9 @@ BANNER
256
268
  @parser.on("-p", "--plugin=DIR", "Add plugin directory") do |s|
257
269
  @plugin_dirs << s
258
270
  end
271
+ @parser.on("-t", "--table", "Use table syntax to dump parameters") do
272
+ @table = true
273
+ end
259
274
  end
260
275
 
261
276
  def parse_options!
@@ -247,7 +247,7 @@ module Fluent
247
247
  def self.check_unused_section(proxy, conf, plugin_class)
248
248
  elems = conf.respond_to?(:elements) ? conf.elements : []
249
249
  elems.each { |e|
250
- next if plugin_class.nil? && Fluent::Config::V1Parser::ELEM_SYMBOLS.include?(e.name) # skip pre-defined non-plugin elements because it doens't have proxy section
250
+ next if plugin_class.nil? && Fluent::Config::V1Parser::ELEM_SYMBOLS.include?(e.name) # skip pre-defined non-plugin elements because it doesn't have proxy section
251
251
  next if e.unused_in && e.unused_in.empty? # the section is used at least once
252
252
 
253
253
  if proxy.sections.any? { |name, subproxy| e.name == subproxy.name.to_s || e.name == subproxy.alias.to_s }
data/lib/fluent/env.rb CHANGED
@@ -28,4 +28,8 @@ module Fluent
28
28
  def self.windows?
29
29
  ServerEngine.windows?
30
30
  end
31
+
32
+ def self.linux?
33
+ /linux/ === RUBY_PLATFORM
34
+ end
31
35
  end