fluentd 0.12.43 → 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 (253) 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 +1239 -0
  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 +58 -640
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -18
  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 +25 -19
  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 +119 -117
  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 -282
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -67
  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 +181 -55
  245. data/CHANGELOG.md +0 -710
  246. data/lib/fluent/buffer.rb +0 -365
  247. data/lib/fluent/plugin/filter_parser.rb +0 -107
  248. data/lib/fluent/plugin/in_status.rb +0 -76
  249. data/lib/fluent/test/helpers.rb +0 -86
  250. data/test/plugin/data/log/foo/bar2 +0 -0
  251. data/test/plugin/test_filter_parser.rb +0 -744
  252. data/test/plugin/test_in_status.rb +0 -38
  253. data/test/test_buffer.rb +0 -624
@@ -7,6 +7,18 @@ require 'fluent/env'
7
7
  require 'fluent/plugin/in_forward'
8
8
 
9
9
  class ForwardInputTest < Test::Unit::TestCase
10
+ class << self
11
+ def startup
12
+ socket_manager_path = ServerEngine::SocketManager::Server.generate_path
13
+ @server = ServerEngine::SocketManager::Server.open(socket_manager_path)
14
+ ENV['SERVERENGINE_SOCKETMANAGER_PATH'] = socket_manager_path.to_s
15
+ end
16
+
17
+ def shutdown
18
+ @server.close
19
+ end
20
+ end
21
+
10
22
  def setup
11
23
  Fluent::Test.setup
12
24
  @responses = [] # for testing responses after sending data
@@ -17,7 +29,6 @@ class ForwardInputTest < Test::Unit::TestCase
17
29
  port #{PORT}
18
30
  bind 127.0.0.1
19
31
  ]
20
- PEERADDR = ['?', '0000', '127.0.0.1', '127.0.0.1']
21
32
 
22
33
  def create_driver(conf=CONFIG)
23
34
  Fluent::Test::InputTestDriver.new(Fluent::ForwardInput).configure(conf)
@@ -41,15 +52,15 @@ class ForwardInputTest < Test::Unit::TestCase
41
52
  def test_time
42
53
  d = create_driver
43
54
 
44
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
55
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
45
56
  Fluent::Engine.now = time
46
57
 
47
58
  d.expect_emit "tag1", time, {"a"=>1}
48
59
  d.expect_emit "tag2", time, {"a"=>2}
49
60
 
50
61
  d.run do
51
- d.expected_emits.each {|tag,time,record|
52
- send_data [tag, 0, record].to_msgpack
62
+ d.expected_emits.each {|tag, _time, record|
63
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, 0, record]).to_s
53
64
  }
54
65
  end
55
66
  end
@@ -57,14 +68,29 @@ class ForwardInputTest < Test::Unit::TestCase
57
68
  def test_message
58
69
  d = create_driver
59
70
 
71
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
72
+
73
+ d.expect_emit "tag1", time, {"a"=>1}
74
+ d.expect_emit "tag2", time, {"a"=>2}
75
+
76
+ d.run do
77
+ d.expected_emits.each {|tag, _time, record|
78
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s
79
+ }
80
+ end
81
+ end
82
+
83
+ def test_message_with_time_as_integer
84
+ d = create_driver
85
+
60
86
  time = Time.parse("2011-01-02 13:14:15 UTC").to_i
61
87
 
62
88
  d.expect_emit "tag1", time, {"a"=>1}
63
89
  d.expect_emit "tag2", time, {"a"=>2}
64
90
 
65
91
  d.run do
66
- d.expected_emits.each {|tag,time,record|
67
- send_data Fluent::Engine.msgpack_factory.packer.write([tag, time, record]).to_s
92
+ d.expected_emits.each {|tag, _time, record|
93
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s
68
94
  }
69
95
  end
70
96
  end
@@ -72,19 +98,19 @@ class ForwardInputTest < Test::Unit::TestCase
72
98
  def test_message_with_skip_invalid_event
73
99
  d = create_driver(CONFIG + "skip_invalid_event true")
74
100
 
75
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
101
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
76
102
 
77
103
  d.expect_emit "tag1", time, {"a" => 1}
78
104
  d.expect_emit "tag2", time, {"a" => 2}
79
105
 
80
106
  d.run do
81
- entries = d.expected_emits.map { |tag, time, record| [tag, time, record] }
107
+ entries = d.expected_emits.map {|tag, _time, record| [tag, _time, record] }
82
108
  # These entries are skipped
83
109
  entries << ['tag1', true, {'a' => 3}] << ['tag2', time, 'invalid record']
84
110
 
85
- entries.each { |tag, time, record|
111
+ entries.each {|tag, _time, record|
86
112
  # Without ack, logs are sometimes not saved to logs during test.
87
- send_data Fluent::Engine.msgpack_factory.packer.write([tag, time, record]).to_s, true
113
+ send_data Fluent::Engine.msgpack_factory.packer.write([tag, _time, record]).to_s, true
88
114
  }
89
115
  end
90
116
 
@@ -94,30 +120,47 @@ class ForwardInputTest < Test::Unit::TestCase
94
120
  def test_forward
95
121
  d = create_driver
96
122
 
97
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
123
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
98
124
 
99
125
  d.expect_emit "tag1", time, {"a"=>1}
100
126
  d.expect_emit "tag1", time, {"a"=>2}
101
127
 
102
128
  d.run do
103
129
  entries = []
104
- d.expected_emits.each {|tag,time,record|
130
+ d.expected_emits.each {|tag, _time,record|
105
131
  entries << [time, record]
106
132
  }
107
133
  send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
108
134
  end
109
135
  end
110
136
 
137
+ def test_forward_with_time_as_integer
138
+ d = create_driver
139
+
140
+ time = Time.parse("2011-01-02 13:14:15 UTC").to_i
141
+
142
+ d.expect_emit "tag1", time, {"a"=>1}
143
+ d.expect_emit "tag1", time, {"a"=>2}
144
+
145
+ d.run do
146
+ entries = []
147
+ d.expected_emits.each {|_tag, _time, record|
148
+ entries << [_time, record]
149
+ }
150
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
151
+ end
152
+ end
153
+
111
154
  def test_forward_with_skip_invalid_event
112
155
  d = create_driver(CONFIG + "skip_invalid_event true")
113
156
 
114
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
157
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
115
158
 
116
159
  d.expect_emit "tag1", time, {"a" => 1}
117
160
  d.expect_emit "tag1", time, {"a" => 2}
118
161
 
119
162
  d.run do
120
- entries = d.expected_emits.map { |tag, time, record| [time, record] }
163
+ entries = d.expected_emits.map {|_tag, _time, record| [_time, record] }
121
164
  # These entries are skipped
122
165
  entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
123
166
 
@@ -130,6 +173,23 @@ class ForwardInputTest < Test::Unit::TestCase
130
173
  def test_packed_forward
131
174
  d = create_driver
132
175
 
176
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
177
+
178
+ d.expect_emit "tag1", time, {"a"=>1}
179
+ d.expect_emit "tag1", time, {"a"=>2}
180
+
181
+ d.run do
182
+ entries = ''
183
+ d.expected_emits.each {|_tag, _time, record|
184
+ Fluent::Engine.msgpack_factory.packer(entries).write([_time, record]).flush
185
+ }
186
+ send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
187
+ end
188
+ end
189
+
190
+ def test_packed_forward_with_time_as_integer
191
+ d = create_driver
192
+
133
193
  time = Time.parse("2011-01-02 13:14:15 UTC").to_i
134
194
 
135
195
  d.expect_emit "tag1", time, {"a"=>1}
@@ -137,8 +197,8 @@ class ForwardInputTest < Test::Unit::TestCase
137
197
 
138
198
  d.run do
139
199
  entries = ''
140
- d.expected_emits.each {|tag,time,record|
141
- Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush
200
+ d.expected_emits.each {|_tag, _time, record|
201
+ Fluent::Engine.msgpack_factory.packer(entries).write([_time, record]).flush
142
202
  }
143
203
  send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
144
204
  end
@@ -147,19 +207,19 @@ class ForwardInputTest < Test::Unit::TestCase
147
207
  def test_packed_forward_with_skip_invalid_event
148
208
  d = create_driver(CONFIG + "skip_invalid_event true")
149
209
 
150
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
210
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
151
211
 
152
212
  d.expect_emit "tag1", time, {"a" => 1}
153
213
  d.expect_emit "tag1", time, {"a" => 2}
154
214
 
155
215
  d.run do
156
- entries = d.expected_emits.map { |tag ,time, record| [time, record] }
216
+ entries = d.expected_emits.map {|_tag , _time, record| [_time, record] }
157
217
  # These entries are skipped
158
218
  entries << ['invalid time', {'a' => 3}] << [time, 'invalid record']
159
219
 
160
220
  packed_entries = ''
161
- entries.each { |time, record|
162
- Fluent::Engine.msgpack_factory.packer(packed_entries).write([time, record]).flush
221
+ entries.each {|_time, record|
222
+ Fluent::Engine.msgpack_factory.packer(packed_entries).write([_time, record]).flush
163
223
  }
164
224
  send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", packed_entries]).to_s
165
225
  end
@@ -176,8 +236,8 @@ class ForwardInputTest < Test::Unit::TestCase
176
236
  d.expect_emit "tag2", time, {"a"=>2}
177
237
 
178
238
  d.run do
179
- d.expected_emits.each {|tag,time,record|
180
- send_data [tag, time, record].to_json
239
+ d.expected_emits.each {|tag, _time, record|
240
+ send_data [tag, _time, record].to_json
181
241
  }
182
242
  end
183
243
  end
@@ -188,7 +248,7 @@ class ForwardInputTest < Test::Unit::TestCase
188
248
  chunk_size_limit 32M
189
249
  ])
190
250
 
191
- time = Time.parse("2014-04-25 13:14:15 UTC").to_i
251
+ time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
192
252
 
193
253
  # generate over 16M chunk
194
254
  str = "X" * 1024 * 1024
@@ -198,7 +258,7 @@ class ForwardInputTest < Test::Unit::TestCase
198
258
 
199
259
  d.run do
200
260
  Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
201
- d.instance.send(:on_message, obj, chunk.size, PEERADDR)
261
+ d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000")
202
262
  end
203
263
  end
204
264
 
@@ -206,7 +266,7 @@ class ForwardInputTest < Test::Unit::TestCase
206
266
  emits = d.emits
207
267
  assert_equal 16, emits.size
208
268
  assert emits.map(&:first).all?{|t| t == "test.tag" }
209
- assert_equal (0...16).to_a, emits.map{|tag, t, record| t - time }
269
+ assert_equal (0...16).to_a, emits.map{|_tag, t, _record| t - time }
210
270
 
211
271
  # check log
212
272
  assert d.instance.log.logs.select{|line|
@@ -219,7 +279,7 @@ class ForwardInputTest < Test::Unit::TestCase
219
279
  d = create_driver(CONFIG + %[
220
280
  chunk_size_warn_limit 16M
221
281
  ])
222
- time = Time.parse("2014-04-25 13:14:15 UTC").to_i
282
+ time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
223
283
 
224
284
  # generate over 16M chunk
225
285
  str = "X" * 1024 * 1024
@@ -227,7 +287,7 @@ class ForwardInputTest < Test::Unit::TestCase
227
287
 
228
288
  d.run do
229
289
  Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
230
- d.instance.send(:on_message, obj, chunk.size, PEERADDR)
290
+ d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000")
231
291
  end
232
292
  end
233
293
 
@@ -244,7 +304,7 @@ class ForwardInputTest < Test::Unit::TestCase
244
304
  chunk_size_limit 32M
245
305
  ])
246
306
 
247
- time = Time.parse("2014-04-25 13:14:15 UTC").to_i
307
+ time = Fluent::EventTime.parse("2014-04-25 13:14:15 UTC")
248
308
 
249
309
  # generate over 32M chunk
250
310
  str = "X" * 1024 * 1024
@@ -254,7 +314,7 @@ class ForwardInputTest < Test::Unit::TestCase
254
314
  # d.run => send_data
255
315
  d.run do
256
316
  Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj|
257
- d.instance.send(:on_message, obj, chunk.size, PEERADDR)
317
+ d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000")
258
318
  end
259
319
  end
260
320
 
@@ -276,7 +336,7 @@ class ForwardInputTest < Test::Unit::TestCase
276
336
 
277
337
  # d.run => send_data
278
338
  d.run do
279
- d.instance.send(:on_message, data, 1000000000, PEERADDR)
339
+ d.instance.send(:on_message, data, 1000000000, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000")
280
340
  end
281
341
 
282
342
  # check emitted data
@@ -292,7 +352,7 @@ class ForwardInputTest < Test::Unit::TestCase
292
352
  def test_respond_to_message_requiring_ack
293
353
  d = create_driver
294
354
 
295
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
355
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
296
356
 
297
357
  events = [
298
358
  ["tag1", time, {"a"=>1}],
@@ -303,10 +363,10 @@ class ForwardInputTest < Test::Unit::TestCase
303
363
  expected_acks = []
304
364
 
305
365
  d.run do
306
- events.each {|tag,time,record|
366
+ events.each {|tag, _time, record|
307
367
  op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
308
368
  expected_acks << op['chunk']
309
- send_data [tag, time, record, op].to_msgpack, true
369
+ send_data [tag, _time, record, op].to_msgpack, true
310
370
  }
311
371
  end
312
372
 
@@ -318,7 +378,7 @@ class ForwardInputTest < Test::Unit::TestCase
318
378
  def test_respond_to_forward_requiring_ack
319
379
  d = create_driver
320
380
 
321
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
381
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
322
382
 
323
383
  events = [
324
384
  ["tag1", time, {"a"=>1}],
@@ -330,7 +390,7 @@ class ForwardInputTest < Test::Unit::TestCase
330
390
 
331
391
  d.run do
332
392
  entries = []
333
- events.each {|tag,time,record|
393
+ events.each {|_tag, _time, record|
334
394
  entries << [time, record]
335
395
  }
336
396
  op = { 'chunk' => Base64.encode64(entries.object_id.to_s) }
@@ -345,7 +405,7 @@ class ForwardInputTest < Test::Unit::TestCase
345
405
  def test_respond_to_packed_forward_requiring_ack
346
406
  d = create_driver
347
407
 
348
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
408
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
349
409
 
350
410
  events = [
351
411
  ["tag1", time, {"a"=>1}],
@@ -357,8 +417,8 @@ class ForwardInputTest < Test::Unit::TestCase
357
417
 
358
418
  d.run do
359
419
  entries = ''
360
- events.each {|tag,time,record|
361
- [time, record].to_msgpack(entries)
420
+ events.each {|_tag, _time, record|
421
+ [_time, record].to_msgpack(entries)
362
422
  }
363
423
  op = { 'chunk' => Base64.encode64(entries.object_id.to_s) }
364
424
  expected_acks << op['chunk']
@@ -383,21 +443,22 @@ class ForwardInputTest < Test::Unit::TestCase
383
443
  expected_acks = []
384
444
 
385
445
  d.run do
386
- events.each {|tag,time,record|
446
+ events.each {|tag, _time, record|
387
447
  op = { 'chunk' => Base64.encode64(record.object_id.to_s) }
388
448
  expected_acks << op['chunk']
389
- send_data [tag, time, record, op].to_json, true
449
+ send_data [tag, _time, record, op].to_json, true
390
450
  }
391
451
  end
392
452
 
393
453
  assert_equal events, d.emits
394
454
  assert_equal expected_acks, @responses.map { |res| JSON.parse(res)['ack'] }
455
+
395
456
  end
396
457
 
397
458
  def test_not_respond_to_message_not_requiring_ack
398
459
  d = create_driver
399
460
 
400
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
461
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
401
462
 
402
463
  events = [
403
464
  ["tag1", time, {"a"=>1}],
@@ -406,8 +467,8 @@ class ForwardInputTest < Test::Unit::TestCase
406
467
  d.expected_emits_length = events.length
407
468
 
408
469
  d.run do
409
- events.each {|tag,time,record|
410
- send_data [tag, time, record].to_msgpack, true
470
+ events.each {|tag, _time, record|
471
+ send_data [tag, _time, record].to_msgpack, true
411
472
  }
412
473
  end
413
474
 
@@ -418,7 +479,7 @@ class ForwardInputTest < Test::Unit::TestCase
418
479
  def test_not_respond_to_forward_not_requiring_ack
419
480
  d = create_driver
420
481
 
421
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
482
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
422
483
 
423
484
  events = [
424
485
  ["tag1", time, {"a"=>1}],
@@ -428,8 +489,8 @@ class ForwardInputTest < Test::Unit::TestCase
428
489
 
429
490
  d.run do
430
491
  entries = []
431
- events.each {|tag,time,record|
432
- entries << [time, record]
492
+ events.each {|_tag, _time, record|
493
+ entries << [_time, record]
433
494
  }
434
495
  send_data ["tag1", entries].to_msgpack, true
435
496
  end
@@ -441,7 +502,7 @@ class ForwardInputTest < Test::Unit::TestCase
441
502
  def test_not_respond_to_packed_forward_not_requiring_ack
442
503
  d = create_driver
443
504
 
444
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
505
+ time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC")
445
506
 
446
507
  events = [
447
508
  ["tag1", time, {"a"=>1}],
@@ -451,8 +512,8 @@ class ForwardInputTest < Test::Unit::TestCase
451
512
 
452
513
  d.run do
453
514
  entries = ''
454
- events.each {|tag,time,record|
455
- [time, record].to_msgpack(entries)
515
+ events.each {|_tag, _time, record|
516
+ [_time, record].to_msgpack(entries)
456
517
  }
457
518
  send_data ["tag1", entries].to_msgpack, true
458
519
  end
@@ -473,8 +534,8 @@ class ForwardInputTest < Test::Unit::TestCase
473
534
  d.expected_emits_length = events.length
474
535
 
475
536
  d.run do
476
- events.each {|tag,time,record|
477
- send_data [tag, time, record].to_json, true
537
+ events.each {|tag, _time, record|
538
+ send_data [tag, _time, record].to_json, true
478
539
  }
479
540
  end
480
541
 
@@ -498,105 +559,5 @@ class ForwardInputTest < Test::Unit::TestCase
498
559
  @responses << res if try_to_receive_response
499
560
  end
500
561
 
501
- LOCALHOST_HOSTNAME_GETTER = ->(){sock = UDPSocket.new(::Socket::AF_INET); sock.do_not_reverse_lookup = false; sock.connect("127.0.0.1", 2048); sock.peeraddr[2] }
502
- LOCALHOST_HOSTNAME = LOCALHOST_HOSTNAME_GETTER.call
503
- DUMMY_SOCK = Struct.new(:remote_host, :remote_addr, :remote_port).new(LOCALHOST_HOSTNAME, "127.0.0.1", 0)
504
-
505
- sub_test_case 'source_hostname_key and source_address_key features' do
506
- test 'resolve_hostname must be true with source_hostname_key' do
507
- assert_raise(Fluent::ConfigError) {
508
- create_driver(CONFIG + <<EOS)
509
- resolve_hostname false
510
- source_hostname_key hostname
511
- EOS
512
- }
513
- end
514
- data(
515
- both: [:hostname, :address],
516
- hostname: [:hostname],
517
- address: [:address],
518
- )
519
- test 'message protocol' do |keys|
520
- execute_test(*keys) { |events|
521
- events.each { |tag, time, record|
522
- send_data [tag, time, record].to_msgpack
523
- }
524
- }
525
- end
526
-
527
- data(
528
- both: [:hostname, :address],
529
- hostname: [:hostname],
530
- address: [:address],
531
- )
532
- test 'forward protocol' do |keys|
533
- execute_test(*keys) { |events|
534
- entries = []
535
- events.each {|tag,time,record|
536
- entries << [time, record]
537
- }
538
- send_data ['tag1', entries].to_msgpack
539
- }
540
- end
541
-
542
- data(
543
- both: [:hostname, :address],
544
- hostname: [:hostname],
545
- address: [:address],
546
- )
547
- test 'packed forward protocol' do |keys|
548
- execute_test(*keys) { |events|
549
- entries = ''
550
- events.each { |tag, time, record|
551
- Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush
552
- }
553
- send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s
554
- }
555
- end
556
-
557
- def execute_test(*keys, &block)
558
- conf = CONFIG.dup
559
- if keys.include?(:hostname)
560
- conf << <<EOL
561
- source_hostname_key source_hostname
562
- EOL
563
- end
564
- if keys.include?(:address)
565
- conf << <<EOL
566
- source_address_key source_address
567
- EOL
568
- end
569
- d = create_driver(conf)
570
-
571
- time = Time.parse("2011-01-02 13:14:15 UTC").to_i
572
- events = [
573
- ["tag1", time, {"a"=>1}],
574
- ["tag1", time, {"a"=>2}]
575
- ]
576
- d.expected_emits_length = events.length
577
-
578
- d.run do
579
- block.call(events)
580
- end
581
-
582
- d.emits.each { |tag, _time, record|
583
- if keys.include?(:hostname)
584
- assert_true record.has_key?('source_hostname')
585
- assert_equal DUMMY_SOCK.remote_host, record['source_hostname']
586
- unless keys.include?(:address)
587
- assert_false record.has_key?('source_address')
588
- end
589
- end
590
- if keys.include?(:address)
591
- assert_true record.has_key?('source_address')
592
- assert_equal DUMMY_SOCK.remote_addr, record['source_address']
593
- unless keys.include?(:hostname)
594
- assert_false record.has_key?('source_hostname')
595
- end
596
- end
597
- }
598
- end
599
- end
600
-
601
562
  # TODO heartbeat
602
563
  end