fluentd 1.17.0-x86-mingw32 → 1.18.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -0
  3. data/README.md +1 -0
  4. data/SECURITY.md +2 -2
  5. data/fluent.conf +14 -14
  6. data/lib/fluent/command/cap_ctl.rb +4 -4
  7. data/lib/fluent/command/fluentd.rb +7 -1
  8. data/lib/fluent/compat/call_super_mixin.rb +3 -3
  9. data/lib/fluent/compat/propagate_default.rb +4 -4
  10. data/lib/fluent/config/literal_parser.rb +9 -2
  11. data/lib/fluent/config/yaml_parser/parser.rb +4 -0
  12. data/lib/fluent/engine.rb +49 -33
  13. data/lib/fluent/env.rb +3 -0
  14. data/lib/fluent/event_router.rb +2 -2
  15. data/lib/fluent/log/console_adapter.rb +4 -2
  16. data/lib/fluent/plugin/filter_parser.rb +27 -51
  17. data/lib/fluent/plugin/in_exec.rb +14 -2
  18. data/lib/fluent/plugin/in_http.rb +6 -1
  19. data/lib/fluent/plugin/in_sample.rb +13 -7
  20. data/lib/fluent/plugin/in_syslog.rb +4 -0
  21. data/lib/fluent/plugin/in_tail.rb +65 -23
  22. data/lib/fluent/plugin/in_tcp.rb +4 -0
  23. data/lib/fluent/plugin/in_udp.rb +10 -1
  24. data/lib/fluent/plugin/input.rb +4 -0
  25. data/lib/fluent/plugin/out_buffer.rb +40 -0
  26. data/lib/fluent/plugin/out_copy.rb +1 -1
  27. data/lib/fluent/plugin/out_file.rb +8 -0
  28. data/lib/fluent/plugin/out_http.rb +12 -0
  29. data/lib/fluent/plugin/output.rb +2 -0
  30. data/lib/fluent/plugin/parser_json.rb +4 -12
  31. data/lib/fluent/plugin_helper/cert_option.rb +8 -0
  32. data/lib/fluent/plugin_helper/event_emitter.rb +12 -0
  33. data/lib/fluent/plugin_helper/http_server/server.rb +24 -8
  34. data/lib/fluent/plugin_helper/server.rb +9 -0
  35. data/lib/fluent/root_agent.rb +114 -19
  36. data/lib/fluent/source_only_buffer_agent.rb +102 -0
  37. data/lib/fluent/supervisor.rb +207 -34
  38. data/lib/fluent/system_config.rb +15 -3
  39. data/lib/fluent/version.rb +1 -1
  40. data/templates/new_gem/fluent-plugin.gemspec.erb +6 -5
  41. metadata +24 -483
  42. data/.github/DISCUSSION_TEMPLATE/q-a-japanese.yml +0 -50
  43. data/.github/DISCUSSION_TEMPLATE/q-a.yml +0 -47
  44. data/.github/ISSUE_TEMPLATE/bug_report.yml +0 -71
  45. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  46. data/.github/ISSUE_TEMPLATE/feature_request.yml +0 -39
  47. data/.github/ISSUE_TEMPLATE.md +0 -17
  48. data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
  49. data/.github/workflows/stale-actions.yml +0 -24
  50. data/.github/workflows/test-ruby-head.yml +0 -31
  51. data/.github/workflows/test.yml +0 -32
  52. data/.gitignore +0 -30
  53. data/Gemfile +0 -9
  54. data/fluentd.gemspec +0 -62
  55. data/test/command/test_binlog_reader.rb +0 -362
  56. data/test/command/test_ca_generate.rb +0 -70
  57. data/test/command/test_cap_ctl.rb +0 -100
  58. data/test/command/test_cat.rb +0 -128
  59. data/test/command/test_ctl.rb +0 -56
  60. data/test/command/test_fluentd.rb +0 -1291
  61. data/test/command/test_plugin_config_formatter.rb +0 -397
  62. data/test/command/test_plugin_generator.rb +0 -109
  63. data/test/compat/test_calls_super.rb +0 -166
  64. data/test/compat/test_parser.rb +0 -92
  65. data/test/config/assertions.rb +0 -42
  66. data/test/config/test_config_parser.rb +0 -551
  67. data/test/config/test_configurable.rb +0 -1784
  68. data/test/config/test_configure_proxy.rb +0 -604
  69. data/test/config/test_dsl.rb +0 -415
  70. data/test/config/test_element.rb +0 -518
  71. data/test/config/test_literal_parser.rb +0 -309
  72. data/test/config/test_plugin_configuration.rb +0 -56
  73. data/test/config/test_section.rb +0 -191
  74. data/test/config/test_system_config.rb +0 -195
  75. data/test/config/test_types.rb +0 -408
  76. data/test/counter/test_client.rb +0 -563
  77. data/test/counter/test_error.rb +0 -44
  78. data/test/counter/test_mutex_hash.rb +0 -179
  79. data/test/counter/test_server.rb +0 -589
  80. data/test/counter/test_store.rb +0 -258
  81. data/test/counter/test_validator.rb +0 -137
  82. data/test/helper.rb +0 -155
  83. data/test/helpers/fuzzy_assert.rb +0 -89
  84. data/test/helpers/process_extenstion.rb +0 -33
  85. data/test/log/test_console_adapter.rb +0 -117
  86. data/test/plugin/data/2010/01/20100102-030405.log +0 -0
  87. data/test/plugin/data/2010/01/20100102-030406.log +0 -0
  88. data/test/plugin/data/2010/01/20100102.log +0 -0
  89. data/test/plugin/data/log/bar +0 -0
  90. data/test/plugin/data/log/foo/bar.log +0 -0
  91. data/test/plugin/data/log/foo/bar2 +0 -0
  92. data/test/plugin/data/log/test.log +0 -0
  93. data/test/plugin/data/log_numeric/01.log +0 -0
  94. data/test/plugin/data/log_numeric/02.log +0 -0
  95. data/test/plugin/data/log_numeric/12.log +0 -0
  96. data/test/plugin/data/log_numeric/14.log +0 -0
  97. data/test/plugin/data/sd_file/config +0 -11
  98. data/test/plugin/data/sd_file/config.json +0 -17
  99. data/test/plugin/data/sd_file/config.yaml +0 -11
  100. data/test/plugin/data/sd_file/config.yml +0 -11
  101. data/test/plugin/data/sd_file/invalid_config.yml +0 -7
  102. data/test/plugin/in_tail/test_fifo.rb +0 -121
  103. data/test/plugin/in_tail/test_io_handler.rb +0 -150
  104. data/test/plugin/in_tail/test_position_file.rb +0 -346
  105. data/test/plugin/out_forward/test_ack_handler.rb +0 -140
  106. data/test/plugin/out_forward/test_connection_manager.rb +0 -145
  107. data/test/plugin/out_forward/test_handshake_protocol.rb +0 -112
  108. data/test/plugin/out_forward/test_load_balancer.rb +0 -106
  109. data/test/plugin/out_forward/test_socket_cache.rb +0 -174
  110. data/test/plugin/test_bare_output.rb +0 -131
  111. data/test/plugin/test_base.rb +0 -247
  112. data/test/plugin/test_buf_file.rb +0 -1314
  113. data/test/plugin/test_buf_file_single.rb +0 -898
  114. data/test/plugin/test_buf_memory.rb +0 -42
  115. data/test/plugin/test_buffer.rb +0 -1493
  116. data/test/plugin/test_buffer_chunk.rb +0 -209
  117. data/test/plugin/test_buffer_file_chunk.rb +0 -871
  118. data/test/plugin/test_buffer_file_single_chunk.rb +0 -611
  119. data/test/plugin/test_buffer_memory_chunk.rb +0 -339
  120. data/test/plugin/test_compressable.rb +0 -87
  121. data/test/plugin/test_file_util.rb +0 -96
  122. data/test/plugin/test_filter.rb +0 -368
  123. data/test/plugin/test_filter_grep.rb +0 -697
  124. data/test/plugin/test_filter_parser.rb +0 -731
  125. data/test/plugin/test_filter_record_transformer.rb +0 -577
  126. data/test/plugin/test_filter_stdout.rb +0 -207
  127. data/test/plugin/test_formatter_csv.rb +0 -136
  128. data/test/plugin/test_formatter_hash.rb +0 -38
  129. data/test/plugin/test_formatter_json.rb +0 -61
  130. data/test/plugin/test_formatter_ltsv.rb +0 -70
  131. data/test/plugin/test_formatter_msgpack.rb +0 -28
  132. data/test/plugin/test_formatter_out_file.rb +0 -116
  133. data/test/plugin/test_formatter_single_value.rb +0 -44
  134. data/test/plugin/test_formatter_tsv.rb +0 -76
  135. data/test/plugin/test_in_debug_agent.rb +0 -49
  136. data/test/plugin/test_in_exec.rb +0 -261
  137. data/test/plugin/test_in_forward.rb +0 -1178
  138. data/test/plugin/test_in_gc_stat.rb +0 -62
  139. data/test/plugin/test_in_http.rb +0 -1124
  140. data/test/plugin/test_in_monitor_agent.rb +0 -922
  141. data/test/plugin/test_in_object_space.rb +0 -66
  142. data/test/plugin/test_in_sample.rb +0 -190
  143. data/test/plugin/test_in_syslog.rb +0 -505
  144. data/test/plugin/test_in_tail.rb +0 -3429
  145. data/test/plugin/test_in_tcp.rb +0 -328
  146. data/test/plugin/test_in_udp.rb +0 -296
  147. data/test/plugin/test_in_unix.rb +0 -181
  148. data/test/plugin/test_input.rb +0 -137
  149. data/test/plugin/test_metadata.rb +0 -89
  150. data/test/plugin/test_metrics.rb +0 -294
  151. data/test/plugin/test_metrics_local.rb +0 -96
  152. data/test/plugin/test_multi_output.rb +0 -204
  153. data/test/plugin/test_out_copy.rb +0 -308
  154. data/test/plugin/test_out_exec.rb +0 -312
  155. data/test/plugin/test_out_exec_filter.rb +0 -606
  156. data/test/plugin/test_out_file.rb +0 -1038
  157. data/test/plugin/test_out_forward.rb +0 -1349
  158. data/test/plugin/test_out_http.rb +0 -557
  159. data/test/plugin/test_out_null.rb +0 -105
  160. data/test/plugin/test_out_relabel.rb +0 -28
  161. data/test/plugin/test_out_roundrobin.rb +0 -146
  162. data/test/plugin/test_out_secondary_file.rb +0 -458
  163. data/test/plugin/test_out_stdout.rb +0 -205
  164. data/test/plugin/test_out_stream.rb +0 -103
  165. data/test/plugin/test_output.rb +0 -1334
  166. data/test/plugin/test_output_as_buffered.rb +0 -2024
  167. data/test/plugin/test_output_as_buffered_backup.rb +0 -363
  168. data/test/plugin/test_output_as_buffered_compress.rb +0 -179
  169. data/test/plugin/test_output_as_buffered_overflow.rb +0 -250
  170. data/test/plugin/test_output_as_buffered_retries.rb +0 -966
  171. data/test/plugin/test_output_as_buffered_secondary.rb +0 -882
  172. data/test/plugin/test_output_as_standard.rb +0 -374
  173. data/test/plugin/test_owned_by.rb +0 -34
  174. data/test/plugin/test_parser.rb +0 -399
  175. data/test/plugin/test_parser_apache.rb +0 -42
  176. data/test/plugin/test_parser_apache2.rb +0 -47
  177. data/test/plugin/test_parser_apache_error.rb +0 -45
  178. data/test/plugin/test_parser_csv.rb +0 -200
  179. data/test/plugin/test_parser_json.rb +0 -244
  180. data/test/plugin/test_parser_labeled_tsv.rb +0 -160
  181. data/test/plugin/test_parser_msgpack.rb +0 -127
  182. data/test/plugin/test_parser_multiline.rb +0 -111
  183. data/test/plugin/test_parser_nginx.rb +0 -88
  184. data/test/plugin/test_parser_none.rb +0 -52
  185. data/test/plugin/test_parser_regexp.rb +0 -284
  186. data/test/plugin/test_parser_syslog.rb +0 -650
  187. data/test/plugin/test_parser_tsv.rb +0 -122
  188. data/test/plugin/test_sd_file.rb +0 -228
  189. data/test/plugin/test_sd_srv.rb +0 -230
  190. data/test/plugin/test_storage.rb +0 -166
  191. data/test/plugin/test_storage_local.rb +0 -335
  192. data/test/plugin/test_string_util.rb +0 -26
  193. data/test/plugin_helper/data/cert/cert-key.pem +0 -27
  194. data/test/plugin_helper/data/cert/cert-with-CRLF.pem +0 -19
  195. data/test/plugin_helper/data/cert/cert-with-no-newline.pem +0 -19
  196. data/test/plugin_helper/data/cert/cert.pem +0 -19
  197. data/test/plugin_helper/data/cert/cert_chains/ca-cert-key.pem +0 -27
  198. data/test/plugin_helper/data/cert/cert_chains/ca-cert.pem +0 -20
  199. data/test/plugin_helper/data/cert/cert_chains/cert-key.pem +0 -27
  200. data/test/plugin_helper/data/cert/cert_chains/cert.pem +0 -40
  201. data/test/plugin_helper/data/cert/empty.pem +0 -0
  202. data/test/plugin_helper/data/cert/generate_cert.rb +0 -125
  203. data/test/plugin_helper/data/cert/with_ca/ca-cert-key-pass.pem +0 -30
  204. data/test/plugin_helper/data/cert/with_ca/ca-cert-key.pem +0 -27
  205. data/test/plugin_helper/data/cert/with_ca/ca-cert-pass.pem +0 -20
  206. data/test/plugin_helper/data/cert/with_ca/ca-cert.pem +0 -20
  207. data/test/plugin_helper/data/cert/with_ca/cert-key-pass.pem +0 -30
  208. data/test/plugin_helper/data/cert/with_ca/cert-key.pem +0 -27
  209. data/test/plugin_helper/data/cert/with_ca/cert-pass.pem +0 -21
  210. data/test/plugin_helper/data/cert/with_ca/cert.pem +0 -21
  211. data/test/plugin_helper/data/cert/without_ca/cert-key-pass.pem +0 -30
  212. data/test/plugin_helper/data/cert/without_ca/cert-key.pem +0 -27
  213. data/test/plugin_helper/data/cert/without_ca/cert-pass.pem +0 -20
  214. data/test/plugin_helper/data/cert/without_ca/cert.pem +0 -20
  215. data/test/plugin_helper/http_server/test_app.rb +0 -65
  216. data/test/plugin_helper/http_server/test_route.rb +0 -32
  217. data/test/plugin_helper/service_discovery/test_manager.rb +0 -93
  218. data/test/plugin_helper/service_discovery/test_round_robin_balancer.rb +0 -21
  219. data/test/plugin_helper/test_cert_option.rb +0 -25
  220. data/test/plugin_helper/test_child_process.rb +0 -862
  221. data/test/plugin_helper/test_compat_parameters.rb +0 -358
  222. data/test/plugin_helper/test_event_emitter.rb +0 -80
  223. data/test/plugin_helper/test_event_loop.rb +0 -52
  224. data/test/plugin_helper/test_extract.rb +0 -194
  225. data/test/plugin_helper/test_formatter.rb +0 -255
  226. data/test/plugin_helper/test_http_server_helper.rb +0 -372
  227. data/test/plugin_helper/test_inject.rb +0 -561
  228. data/test/plugin_helper/test_metrics.rb +0 -137
  229. data/test/plugin_helper/test_parser.rb +0 -264
  230. data/test/plugin_helper/test_record_accessor.rb +0 -238
  231. data/test/plugin_helper/test_retry_state.rb +0 -1006
  232. data/test/plugin_helper/test_server.rb +0 -1895
  233. data/test/plugin_helper/test_service_discovery.rb +0 -165
  234. data/test/plugin_helper/test_socket.rb +0 -146
  235. data/test/plugin_helper/test_storage.rb +0 -542
  236. data/test/plugin_helper/test_thread.rb +0 -164
  237. data/test/plugin_helper/test_timer.rb +0 -130
  238. data/test/scripts/exec_script.rb +0 -32
  239. data/test/scripts/fluent/plugin/formatter1/formatter_test1.rb +0 -7
  240. data/test/scripts/fluent/plugin/formatter2/formatter_test2.rb +0 -7
  241. data/test/scripts/fluent/plugin/formatter_known.rb +0 -8
  242. data/test/scripts/fluent/plugin/out_test.rb +0 -81
  243. data/test/scripts/fluent/plugin/out_test2.rb +0 -80
  244. data/test/scripts/fluent/plugin/parser_known.rb +0 -4
  245. data/test/test_capability.rb +0 -74
  246. data/test/test_clock.rb +0 -164
  247. data/test/test_config.rb +0 -369
  248. data/test/test_configdsl.rb +0 -148
  249. data/test/test_daemonizer.rb +0 -91
  250. data/test/test_engine.rb +0 -203
  251. data/test/test_event.rb +0 -531
  252. data/test/test_event_router.rb +0 -348
  253. data/test/test_event_time.rb +0 -199
  254. data/test/test_file_wrapper.rb +0 -53
  255. data/test/test_filter.rb +0 -121
  256. data/test/test_fluent_log_event_router.rb +0 -99
  257. data/test/test_formatter.rb +0 -369
  258. data/test/test_input.rb +0 -31
  259. data/test/test_log.rb +0 -1076
  260. data/test/test_match.rb +0 -148
  261. data/test/test_mixin.rb +0 -351
  262. data/test/test_msgpack_factory.rb +0 -50
  263. data/test/test_oj_options.rb +0 -55
  264. data/test/test_output.rb +0 -278
  265. data/test/test_plugin.rb +0 -251
  266. data/test/test_plugin_classes.rb +0 -370
  267. data/test/test_plugin_helper.rb +0 -81
  268. data/test/test_plugin_id.rb +0 -119
  269. data/test/test_process.rb +0 -14
  270. data/test/test_root_agent.rb +0 -951
  271. data/test/test_static_config_analysis.rb +0 -177
  272. data/test/test_supervisor.rb +0 -821
  273. data/test/test_test_drivers.rb +0 -136
  274. data/test/test_time_formatter.rb +0 -301
  275. data/test/test_time_parser.rb +0 -362
  276. data/test/test_tls.rb +0 -65
  277. data/test/test_unique_id.rb +0 -47
  278. data/test/test_variable_store.rb +0 -65
@@ -22,6 +22,7 @@ require 'fluent/label'
22
22
  require 'fluent/plugin'
23
23
  require 'fluent/system_config'
24
24
  require 'fluent/time'
25
+ require 'fluent/source_only_buffer_agent'
25
26
 
26
27
  module Fluent
27
28
  #
@@ -47,24 +48,57 @@ module Fluent
47
48
  class RootAgent < Agent
48
49
  ERROR_LABEL = "@ERROR".freeze # @ERROR is built-in error label
49
50
 
50
- def initialize(log:, system_config: SystemConfig.new)
51
+ class SourceOnlyMode
52
+ DISABLED = 0
53
+ NORMAL = 1
54
+ ONLY_ZERO_DOWNTIME_RESTART_READY = 2
55
+
56
+ def initialize(with_source_only, start_in_parallel)
57
+ if start_in_parallel
58
+ @mode = ONLY_ZERO_DOWNTIME_RESTART_READY
59
+ elsif with_source_only
60
+ @mode = NORMAL
61
+ else
62
+ @mode = DISABLED
63
+ end
64
+ end
65
+
66
+ def enabled?
67
+ @mode != DISABLED
68
+ end
69
+
70
+ def only_zero_downtime_restart_ready?
71
+ @mode == ONLY_ZERO_DOWNTIME_RESTART_READY
72
+ end
73
+
74
+ def disable!
75
+ @mode = DISABLED
76
+ end
77
+ end
78
+
79
+ def initialize(log:, system_config: SystemConfig.new, start_in_parallel: false)
51
80
  super(log: log)
52
81
 
53
82
  @labels = {}
54
83
  @inputs = []
55
84
  @suppress_emit_error_log_interval = 0
56
85
  @next_emit_error_log_time = nil
57
- @without_source = false
58
- @enable_input_metrics = false
86
+ @without_source = system_config.without_source || false
87
+ @source_only_mode = SourceOnlyMode.new(system_config.with_source_only, start_in_parallel)
88
+ @source_only_buffer_agent = nil
89
+ @enable_input_metrics = system_config.enable_input_metrics || false
59
90
 
60
91
  suppress_interval(system_config.emit_error_log_interval) unless system_config.emit_error_log_interval.nil?
61
- @without_source = system_config.without_source unless system_config.without_source.nil?
62
- @enable_input_metrics = !!system_config.enable_input_metrics
63
92
  end
64
93
 
65
94
  attr_reader :inputs
66
95
  attr_reader :labels
67
96
 
97
+ def source_only_router
98
+ raise "[BUG] 'RootAgent#source_only_router' should not be called when 'with_source_only' is false" unless @source_only_mode.enabled?
99
+ @source_only_buffer_agent.event_router
100
+ end
101
+
68
102
  def configure(conf)
69
103
  used_worker_ids = []
70
104
  available_worker_ids = (0..Fluent::Engine.system_config.workers - 1).to_a
@@ -148,6 +182,8 @@ module Fluent
148
182
 
149
183
  super
150
184
 
185
+ setup_source_only_buffer_agent if @source_only_mode.enabled?
186
+
151
187
  # initialize <source> elements
152
188
  if @without_source
153
189
  log.info :worker0, "'--without-source' is applied. Ignore <source> sections"
@@ -169,16 +205,36 @@ module Fluent
169
205
  @error_collector = error_label.event_router
170
206
  end
171
207
 
172
- def lifecycle(desc: false, kind_callback: nil)
173
- kind_or_label_list = if desc
174
- [:output, :filter, @labels.values.reverse, :output_with_router, :input].flatten
175
- else
176
- [:input, :output_with_router, @labels.values, :filter, :output].flatten
177
- end
178
- kind_or_label_list.each do |kind|
208
+ def setup_source_only_buffer_agent(flush: false)
209
+ @source_only_buffer_agent = SourceOnlyBufferAgent.new(log: log, system_config: Fluent::Engine.system_config)
210
+ @source_only_buffer_agent.configure(flush: flush)
211
+ end
212
+
213
+ def cleanup_source_only_buffer_agent
214
+ @source_only_buffer_agent&.cleanup
215
+ end
216
+
217
+ def lifecycle(desc: false, kind_callback: nil, kind_or_agent_list: nil)
218
+ only_zero_downtime_restart_ready = false
219
+
220
+ unless kind_or_agent_list
221
+ if @source_only_mode.enabled?
222
+ kind_or_agent_list = [:input, @source_only_buffer_agent]
223
+ only_zero_downtime_restart_ready = @source_only_mode.only_zero_downtime_restart_ready?
224
+ elsif @source_only_buffer_agent
225
+ # source_only_buffer_agent can re-reroute events, so the priority is equal to output_with_router.
226
+ kind_or_agent_list = [:input, :output_with_router, @source_only_buffer_agent, @labels.values, :filter, :output].flatten
227
+ else
228
+ kind_or_agent_list = [:input, :output_with_router, @labels.values, :filter, :output].flatten
229
+ end
230
+
231
+ kind_or_agent_list.reverse! if desc
232
+ end
233
+
234
+ kind_or_agent_list.each do |kind|
179
235
  if kind.respond_to?(:lifecycle)
180
- label = kind
181
- label.lifecycle(desc: desc) do |plugin, display_kind|
236
+ agent = kind
237
+ agent.lifecycle(desc: desc) do |plugin, display_kind|
182
238
  yield plugin, display_kind
183
239
  end
184
240
  else
@@ -189,6 +245,9 @@ module Fluent
189
245
  end
190
246
  display_kind = (kind == :output_with_router ? :output : kind)
191
247
  list.each do |instance|
248
+ if only_zero_downtime_restart_ready
249
+ next unless instance.respond_to?(:zero_downtime_restart_ready?) and instance.zero_downtime_restart_ready?
250
+ end
192
251
  yield instance, display_kind
193
252
  end
194
253
  end
@@ -198,8 +257,8 @@ module Fluent
198
257
  end
199
258
  end
200
259
 
201
- def start
202
- lifecycle(desc: true) do |i| # instance
260
+ def start(kind_or_agent_list: nil)
261
+ lifecycle(desc: true, kind_or_agent_list: kind_or_agent_list) do |i| # instance
203
262
  i.start unless i.started?
204
263
  # Input#start sometimes emits lots of events with in_tail/`read_from_head true` case
205
264
  # and it causes deadlock for small buffer/queue output. To avoid such problem,
@@ -231,13 +290,46 @@ module Fluent
231
290
  flushing_threads.each{|t| t.join }
232
291
  end
233
292
 
234
- def shutdown # Fluentd's shutdown sequence is stop, before_shutdown, shutdown, after_shutdown, close, terminate for plugins
293
+ def cancel_source_only!
294
+ unless @source_only_mode.enabled?
295
+ log.info "do nothing for canceling with-source-only because the current mode is not with-source-only."
296
+ return
297
+ end
298
+
299
+ log.info "cancel with-source-only mode and start the other plugins"
300
+ all_plugins = [:input, :output_with_router, @labels.values, :filter, :output].flatten.reverse
301
+ start(kind_or_agent_list: all_plugins)
302
+
303
+ lifecycle_control_list[:input].each(&:event_emitter_cancel_source_only)
304
+
305
+ # Want to make sure that the source_only_router finishes all process before
306
+ # shutting down the agent.
307
+ # Strictly speaking, it would be necessary to have exclusive lock between
308
+ # EventRouter and the shutting down process of this agent.
309
+ # However, adding lock to EventRouter would worsen its performance, and
310
+ # the entire shutting down process does not care about it either.
311
+ # So, sleep here just in case.
312
+ sleep 1
313
+
314
+ shutdown(kind_or_agent_list: [@source_only_buffer_agent])
315
+ @source_only_buffer_agent = nil
316
+
317
+ # This agent can stop after flushing its all buffer, but it is not implemented for now.
318
+ log.info "starts the loading agent for with-source-only"
319
+ setup_source_only_buffer_agent(flush: true)
320
+ start(kind_or_agent_list: [@source_only_buffer_agent])
321
+
322
+ @source_only_mode.disable!
323
+ end
324
+
325
+ def shutdown(kind_or_agent_list: nil)
326
+ # Fluentd's shutdown sequence is stop, before_shutdown, shutdown, after_shutdown, close, terminate for plugins
235
327
  # These method callers does `rescue Exception` to call methods of shutdown sequence as far as possible
236
328
  # if plugin methods does something like infinite recursive call, `exit`, unregistering signal handlers or others.
237
329
  # Plugins should be separated and be in sandbox to protect data in each plugins/buffers.
238
330
 
239
331
  lifecycle_safe_sequence = ->(method, checker) {
240
- lifecycle do |instance, kind|
332
+ lifecycle(kind_or_agent_list: kind_or_agent_list) do |instance, kind|
241
333
  begin
242
334
  log.debug "calling #{method} on #{kind} plugin", type: Plugin.lookup_type_from_class(instance.class), plugin_id: instance.plugin_id
243
335
  instance.__send__(method) unless instance.__send__(checker)
@@ -260,7 +352,7 @@ module Fluent
260
352
  operation_threads.each{|t| t.join }
261
353
  operation_threads.clear
262
354
  }
263
- lifecycle(kind_callback: callback) do |instance, kind|
355
+ lifecycle(kind_callback: callback, kind_or_agent_list: kind_or_agent_list) do |instance, kind|
264
356
  t = Thread.new do
265
357
  Thread.current.abort_on_exception = true
266
358
  begin
@@ -301,6 +393,8 @@ module Fluent
301
393
  lifecycle_unsafe_sequence.call(:close, :closed?)
302
394
 
303
395
  lifecycle_safe_sequence.call(:terminate, :terminated?)
396
+
397
+ cleanup_source_only_buffer_agent unless kind_or_agent_list
304
398
  end
305
399
 
306
400
  def suppress_interval(interval_time)
@@ -318,6 +412,7 @@ module Fluent
318
412
  # See also 'fluentd/plugin/input.rb'
319
413
  input.context_router = @event_router
320
414
  input.configure(conf)
415
+ input.event_emitter_apply_source_only if @source_only_mode.enabled?
321
416
  if @enable_input_metrics
322
417
  @event_router.add_metric_callbacks(input.plugin_id, Proc.new {|es| input.metric_callback(es) })
323
418
  end
@@ -0,0 +1,102 @@
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 'fluent/agent'
18
+ require 'fluent/system_config'
19
+
20
+ module Fluent
21
+ class SourceOnlyBufferAgent < Agent
22
+ # Use INSTANCE_ID to use the same base dir as the other workers.
23
+ # This will make recovery easier.
24
+ BUFFER_DIR_NAME = Fluent::INSTANCE_ID
25
+
26
+ def initialize(log:, system_config:)
27
+ super(log: log)
28
+
29
+ @default_buffer_path = File.join(system_config.root_dir || DEFAULT_BACKUP_DIR, 'source-only-buffer', BUFFER_DIR_NAME)
30
+ @optional_buffer_config = system_config.source_only_buffer.to_h.transform_keys(&:to_s)
31
+ @base_buffer_dir = nil
32
+ @actual_buffer_dir = nil
33
+ end
34
+
35
+ def configure(flush: false)
36
+ buffer_config = @optional_buffer_config.compact
37
+ buffer_config['flush_at_shutdown'] = flush ? 'true' : 'false'
38
+ buffer_config['flush_thread_count'] = 0 unless flush
39
+ buffer_config['path'] ||= @default_buffer_path
40
+
41
+ super(
42
+ Config::Element.new('SOURCE_ONLY_BUFFER', '', {}, [
43
+ Config::Element.new('match', '**', {'@type' => 'buffer', '@label' => '@ROOT'}, [
44
+ Config::Element.new('buffer', '', buffer_config, [])
45
+ ])
46
+ ])
47
+ )
48
+
49
+ @base_buffer_dir = buffer_config['path']
50
+ # It can be "#{@base_buffer_dir}/worker#{fluentd_worker_id}/" when using multiple workers
51
+ @actual_buffer_dir = File.dirname(outputs[0].buffer.path)
52
+
53
+ unless flush
54
+ log.info "with-source-only: the emitted data will be stored in the buffer files under" +
55
+ " #{@base_buffer_dir}. You can send SIGWINCH to the supervisor process to cancel" +
56
+ " with-source-only mode and process data."
57
+ end
58
+ end
59
+
60
+ def cleanup
61
+ unless (Dir.empty?(@actual_buffer_dir) rescue true)
62
+ log.warn "some buffer files remain in #{@base_buffer_dir}." +
63
+ " Please consider recovering or saving the buffer files in the directory." +
64
+ " To recover them, you can set the buffer path manually to system config and" +
65
+ " retry, i.e., restart Fluentd with with-source-only mode and send SIGWINCH again." +
66
+ " Config Example:\n#{config_example_to_recover(@base_buffer_dir)}"
67
+ return
68
+ end
69
+
70
+ begin
71
+ FileUtils.remove_dir(@base_buffer_dir)
72
+ rescue Errno::ENOENT
73
+ # This worker doesn't need to do anything. Another worker may remove the dir first.
74
+ rescue => e
75
+ log.warn "failed to remove the buffer directory: #{@base_buffer_dir}", error: e
76
+ end
77
+ end
78
+
79
+ def emit_error_event(tag, time, record, error)
80
+ error_info = {error: error, location: (error.backtrace ? error.backtrace.first : nil), tag: tag, time: time, record: record}
81
+ log.warn "SourceOnlyBufferAgent: dump an error event:", error_info
82
+ end
83
+
84
+ def handle_emits_error(tag, es, error)
85
+ error_info = {error: error, location: (error.backtrace ? error.backtrace.first : nil), tag: tag}
86
+ log.warn "SourceOnlyBufferAgent: emit transaction failed:", error_info
87
+ log.warn_backtrace
88
+ end
89
+
90
+ private
91
+
92
+ def config_example_to_recover(path)
93
+ <<~EOC
94
+ <system>
95
+ <source_only_buffer>
96
+ path #{path}
97
+ </source_only_buffer>
98
+ </system>
99
+ EOC
100
+ end
101
+ end
102
+ end