fluentd 0.12.40 → 0.14.0

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 (252) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +33 -21
  5. data/CONTRIBUTING.md +1 -0
  6. data/ChangeLog +810 -237
  7. data/README.md +0 -25
  8. data/Rakefile +2 -1
  9. data/Vagrantfile +17 -0
  10. data/appveyor.yml +35 -0
  11. data/example/filter_stdout.conf +5 -5
  12. data/example/in_forward.conf +2 -2
  13. data/example/in_http.conf +2 -2
  14. data/example/in_out_forward.conf +17 -0
  15. data/example/in_syslog.conf +2 -2
  16. data/example/in_tail.conf +2 -2
  17. data/example/in_tcp.conf +2 -2
  18. data/example/in_udp.conf +2 -2
  19. data/example/out_copy.conf +4 -4
  20. data/example/out_file.conf +2 -2
  21. data/example/out_forward.conf +2 -2
  22. data/example/out_forward_buf_file.conf +23 -0
  23. data/example/v0_12_filter.conf +8 -8
  24. data/fluent.conf +29 -0
  25. data/fluentd.gemspec +18 -11
  26. data/lib/fluent/agent.rb +60 -58
  27. data/lib/fluent/command/cat.rb +1 -1
  28. data/lib/fluent/command/debug.rb +7 -5
  29. data/lib/fluent/command/fluentd.rb +97 -2
  30. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  31. data/lib/fluent/compat/filter.rb +50 -0
  32. data/lib/fluent/compat/formatter.rb +109 -0
  33. data/lib/fluent/compat/input.rb +50 -0
  34. data/lib/fluent/compat/output.rb +617 -0
  35. data/lib/fluent/compat/output_chain.rb +60 -0
  36. data/lib/fluent/compat/parser.rb +163 -0
  37. data/lib/fluent/compat/propagate_default.rb +62 -0
  38. data/lib/fluent/config.rb +23 -20
  39. data/lib/fluent/config/configure_proxy.rb +119 -70
  40. data/lib/fluent/config/dsl.rb +5 -18
  41. data/lib/fluent/config/element.rb +72 -8
  42. data/lib/fluent/config/error.rb +0 -3
  43. data/lib/fluent/config/literal_parser.rb +0 -2
  44. data/lib/fluent/config/parser.rb +4 -4
  45. data/lib/fluent/config/section.rb +39 -28
  46. data/lib/fluent/config/types.rb +2 -13
  47. data/lib/fluent/config/v1_parser.rb +1 -3
  48. data/lib/fluent/configurable.rb +48 -16
  49. data/lib/fluent/daemon.rb +15 -0
  50. data/lib/fluent/engine.rb +26 -52
  51. data/lib/fluent/env.rb +6 -4
  52. data/lib/fluent/event.rb +58 -11
  53. data/lib/fluent/event_router.rb +5 -5
  54. data/lib/fluent/filter.rb +2 -50
  55. data/lib/fluent/formatter.rb +4 -293
  56. data/lib/fluent/input.rb +2 -32
  57. data/lib/fluent/label.rb +2 -2
  58. data/lib/fluent/load.rb +3 -2
  59. data/lib/fluent/log.rb +107 -38
  60. data/lib/fluent/match.rb +0 -36
  61. data/lib/fluent/mixin.rb +117 -7
  62. data/lib/fluent/msgpack_factory.rb +62 -0
  63. data/lib/fluent/output.rb +7 -612
  64. data/lib/fluent/output_chain.rb +23 -0
  65. data/lib/fluent/parser.rb +4 -800
  66. data/lib/fluent/plugin.rb +100 -121
  67. data/lib/fluent/plugin/bare_output.rb +63 -0
  68. data/lib/fluent/plugin/base.rb +121 -0
  69. data/lib/fluent/plugin/buf_file.rb +101 -182
  70. data/lib/fluent/plugin/buf_memory.rb +9 -92
  71. data/lib/fluent/plugin/buffer.rb +473 -0
  72. data/lib/fluent/plugin/buffer/chunk.rb +135 -0
  73. data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
  74. data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
  75. data/lib/fluent/plugin/exec_util.rb +80 -75
  76. data/lib/fluent/plugin/file_util.rb +33 -28
  77. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  78. data/lib/fluent/plugin/filter.rb +51 -0
  79. data/lib/fluent/plugin/filter_grep.rb +13 -40
  80. data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
  81. data/lib/fluent/plugin/formatter.rb +93 -0
  82. data/lib/fluent/plugin/formatter_csv.rb +48 -0
  83. data/lib/fluent/plugin/formatter_hash.rb +32 -0
  84. data/lib/fluent/plugin/formatter_json.rb +47 -0
  85. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  86. data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
  87. data/lib/fluent/plugin/formatter_out_file.rb +45 -0
  88. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  89. data/lib/fluent/plugin/formatter_stdout.rb +39 -0
  90. data/lib/fluent/plugin/in_debug_agent.rb +4 -0
  91. data/lib/fluent/plugin/in_dummy.rb +22 -18
  92. data/lib/fluent/plugin/in_exec.rb +18 -8
  93. data/lib/fluent/plugin/in_forward.rb +36 -79
  94. data/lib/fluent/plugin/in_gc_stat.rb +4 -0
  95. data/lib/fluent/plugin/in_http.rb +21 -18
  96. data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
  97. data/lib/fluent/plugin/in_object_space.rb +6 -1
  98. data/lib/fluent/plugin/in_stream.rb +7 -3
  99. data/lib/fluent/plugin/in_syslog.rb +46 -95
  100. data/lib/fluent/plugin/in_tail.rb +51 -595
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -14
  103. data/lib/fluent/plugin/input.rb +33 -0
  104. data/lib/fluent/plugin/multi_output.rb +95 -0
  105. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  106. data/lib/fluent/plugin/out_copy.rb +11 -7
  107. data/lib/fluent/plugin/out_exec.rb +15 -11
  108. data/lib/fluent/plugin/out_exec_filter.rb +18 -10
  109. data/lib/fluent/plugin/out_file.rb +34 -5
  110. data/lib/fluent/plugin/out_forward.rb +19 -9
  111. data/lib/fluent/plugin/out_null.rb +0 -14
  112. data/lib/fluent/plugin/out_roundrobin.rb +11 -7
  113. data/lib/fluent/plugin/out_stdout.rb +5 -7
  114. data/lib/fluent/plugin/out_stream.rb +3 -1
  115. data/lib/fluent/plugin/output.rb +979 -0
  116. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  117. data/lib/fluent/plugin/parser.rb +244 -0
  118. data/lib/fluent/plugin/parser_apache.rb +24 -0
  119. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  120. data/lib/fluent/plugin/parser_apache_error.rb +21 -0
  121. data/lib/fluent/plugin/parser_csv.rb +31 -0
  122. data/lib/fluent/plugin/parser_json.rb +79 -0
  123. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  124. data/lib/fluent/plugin/parser_multiline.rb +102 -0
  125. data/lib/fluent/plugin/parser_nginx.rb +24 -0
  126. data/lib/fluent/plugin/parser_none.rb +36 -0
  127. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  128. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  129. data/lib/fluent/plugin/socket_util.rb +120 -114
  130. data/lib/fluent/plugin/storage.rb +84 -0
  131. data/lib/fluent/plugin/storage_local.rb +116 -0
  132. data/lib/fluent/plugin/string_util.rb +16 -13
  133. data/lib/fluent/plugin_helper.rb +39 -0
  134. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  135. data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
  136. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  137. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  138. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  139. data/lib/fluent/plugin_helper/storage.rb +308 -0
  140. data/lib/fluent/plugin_helper/thread.rb +147 -0
  141. data/lib/fluent/plugin_helper/timer.rb +85 -0
  142. data/lib/fluent/plugin_id.rb +63 -0
  143. data/lib/fluent/process.rb +21 -30
  144. data/lib/fluent/registry.rb +21 -9
  145. data/lib/fluent/root_agent.rb +115 -40
  146. data/lib/fluent/supervisor.rb +330 -320
  147. data/lib/fluent/system_config.rb +42 -18
  148. data/lib/fluent/test.rb +6 -1
  149. data/lib/fluent/test/base.rb +23 -3
  150. data/lib/fluent/test/driver/base.rb +247 -0
  151. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  152. data/lib/fluent/test/driver/filter.rb +35 -0
  153. data/lib/fluent/test/driver/input.rb +31 -0
  154. data/lib/fluent/test/driver/output.rb +78 -0
  155. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  156. data/lib/fluent/test/filter_test.rb +0 -1
  157. data/lib/fluent/test/formatter_test.rb +2 -1
  158. data/lib/fluent/test/input_test.rb +23 -17
  159. data/lib/fluent/test/output_test.rb +28 -39
  160. data/lib/fluent/test/parser_test.rb +1 -1
  161. data/lib/fluent/time.rb +104 -1
  162. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  163. data/lib/fluent/version.rb +1 -1
  164. data/lib/fluent/winsvc.rb +72 -0
  165. data/test/compat/test_calls_super.rb +164 -0
  166. data/test/config/test_config_parser.rb +83 -0
  167. data/test/config/test_configurable.rb +547 -274
  168. data/test/config/test_configure_proxy.rb +146 -29
  169. data/test/config/test_dsl.rb +3 -181
  170. data/test/config/test_element.rb +274 -0
  171. data/test/config/test_literal_parser.rb +1 -1
  172. data/test/config/test_section.rb +79 -7
  173. data/test/config/test_system_config.rb +21 -0
  174. data/test/config/test_types.rb +3 -26
  175. data/test/helper.rb +78 -8
  176. data/test/plugin/test_bare_output.rb +118 -0
  177. data/test/plugin/test_base.rb +75 -0
  178. data/test/plugin/test_buf_file.rb +420 -521
  179. data/test/plugin/test_buf_memory.rb +32 -194
  180. data/test/plugin/test_buffer.rb +981 -0
  181. data/test/plugin/test_buffer_chunk.rb +110 -0
  182. data/test/plugin/test_buffer_file_chunk.rb +770 -0
  183. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  184. data/test/plugin/test_filter.rb +255 -0
  185. data/test/plugin/test_filter_grep.rb +2 -73
  186. data/test/plugin/test_filter_record_transformer.rb +24 -68
  187. data/test/plugin/test_filter_stdout.rb +6 -6
  188. data/test/plugin/test_in_debug_agent.rb +2 -0
  189. data/test/plugin/test_in_dummy.rb +11 -17
  190. data/test/plugin/test_in_exec.rb +6 -25
  191. data/test/plugin/test_in_forward.rb +112 -151
  192. data/test/plugin/test_in_gc_stat.rb +2 -0
  193. data/test/plugin/test_in_http.rb +106 -157
  194. data/test/plugin/test_in_object_space.rb +21 -5
  195. data/test/plugin/test_in_stream.rb +14 -13
  196. data/test/plugin/test_in_syslog.rb +30 -275
  197. data/test/plugin/test_in_tail.rb +95 -234
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -13
  200. data/test/plugin/test_input.rb +122 -0
  201. data/test/plugin/test_multi_output.rb +180 -0
  202. data/test/plugin/test_out_buffered_null.rb +79 -0
  203. data/test/plugin/test_out_copy.rb +15 -2
  204. data/test/plugin/test_out_exec.rb +75 -25
  205. data/test/plugin/test_out_exec_filter.rb +74 -8
  206. data/test/plugin/test_out_file.rb +61 -7
  207. data/test/plugin/test_out_forward.rb +92 -15
  208. data/test/plugin/test_out_roundrobin.rb +1 -0
  209. data/test/plugin/test_out_stdout.rb +22 -13
  210. data/test/plugin/test_out_stream.rb +18 -0
  211. data/test/plugin/test_output.rb +515 -0
  212. data/test/plugin/test_output_as_buffered.rb +1540 -0
  213. data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
  214. data/test/plugin/test_output_as_buffered_retries.rb +808 -0
  215. data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
  216. data/test/plugin/test_output_as_standard.rb +362 -0
  217. data/test/plugin/test_owned_by.rb +35 -0
  218. data/test/plugin/test_storage.rb +167 -0
  219. data/test/plugin/test_storage_local.rb +8 -0
  220. data/test/plugin_helper/test_child_process.rb +599 -0
  221. data/test/plugin_helper/test_compat_parameters.rb +175 -0
  222. data/test/plugin_helper/test_event_emitter.rb +51 -0
  223. data/test/plugin_helper/test_event_loop.rb +52 -0
  224. data/test/plugin_helper/test_retry_state.rb +399 -0
  225. data/test/plugin_helper/test_storage.rb +411 -0
  226. data/test/plugin_helper/test_thread.rb +164 -0
  227. data/test/plugin_helper/test_timer.rb +100 -0
  228. data/test/scripts/exec_script.rb +0 -6
  229. data/test/scripts/fluent/plugin/out_test.rb +3 -0
  230. data/test/test_config.rb +13 -4
  231. data/test/test_event.rb +24 -13
  232. data/test/test_event_router.rb +8 -7
  233. data/test/test_event_time.rb +187 -0
  234. data/test/test_formatter.rb +13 -51
  235. data/test/test_input.rb +1 -1
  236. data/test/test_log.rb +239 -16
  237. data/test/test_mixin.rb +1 -1
  238. data/test/test_output.rb +53 -66
  239. data/test/test_parser.rb +105 -323
  240. data/test/test_plugin_helper.rb +81 -0
  241. data/test/test_root_agent.rb +4 -52
  242. data/test/test_supervisor.rb +272 -0
  243. data/test/test_unique_id.rb +47 -0
  244. metadata +180 -54
  245. data/lib/fluent/buffer.rb +0 -365
  246. data/lib/fluent/plugin/filter_parser.rb +0 -107
  247. data/lib/fluent/plugin/in_status.rb +0 -76
  248. data/lib/fluent/test/helpers.rb +0 -86
  249. data/test/plugin/data/log/foo/bar2 +0 -0
  250. data/test/plugin/test_filter_parser.rb +0 -744
  251. data/test/plugin/test_in_status.rb +0 -38
  252. data/test/test_buffer.rb +0 -624
@@ -22,51 +22,12 @@ class GrepFilterTest < Test::Unit::TestCase
22
22
 
23
23
  test "regexpN can contain a space" do
24
24
  d = create_driver(%[regexp1 message foo])
25
- assert_equal(Regexp.compile(/ foo/), d.instance._regexps['message'])
25
+ assert_equal(Regexp.compile(/ foo/), d.instance.regexps['message'])
26
26
  end
27
27
 
28
28
  test "excludeN can contain a space" do
29
29
  d = create_driver(%[exclude1 message foo])
30
- assert_equal(Regexp.compile(/ foo/), d.instance._excludes['message'])
31
- end
32
-
33
- sub_test_case "duplicate key" do
34
- test "flat" do
35
- conf = %[
36
- regexp1 message test
37
- regexp2 message test2
38
- ]
39
- assert_raise(Fluent::ConfigError) do
40
- create_driver(conf)
41
- end
42
- end
43
- test "section" do
44
- conf = %[
45
- <regexp>
46
- key message
47
- pattern test
48
- </regexp>
49
- <regexp>
50
- key message
51
- pattern test2
52
- </regexp>
53
- ]
54
- assert_raise(Fluent::ConfigError) do
55
- create_driver(conf)
56
- end
57
- end
58
- test "mix" do
59
- conf = %[
60
- regexp1 message test
61
- <regexp>
62
- key message
63
- pattern test
64
- </regexp>
65
- ]
66
- assert_raise(Fluent::ConfigError) do
67
- create_driver(conf)
68
- end
69
- end
30
+ assert_equal(Regexp.compile(/ foo/), d.instance.excludes['message'])
70
31
  end
71
32
  end
72
33
 
@@ -114,38 +75,6 @@ class GrepFilterTest < Test::Unit::TestCase
114
75
  end
115
76
  end
116
77
 
117
- test 'regexps' do
118
- conf = %[
119
- <regexp>
120
- key message
121
- pattern WARN
122
- </regexp>
123
- ]
124
- es = emit(conf, messages)
125
- assert_equal(3, es.instance_variable_get(:@record_array).size)
126
- assert_block('only WARN logs') do
127
- es.all? { |t, r|
128
- !r['message'].include?('INFO')
129
- }
130
- end
131
- end
132
-
133
- test 'excludes' do
134
- conf = %[
135
- <exclude>
136
- key message
137
- pattern favicon
138
- </exclude>
139
- ]
140
- es = emit(conf, messages)
141
- assert_equal(3, es.instance_variable_get(:@record_array).size)
142
- assert_block('remove favicon logs') do
143
- es.all? { |t, r|
144
- !r['message'].include?('favicon')
145
- }
146
- end
147
- end
148
-
149
78
  sub_test_case 'with invalid sequence' do
150
79
  def messages
151
80
  [
@@ -58,7 +58,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
58
58
  test 'typical usage' do
59
59
  msgs = ['1', '2']
60
60
  es = emit(CONFIG, msgs)
61
- es.each_with_index do |(t, r), i|
61
+ es.each_with_index do |(_t, r), i|
62
62
  assert_equal('bar', r['foo'])
63
63
  assert_equal(@hostname, r['hostname'])
64
64
  assert_equal(@tag, r['tag'])
@@ -70,7 +70,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
70
70
  test 'remove_keys' do
71
71
  config = CONFIG + %[remove_keys foo,message]
72
72
  es = emit(config)
73
- es.each_with_index do |(t, r), i|
73
+ es.each_with_index do |(_t, r), i|
74
74
  assert_not_include(r, 'foo')
75
75
  assert_equal(@hostname, r['hostname'])
76
76
  assert_equal(@tag, r['tag'])
@@ -83,7 +83,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
83
83
  config = CONFIG + %[renew_record true]
84
84
  msgs = ['1', '2']
85
85
  es = emit(config, msgs)
86
- es.each_with_index do |(t, r), i|
86
+ es.each_with_index do |(_t, r), i|
87
87
  assert_not_include(r, 'foo')
88
88
  assert_equal(@hostname, r['hostname'])
89
89
  assert_equal(@tag, r['tag'])
@@ -95,29 +95,11 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
95
95
  test 'renew_time_key' do
96
96
  config = %[renew_time_key message]
97
97
  times = [ Time.local(2,2,3,4,5,2010,nil,nil,nil,nil), Time.local(3,2,3,4,5,2010,nil,nil,nil,nil) ]
98
- msgs = times.map{|t| t.to_i.to_s }
98
+ msgs = times.map{|t| t.to_f.to_s }
99
99
  es = emit(config, msgs)
100
- es.each_with_index do |(time, record), i|
100
+ es.each_with_index do |(time, _record), i|
101
101
  assert_equal(times[i].to_i, time)
102
- assert_true(record.has_key?('message'))
103
- end
104
- end
105
-
106
- test 'renew_time_key and remove_keys' do
107
- config = %[
108
- renew_time_key event_time_key
109
- remove_keys event_time_key
110
- auto_typecast true
111
- <record>
112
- event_time_key ${record["message"]}
113
- </record>
114
- ]
115
- times = [Time.local(2, 2, 3, 4, 5, 2010, nil, nil, nil, nil), Time.local(3, 2, 3, 4, 5, 2010, nil, nil, nil, nil)]
116
- msgs = times.map { |t| t.to_f.to_s }
117
- filtered = emit(config, msgs)
118
- filtered.each_with_index do |(time, _record), i|
119
- assert_equal(times[i].to_i, time)
120
- assert_false(_record.has_key?('event_time_key'))
102
+ assert(time.is_a?(Fluent::EventTime))
121
103
  end
122
104
  end
123
105
 
@@ -125,21 +107,9 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
125
107
  config = %[renew_record true\nkeep_keys foo,message]
126
108
  msgs = ['1', '2']
127
109
  es = emit(config, msgs)
128
- es.each_with_index do |(t, r), i|
129
- assert_equal('bar', r['foo'])
130
- assert_equal(msgs[i], r['message'])
131
- end
132
- end
133
-
134
- test 'keep_keys that are not present in the original record should not be included in the result record' do
135
- config = %[renew_record true\nkeep_keys foo, bar, baz, message]
136
- msgs = ['1', '2', nil]
137
- es = emit(config, msgs)
138
- es.each_with_index do |(t, r), i|
110
+ es.each_with_index do |(_t, r), i|
139
111
  assert_equal('bar', r['foo'])
140
112
  assert_equal(msgs[i], r['message'])
141
- assert_equal(false, r.has_key?('bar'))
142
- assert_equal(false, r.has_key?('baz'))
143
113
  end
144
114
  end
145
115
 
@@ -147,13 +117,13 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
147
117
  config = %[
148
118
  enable_ruby yes
149
119
  <record>
150
- message ${hostname} ${tag_parts.last} ${URI.encode(message)}
120
+ message ${hostname} ${tag_parts.last} ${"'" + message + "'"}
151
121
  </record>
152
122
  ]
153
123
  msgs = ['1', '2']
154
124
  es = emit(config, msgs)
155
- es.each_with_index do |(t, r), i|
156
- assert_equal("#{@hostname} #{@tag_parts[-1]} #{msgs[i]}", r['message'])
125
+ es.each_with_index do |(_t, r), i|
126
+ assert_equal("#{@hostname} #{@tag_parts[-1]} '#{msgs[i]}'", r['message'])
157
127
  end
158
128
  end
159
129
 
@@ -165,7 +135,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
165
135
  %]
166
136
  msgs = ['1', '2']
167
137
  es = emit(config, msgs)
168
- es.each_with_index do |(t, r), i|
138
+ es.each_with_index do |(_t, r), i|
169
139
  assert_equal({"k1"=>100, "k2"=>"foobar"}, r['hash_field'])
170
140
  end
171
141
  end
@@ -178,7 +148,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
178
148
  %]
179
149
  msgs = ['1', '2']
180
150
  es = emit(config, msgs)
181
- es.each_with_index do |(t, r), i|
151
+ es.each_with_index do |(_t, r), i|
182
152
  assert_equal([1,2,3], r['array_field'])
183
153
  end
184
154
  end
@@ -191,7 +161,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
191
161
  %]
192
162
  msgs = ['1', '2']
193
163
  es = emit(config, msgs)
194
- es.each_with_index do |(t, r), i|
164
+ es.each_with_index do |(_t, r), i|
195
165
  assert_equal({"hello"=>[1,2,3], "world"=>{"foo"=>"bar"}}, r['mixed_field'])
196
166
  end
197
167
  end
@@ -203,7 +173,10 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
203
173
  yield d if block_given?
204
174
  d.run {
205
175
  msgs.each do |msg|
206
- record = {'eventType0' => 'bar', 'message' => msg}
176
+ record = {
177
+ 'eventType0' => 'bar',
178
+ 'message' => msg,
179
+ }
207
180
  record = record.merge(msg) if msg.is_a?(Hash)
208
181
  d.emit(record, @time)
209
182
  end
@@ -290,30 +263,13 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
290
263
  ]
291
264
  msgs = ['1', '2']
292
265
  es = emit(config, msgs)
293
- es.each_with_index do |(t, r), i|
266
+ es.each_with_index do |(_t, r), i|
294
267
  assert_not_include(r, 'eventType0')
295
268
  assert_equal("bar", r['eventtype'])
296
269
  assert_equal("bar #{msgs[i]}", r['message'])
297
270
  end
298
271
  end
299
272
 
300
- test "Prevent overwriting reserved keys such as tag with enable_ruby #{enable_ruby}" do
301
- config = %[
302
- enable_ruby #{enable_ruby}
303
- <record>
304
- new_tag ${tag}
305
- new_record_tag ${record["tag"]}
306
- </record>
307
- ]
308
- records = [{'tag' => 'tag', 'time' => 'time'}]
309
- filtered = emit(config, records)
310
- filtered.each_with_index do |(_t, r), i|
311
- assert_not_equal('tag', r['new_tag'])
312
- assert_equal(@tag, r['new_tag'])
313
- assert_equal('tag', r['new_record_tag'])
314
- end
315
- end
316
-
317
273
  test "hash values with placeholders with enable_ruby #{enable_ruby}" do
318
274
  config = %[
319
275
  enable_ruby #{enable_ruby}
@@ -327,7 +283,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
327
283
  ]
328
284
  msgs = ['1', '2']
329
285
  es = emit(config, msgs)
330
- es.each_with_index do |(t, r), i|
286
+ es.each_with_index do |(_t, r), i|
331
287
  assert_equal({"hostname" => @hostname, "tag" => @tag, "#{@tag}" => 100}, r['hash_field'])
332
288
  end
333
289
  end
@@ -341,7 +297,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
341
297
  ]
342
298
  msgs = ['1', '2']
343
299
  es = emit(config, msgs)
344
- es.each_with_index do |(t, r), i|
300
+ es.each_with_index do |(_t, r), i|
345
301
  assert_equal([@hostname, @tag], r['array_field'])
346
302
  end
347
303
  end
@@ -355,7 +311,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
355
311
  ]
356
312
  msgs = ['1', '2']
357
313
  es = emit(config, msgs)
358
- es.each_with_index do |(t, r), i|
314
+ es.each_with_index do |(_t, r), i|
359
315
  assert_equal([{"tag" => @tag}], r['mixed_field'])
360
316
  end
361
317
  end
@@ -371,7 +327,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
371
327
  ]
372
328
  msgs = ['1', '2']
373
329
  es = emit(config, msgs)
374
- es.each_with_index do |(t, r), i|
330
+ es.each_with_index do |(_t, r), i|
375
331
  assert_equal({@hostname=>'hostname',"foo.#{@tag}"=>'tag'}, r)
376
332
  end
377
333
  end
@@ -424,7 +380,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
424
380
  ]
425
381
  actual_results = []
426
382
  es = emit(config, msgs)
427
- es.each_with_index do |(t, r), i|
383
+ es.each_with_index do |(_t, r), i|
428
384
  actual_results << {
429
385
  single: r["single"],
430
386
  multiple: r["multiple"],
@@ -478,7 +434,7 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
478
434
  ]
479
435
  actual_results = []
480
436
  es = emit(config, msgs)
481
- es.each_with_index do |(t, r), i|
437
+ es.each_with_index do |(_t, r), i|
482
438
  actual_results << {
483
439
  single: r["single"],
484
440
  multiple: r["multiple"],
@@ -34,7 +34,7 @@ class StdoutFilterTest < Test::Unit::TestCase
34
34
  def test_through_record
35
35
  d = create_driver
36
36
  time = Time.now
37
- filtered = emit(d, {'test' => 'test'}, time)
37
+ filtered = emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time))
38
38
  assert_equal({'test' => 'test'}, filtered)
39
39
  end
40
40
 
@@ -61,7 +61,7 @@ class StdoutFilterTest < Test::Unit::TestCase
61
61
  def test_output_type_json
62
62
  d = create_driver(CONFIG + "\noutput_type json")
63
63
  time = Time.now
64
- out = capture_log(d) { emit(d, {'test' => 'test'}, time) }
64
+ out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time)) }
65
65
  assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out
66
66
 
67
67
  # NOTE: Float::NAN is not jsonable
@@ -73,12 +73,12 @@ class StdoutFilterTest < Test::Unit::TestCase
73
73
  def test_output_type_hash
74
74
  d = create_driver(CONFIG + "\noutput_type hash")
75
75
  time = Time.now
76
- out = capture_log(d) { emit(d, {'test' => 'test'}, time) }
76
+ out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time)) }
77
77
  assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out
78
78
 
79
79
  # NOTE: Float::NAN is not jsonable, but hash string can output it.
80
80
  d = create_driver(CONFIG + "\noutput_type hash")
81
- out = capture_log(d) { emit(d, {'test' => Float::NAN}, time) }
81
+ out = capture_log(d) { emit(d, {'test' => Float::NAN}, Fluent::EventTime.from_time(time)) }
82
82
  assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out
83
83
  end
84
84
 
@@ -86,7 +86,7 @@ class StdoutFilterTest < Test::Unit::TestCase
86
86
  def test_include_time_key
87
87
  d = create_driver(CONFIG + "\noutput_type json\ninclude_time_key true\nutc")
88
88
  time = Time.now
89
- message_time = Time.parse("2011-01-02 13:14:15 UTC").to_i
89
+ message_time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
90
90
  out = capture_log(d) { emit(d, {'test' => 'test'}, message_time) }
91
91
  assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out
92
92
  end
@@ -95,7 +95,7 @@ class StdoutFilterTest < Test::Unit::TestCase
95
95
  def test_format_json
96
96
  d = create_driver(CONFIG + "\nformat json")
97
97
  time = Time.now
98
- out = capture_log(d) { emit(d, {'test' => 'test'}, time) }
98
+ out = capture_log(d) { emit(d, {'test' => 'test'}, Fluent::EventTime.from_time(time)) }
99
99
  assert_equal "{\"test\":\"test\"}\n", out
100
100
  end
101
101
 
@@ -1,4 +1,6 @@
1
1
  require_relative '../helper'
2
+ require 'fluent/test'
3
+ require 'fluent/plugin/in_debug_agent'
2
4
  require 'fileutils'
3
5
 
4
6
  class DebugAgentInputTest < Test::Unit::TestCase
@@ -1,5 +1,6 @@
1
1
  require_relative '../helper'
2
- require 'fluent/test'
2
+ require 'fluent/test/driver/input'
3
+ require 'fluent/plugin/in_dummy'
3
4
 
4
5
  class DummyTest < Test::Unit::TestCase
5
6
  def setup
@@ -7,7 +8,7 @@ class DummyTest < Test::Unit::TestCase
7
8
  end
8
9
 
9
10
  def create_driver(conf)
10
- Fluent::Test::InputTestDriver.new(Fluent::DummyInput).configure(conf)
11
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::DummyInput).configure(conf)
11
12
  end
12
13
 
13
14
  sub_test_case 'configure' do
@@ -42,10 +43,6 @@ class DummyTest < Test::Unit::TestCase
42
43
  assert_equal 10, d.instance.rate
43
44
  end
44
45
 
45
- def json_error_messages_regexp
46
- /JSON::ParserError|got incomplete JSON|0th element of dummy, foo, is not a hash/
47
- end
48
-
49
46
  test 'dummy' do
50
47
  # hash is okay
51
48
  d = create_driver(config + %[dummy {"foo":"bar"}])
@@ -55,7 +52,7 @@ class DummyTest < Test::Unit::TestCase
55
52
  d = create_driver(config + %[dummy [{"foo":"bar"}]])
56
53
  assert_equal [{"foo"=>"bar"}], d.instance.dummy
57
54
 
58
- assert_raise_message(json_error_messages_regexp) do
55
+ assert_raise_message(/JSON::ParserError|got incomplete JSON/) do
59
56
  create_driver(config + %[dummy "foo"])
60
57
  end
61
58
 
@@ -74,23 +71,20 @@ class DummyTest < Test::Unit::TestCase
74
71
 
75
72
  test 'simple' do
76
73
  d = create_driver(config)
77
- d.run {
78
- # d.run sleeps 0.5 sec
79
- }
80
- emits = d.emits
81
- emits.each do |tag, time, record|
74
+ d.run(timeout: 0.5)
75
+
76
+ d.events.each do |tag, time, record|
82
77
  assert_equal("dummy", tag)
83
78
  assert_equal({"foo"=>"bar"}, record)
79
+ assert(time.is_a?(Fluent::EventTime))
84
80
  end
85
81
  end
86
82
 
87
83
  test 'with auto_increment_key' do
88
84
  d = create_driver(config + %[auto_increment_key id])
89
- d.run {
90
- # d.run sleeps 0.5 sec
91
- }
92
- emits = d.emits
93
- emits.each_with_index do |(tag, time, record), i|
85
+ d.run(timeout: 0.5)
86
+
87
+ d.events.each_with_index do |(tag, _time, record), i|
94
88
  assert_equal("dummy", tag)
95
89
  assert_equal({"foo"=>"bar", "id"=>i}, record)
96
90
  end
@@ -1,11 +1,12 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/test'
3
+ require 'fluent/plugin/in_exec'
3
4
  require 'net/http'
4
5
 
5
6
  class ExecInputTest < Test::Unit::TestCase
6
7
  def setup
7
8
  Fluent::Test.setup
8
- @test_time = Time.parse("2011-01-02 13:14:15").to_i
9
+ @test_time = Fluent::EventTime.parse("2011-01-02 13:14:15")
9
10
  @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb'))
10
11
  end
11
12
 
@@ -53,17 +54,6 @@ class ExecInputTest < Test::Unit::TestCase
53
54
  ]
54
55
  end
55
56
 
56
- def invalid_json_config
57
- # For counting command execution, redirect stderr to file
58
- %[
59
- command ruby #{@script} #{@test_time} 4
60
- format json
61
- tag_key tag
62
- time_key time
63
- run_interval 0.5
64
- ]
65
- end
66
-
67
57
  def test_configure
68
58
  d = create_driver
69
59
  assert_equal 'tsv', d.instance.format
@@ -103,6 +93,7 @@ class ExecInputTest < Test::Unit::TestCase
103
93
  emits = d.emits
104
94
  assert_equal true, emits.length > 0
105
95
  assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0]
96
+ assert_equal_event_time(@test_time, emits[0][1])
106
97
  end
107
98
 
108
99
  def test_emit_json
@@ -115,6 +106,7 @@ class ExecInputTest < Test::Unit::TestCase
115
106
  emits = d.emits
116
107
  assert_equal true, emits.length > 0
117
108
  assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0]
109
+ assert_equal_event_time(@test_time, emits[0][1])
118
110
  end
119
111
 
120
112
  def test_emit_msgpack
@@ -127,6 +119,7 @@ class ExecInputTest < Test::Unit::TestCase
127
119
  emits = d.emits
128
120
  assert_equal true, emits.length > 0
129
121
  assert_equal ["tag1", @test_time, {"k1"=>"ok"}], emits[0]
122
+ assert_equal_event_time(@test_time, emits[0][1])
130
123
  end
131
124
 
132
125
  def test_emit_regexp
@@ -139,18 +132,6 @@ class ExecInputTest < Test::Unit::TestCase
139
132
  emits = d.emits
140
133
  assert_equal true, emits.length > 0
141
134
  assert_equal ["regex_tag", @test_time, {"message"=>"hello"}], emits[0]
142
- assert_equal @test_time, emits[0][1]
143
- end
144
-
145
- def test_emit_with_invalid_script
146
- d = create_driver invalid_json_config
147
-
148
- d.run do
149
- sleep 2
150
- end
151
-
152
- assert_equal true, d.emits.empty?
153
- logs = d.instance.log.logs
154
- assert_equal true, logs.count { |line| line =~ /exec failed to run or shutdown child process/ }.between?(1, 4)
135
+ assert_equal_event_time(@test_time, emits[0][1])
155
136
  end
156
137
  end