fluentd 0.14.2 → 0.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +77 -1131
  3. data/Rakefile +15 -0
  4. data/appveyor.yml +2 -2
  5. data/example/in_forward.conf +3 -0
  6. data/example/in_forward_client.conf +37 -0
  7. data/example/in_forward_shared_key.conf +15 -0
  8. data/example/in_forward_users.conf +24 -0
  9. data/example/multi_filters.conf +61 -0
  10. data/example/out_forward.conf +13 -13
  11. data/example/out_forward_client.conf +109 -0
  12. data/example/out_forward_shared_key.conf +36 -0
  13. data/example/out_forward_users.conf +65 -0
  14. data/example/{out_buffered_null.conf → out_null.conf} +10 -6
  15. data/example/secondary_file.conf +41 -0
  16. data/fluentd.gemspec +19 -16
  17. data/lib/fluent/agent.rb +5 -0
  18. data/lib/fluent/command/debug.rb +4 -4
  19. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +2 -0
  20. data/lib/fluent/compat/output.rb +5 -2
  21. data/lib/fluent/config/configure_proxy.rb +26 -5
  22. data/lib/fluent/config/error.rb +3 -0
  23. data/lib/fluent/config/section.rb +15 -0
  24. data/lib/fluent/event_router.rb +77 -4
  25. data/lib/fluent/plugin/base.rb +12 -3
  26. data/lib/fluent/plugin/buffer.rb +5 -1
  27. data/lib/fluent/plugin/filter.rb +48 -6
  28. data/lib/fluent/plugin/filter_record_transformer.rb +3 -1
  29. data/lib/fluent/plugin/filter_stdout.rb +0 -4
  30. data/lib/fluent/plugin/in_debug_agent.rb +5 -5
  31. data/lib/fluent/plugin/in_dummy.rb +9 -1
  32. data/lib/fluent/plugin/in_forward.rb +330 -62
  33. data/lib/fluent/plugin/in_monitor_agent.rb +31 -77
  34. data/lib/fluent/plugin/in_tail.rb +76 -92
  35. data/lib/fluent/plugin/multi_output.rb +4 -0
  36. data/lib/fluent/plugin/out_forward.rb +328 -222
  37. data/lib/fluent/plugin/out_null.rb +37 -0
  38. data/lib/fluent/plugin/out_secondary_file.rb +128 -0
  39. data/lib/fluent/plugin/out_stdout.rb +38 -2
  40. data/lib/fluent/plugin/output.rb +29 -6
  41. data/lib/fluent/plugin/storage_local.rb +16 -0
  42. data/lib/fluent/plugin_helper/timer.rb +6 -1
  43. data/lib/fluent/root_agent.rb +4 -1
  44. data/lib/fluent/supervisor.rb +62 -9
  45. data/lib/fluent/test/base.rb +3 -0
  46. data/lib/fluent/test/driver/base.rb +5 -0
  47. data/lib/fluent/test/formatter_test.rb +2 -0
  48. data/lib/fluent/test/parser_test.rb +2 -0
  49. data/lib/fluent/test/startup_shutdown.rb +33 -0
  50. data/lib/fluent/version.rb +1 -1
  51. data/lib/fluent/winsvc.rb +1 -2
  52. data/test/compat/test_calls_super.rb +2 -0
  53. data/test/config/test_configurable.rb +88 -0
  54. data/test/config/test_types.rb +7 -3
  55. data/test/plugin/test_filter.rb +121 -23
  56. data/test/plugin/test_filter_record_transformer.rb +22 -6
  57. data/test/plugin/test_in_debug_agent.rb +2 -2
  58. data/test/plugin/test_in_forward.rb +920 -407
  59. data/test/plugin/test_in_monitor_agent.rb +333 -0
  60. data/test/plugin/test_in_tail.rb +686 -595
  61. data/test/plugin/test_out_forward.rb +150 -207
  62. data/test/plugin/test_out_null.rb +85 -9
  63. data/test/plugin/test_out_secondary_file.rb +432 -0
  64. data/test/plugin/test_out_stdout.rb +143 -45
  65. data/test/plugin/test_output.rb +53 -0
  66. data/test/plugin/test_output_as_buffered.rb +13 -0
  67. data/test/plugin/test_output_as_buffered_overflow.rb +3 -0
  68. data/test/plugin/test_output_as_buffered_retries.rb +11 -0
  69. data/test/plugin/test_output_as_buffered_secondary.rb +12 -0
  70. data/test/plugin/test_output_as_standard.rb +12 -0
  71. data/test/plugin_helper/test_compat_parameters.rb +2 -0
  72. data/test/plugin_helper/test_timer.rb +31 -0
  73. data/test/test_event_router.rb +87 -0
  74. data/test/test_filter.rb +48 -6
  75. data/test/test_log.rb +5 -2
  76. data/test/test_output.rb +41 -1
  77. data/test/test_plugin_classes.rb +17 -9
  78. data/test/test_root_agent.rb +188 -0
  79. metadata +62 -68
  80. data/lib/fluent/plugin/out_buffered_null.rb +0 -59
  81. data/lib/fluent/plugin/out_buffered_stdout.rb +0 -70
  82. data/test/plugin/test_out_buffered_null.rb +0 -79
  83. data/test/plugin/test_out_buffered_stdout.rb +0 -122
@@ -0,0 +1,333 @@
1
+ require_relative '../helper'
2
+ require 'fluent/test/driver/input'
3
+ require 'fluent/plugin/in_monitor_agent'
4
+ require 'fluent/engine'
5
+ require 'fluent/config'
6
+ require 'fluent/event_router'
7
+ require 'fluent/supervisor'
8
+ require 'net/http'
9
+ require 'json'
10
+ require_relative '../test_plugin_classes'
11
+
12
+ class MonitorAgentInputTest < Test::Unit::TestCase
13
+ def setup
14
+ Fluent::Test.setup
15
+ end
16
+
17
+ def create_driver(conf = '')
18
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::MonitorAgentInput).configure(conf)
19
+ end
20
+
21
+ def configure_ra(ra, conf_str)
22
+ conf = Fluent::Config.parse(conf_str, "(test)", "(test_dir)", true)
23
+ ra.configure(conf)
24
+ ra
25
+ end
26
+
27
+ def test_configure
28
+ d = create_driver
29
+ assert_equal("0.0.0.0", d.instance.bind)
30
+ assert_equal(24220, d.instance.port)
31
+ assert_equal(nil, d.instance.tag)
32
+ assert_equal(60, d.instance.emit_interval)
33
+ end
34
+
35
+ sub_test_case "collect plugin information" do
36
+ setup do
37
+ # check @type and type in one configuration
38
+ conf = <<-EOC
39
+ <source>
40
+ @type test_in
41
+ @id test_in
42
+ </source>
43
+ <filter>
44
+ @type test_filter
45
+ @id test_filter
46
+ </filter>
47
+ <match **>
48
+ @type relabel
49
+ @id test_relabel
50
+ @label @test
51
+ </match>
52
+ <label @test>
53
+ <match **>
54
+ @type test_out
55
+ @id test_out
56
+ </match>
57
+ </label>
58
+ <label @ERROR>
59
+ <match>
60
+ @type null
61
+ @id null
62
+ </match>
63
+ </label>
64
+ EOC
65
+ @ra = Fluent::RootAgent.new(log: $log)
66
+ stub(Fluent::Engine).root_agent { @ra }
67
+ @ra = configure_ra(@ra, conf)
68
+ end
69
+
70
+ test "plugin_category" do
71
+ d = create_driver
72
+ test_label = @ra.labels['@test']
73
+ error_label = @ra.labels['@ERROR']
74
+ assert_equal("input", d.instance.plugin_category(@ra.inputs.first))
75
+ assert_equal("filter", d.instance.plugin_category(@ra.filters.first))
76
+ assert_equal("output", d.instance.plugin_category(test_label.outputs.first))
77
+ assert_equal("output", d.instance.plugin_category(error_label.outputs.first))
78
+ end
79
+
80
+ test "get_monitor_info" do
81
+ d = create_driver
82
+ test_label = @ra.labels['@test']
83
+ error_label = @ra.labels['@ERROR']
84
+ input_info = {
85
+ "config" => {
86
+ "@id" => "test_in",
87
+ "@type" => "test_in"
88
+ },
89
+ "output_plugin" => false,
90
+ "plugin_category"=> "input",
91
+ "plugin_id" => "test_in",
92
+ "retry_count" => nil,
93
+ "type" => "test_in"
94
+ }
95
+ filter_info = {
96
+ "config" => {
97
+ "@id" => "test_filter",
98
+ "@type" => "test_filter"
99
+ },
100
+ "output_plugin" => false,
101
+ "plugin_category" => "filter",
102
+ "plugin_id" => "test_filter",
103
+ "retry_count" => nil,
104
+ "type" => "test_filter"
105
+ }
106
+ output_info = {
107
+ "config" => {
108
+ "@id" => "test_out",
109
+ "@type" => "test_out"
110
+ },
111
+ "output_plugin" => true,
112
+ "plugin_category" => "output",
113
+ "plugin_id" => "test_out",
114
+ "retry_count" => 0,
115
+ "type" => "test_out"
116
+ }
117
+ error_label_info = {
118
+ "config" => {
119
+ "@id"=>"null",
120
+ "@type" => "null"
121
+ },
122
+ "buffer_queue_length" => 0,
123
+ "buffer_total_queued_size" => 0,
124
+ "output_plugin" => true,
125
+ "plugin_category" => "output",
126
+ "plugin_id" => "null",
127
+ "retry_count" => 0,
128
+ "type" => "null"
129
+ }
130
+ assert_equal(input_info, d.instance.get_monitor_info(@ra.inputs.first))
131
+ assert_equal(filter_info, d.instance.get_monitor_info(@ra.filters.first))
132
+ assert_equal(output_info, d.instance.get_monitor_info(test_label.outputs.first))
133
+ assert_equal(error_label_info, d.instance.get_monitor_info(error_label.outputs.first))
134
+ end
135
+
136
+ test "fluentd opts" do
137
+ d = create_driver
138
+ opts = Fluent::Supervisor.default_options
139
+ Fluent::Supervisor.new(opts)
140
+ expected_opts = {
141
+ "config_path" => "/etc/fluent/fluent.conf",
142
+ "pid_file" => nil,
143
+ "plugin_dirs" => ["/etc/fluent/plugin"],
144
+ "log_path" => nil
145
+ }
146
+ assert_equal(expected_opts, d.instance.fluentd_opts)
147
+ end
148
+
149
+ test "all_plugins" do
150
+ d = create_driver
151
+ plugins = []
152
+ d.instance.all_plugins.each {|plugin| plugins << plugin.class }
153
+ assert_equal([FluentTest::FluentTestInput,
154
+ Fluent::Plugin::RelabelOutput,
155
+ FluentTest::FluentTestFilter,
156
+ FluentTest::FluentTestOutput,
157
+ Fluent::Plugin::NullOutput], plugins)
158
+ end
159
+
160
+ test "emit" do
161
+ port = unused_port
162
+ d = create_driver("
163
+ @type monitor_agent
164
+ bind '127.0.0.1'
165
+ port #{port}
166
+ tag monitor
167
+ emit_interval 1
168
+ ")
169
+ d.instance.start
170
+ d.end_if do
171
+ d.events.size >= 5
172
+ end
173
+ d.run
174
+ expect_relabel_record = {
175
+ "plugin_id" => "test_relabel",
176
+ "plugin_category" => "output",
177
+ "type" => "relabel",
178
+ "output_plugin" => true,
179
+ "retry_count" => 0}
180
+ expect_test_out_record = {
181
+ "plugin_id" => "test_out",
182
+ "plugin_category" => "output",
183
+ "type" => "test_out",
184
+ "output_plugin" => true,
185
+ "retry_count" => 0
186
+ }
187
+ assert_equal(expect_relabel_record, d.events[1][2])
188
+ assert_equal(expect_test_out_record, d.events[3][2])
189
+ end
190
+ end
191
+
192
+ def get(uri, header = {})
193
+ url = URI.parse(uri)
194
+ req = Net::HTTP::Get.new(url.path, header)
195
+ unless header.has_key?('Content-Type')
196
+ header['Content-Type'] = 'application/octet-stream'
197
+ end
198
+ res = Net::HTTP.start(url.host, url.port) {|http|
199
+ http.request(req)
200
+ }
201
+ res.body
202
+ end
203
+
204
+ sub_test_case "servlets" do
205
+ setup do
206
+ @port = unused_port
207
+ # check @type and type in one configuration
208
+ conf = <<-EOC
209
+ <source>
210
+ @type test_in
211
+ @id test_in
212
+ </source>
213
+ <source>
214
+ @type monitor_agent
215
+ bind "127.0.0.1"
216
+ port #{@port}
217
+ tag monitor
218
+ @id monitor_agent
219
+ </source>
220
+ <filter>
221
+ @type test_filter
222
+ @id test_filter
223
+ </filter>
224
+ <match **>
225
+ @type relabel
226
+ @id test_relabel
227
+ @label @test
228
+ </match>
229
+ <label @test>
230
+ <match **>
231
+ @type test_out
232
+ @id test_out
233
+ </match>
234
+ </label>
235
+ <label @ERROR>
236
+ <match>
237
+ @type null
238
+ @id null
239
+ </match>
240
+ </label>
241
+ EOC
242
+ @ra = Fluent::RootAgent.new(log: $log)
243
+ stub(Fluent::Engine).root_agent { @ra }
244
+ @ra = configure_ra(@ra, conf)
245
+ end
246
+
247
+ test "/api/plugins" do
248
+ d = create_driver("
249
+ @type monitor_agent
250
+ bind '127.0.0.1'
251
+ port #{@port}
252
+ tag monitor
253
+ ")
254
+ d.instance.start
255
+ expected_test_in_response = "\
256
+ plugin_id:test_in\tplugin_category:input\ttype:test_in\toutput_plugin:false\tretry_count:"
257
+ expected_test_filter_response = "\
258
+ plugin_id:test_filter\tplugin_category:filter\ttype:test_filter\toutput_plugin:false\tretry_count:"
259
+
260
+ response = get("http://127.0.0.1:#{@port}/api/plugins")
261
+ test_in = response.split("\n")[0]
262
+ test_filter = response.split("\n")[3]
263
+ assert_equal(expected_test_in_response, test_in)
264
+ assert_equal(expected_test_filter_response, test_filter)
265
+ end
266
+
267
+ test "/api/plugins.json" do
268
+ d = create_driver("
269
+ @type monitor_agent
270
+ bind '127.0.0.1'
271
+ port #{@port}
272
+ tag monitor
273
+ ")
274
+ d.instance.start
275
+ expected_test_in_response =
276
+ {"config" => {
277
+ "@id" => "test_in",
278
+ "@type" => "test_in"
279
+ },
280
+ "output_plugin" => false,
281
+ "plugin_category" => "input",
282
+ "plugin_id" => "test_in",
283
+ "retry_count" => nil,
284
+ "type" => "test_in"}
285
+ expected_null_response =
286
+ {"config" => {
287
+ "@id" => "null",
288
+ "@type" => "null"
289
+ },
290
+ "buffer_queue_length" => 0,
291
+ "buffer_total_queued_size" => 0,
292
+ "output_plugin" => true,
293
+ "plugin_category" => "output",
294
+ "plugin_id" => "null",
295
+ "retry_count" => 0,
296
+ "type" => "null"}
297
+ response = JSON.parse(get("http://127.0.0.1:#{@port}/api/plugins.json"))
298
+ test_in_response = response["plugins"][0]
299
+ null_response = response["plugins"][5]
300
+ assert_equal(expected_test_in_response, test_in_response)
301
+ assert_equal(expected_null_response, null_response)
302
+ end
303
+
304
+ test "/api/config" do
305
+ d = create_driver("
306
+ @type monitor_agent
307
+ bind '127.0.0.1'
308
+ port #{@port}
309
+ tag monitor
310
+ ")
311
+ d.instance.start
312
+ expected_response_regex = /pid:\d+\tppid:\d+\tconfig_path:\/etc\/fluent\/fluent.conf\tpid_file:\tplugin_dirs:\[\"\/etc\/fluent\/plugin\"\]\tlog_path:/
313
+
314
+ assert_match(expected_response_regex,
315
+ get("http://127.0.0.1:#{@port}/api/config"))
316
+ end
317
+
318
+ test "/api/config.json" do
319
+ d = create_driver("
320
+ @type monitor_agent
321
+ bind '127.0.0.1'
322
+ port #{@port}
323
+ tag monitor
324
+ ")
325
+ d.instance.start
326
+ res = JSON.parse(get("http://127.0.0.1:#{@port}/api/config.json"))
327
+ assert_equal("/etc/fluent/fluent.conf", res["config_path"])
328
+ assert_nil(res["pid_file"])
329
+ assert_equal(["/etc/fluent/plugin"], res["plugin_dirs"])
330
+ assert_nil(res["log_path"])
331
+ end
332
+ end
333
+ end