fluentd 0.12.43 → 0.14.0

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 (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
@@ -1,15 +1,23 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/test'
3
+ require 'fluent/plugin/in_tail'
4
+ require 'fluent/plugin/buffer'
5
+ require 'fluent/system_config'
3
6
  require 'net/http'
4
7
  require 'flexmock/test_unit'
5
- require 'timecop'
6
8
 
7
9
  class TailInputTest < Test::Unit::TestCase
8
10
  include FlexMock::TestCase
9
11
 
10
12
  def setup
11
13
  Fluent::Test.setup
12
- FileUtils.rm_rf(TMP_DIR)
14
+ FileUtils.rm_rf(TMP_DIR, secure: true)
15
+ if File.exist?(TMP_DIR)
16
+ # ensure files are closed for Windows, on which deleted files
17
+ # are still visible from filesystem
18
+ GC.start(full_mark: true, immediate_mark: true, immediate_sweep: true)
19
+ FileUtils.remove_entry_secure(TMP_DIR)
20
+ end
13
21
  FileUtils.mkdir_p(TMP_DIR)
14
22
  end
15
23
 
@@ -50,7 +58,6 @@ class TailInputTest < Test::Unit::TestCase
50
58
  assert_equal 2, d.instance.rotate_wait
51
59
  assert_equal "#{TMP_DIR}/tail.pos", d.instance.pos_file
52
60
  assert_equal 1000, d.instance.read_lines_limit
53
- assert_equal false, d.instance.ignore_repeated_permission_error
54
61
  end
55
62
 
56
63
  def test_configure_encoding
@@ -64,45 +71,20 @@ class TailInputTest < Test::Unit::TestCase
64
71
  end
65
72
  end
66
73
 
67
- def test_configure_from_encoding
68
- # If only specified from_encoding raise ConfigError
69
- assert_raise(Fluent::ConfigError) do
70
- d = create_driver(SINGLE_LINE_CONFIG + 'from_encoding utf-8')
71
- end
72
-
73
- # valid setting
74
- d = create_driver %[
75
- format /(?<message>.*)/
76
- read_from_head true
77
- from_encoding utf-8
78
- encoding utf-8
79
- ]
80
- assert_equal Encoding::UTF_8, d.instance.from_encoding
81
-
82
- # invalid from_encoding
83
- assert_raise(Fluent::ConfigError) do
84
- d = create_driver %[
85
- format /(?<message>.*)/
86
- read_from_head true
87
- from_encoding no-such-encoding
88
- encoding utf-8
89
- ]
90
- end
91
- end
92
-
93
74
  # TODO: Should using more better approach instead of sleep wait
94
75
 
95
76
  def test_emit
96
- File.open("#{TMP_DIR}/tail.txt", "w") {|f|
77
+ File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
97
78
  f.puts "test1"
98
79
  f.puts "test2"
99
80
  }
100
81
 
101
82
  d = create_driver
83
+
102
84
  d.run do
103
85
  sleep 1
104
86
 
105
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
87
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
106
88
  f.puts "test3"
107
89
  f.puts "test4"
108
90
  }
@@ -113,35 +95,69 @@ class TailInputTest < Test::Unit::TestCase
113
95
  assert_equal(true, emits.length > 0)
114
96
  assert_equal({"message" => "test3"}, emits[0][2])
115
97
  assert_equal({"message" => "test4"}, emits[1][2])
98
+ assert(emits[0][1].is_a?(Fluent::EventTime))
99
+ assert(emits[1][1].is_a?(Fluent::EventTime))
116
100
  assert_equal(1, d.emit_streams.size)
117
101
  end
118
102
 
119
- def test_emit_with_emit_unmatched_lines_true
120
- File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
103
+ class TestWithSystem < self
104
+ include Fluent::SystemConfig::Mixin
121
105
 
122
- d = create_driver(%[
123
- format /^(?<message>test.*)/
124
- emit_unmatched_lines true
125
- ])
126
- d.run do
127
- sleep 1
106
+ OVERRIDE_FILE_PERMISSION = 0620
107
+ CONFIG_SYSTEM = %[
108
+ <system>
109
+ file_permission #{OVERRIDE_FILE_PERMISSION}
110
+ </system>
111
+ ]
128
112
 
129
- File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
130
- f.puts "test line 1"
131
- f.puts "test line 2"
132
- f.puts "bad line 1"
133
- f.puts "test line 3"
134
- }
113
+ def setup
114
+ omit "NTFS doesn't support UNIX like permissions" if Fluent.windows?
115
+ # Store default permission
116
+ @default_permission = system_config.instance_variable_get(:@file_permission)
117
+ end
135
118
 
136
- sleep 1
119
+ def teardown
120
+ # Restore default permission
121
+ system_config.instance_variable_set(:@file_permission, @default_permission)
122
+ end
123
+
124
+ def parse_system(text)
125
+ basepath = File.expand_path(File.dirname(__FILE__) + '/../../')
126
+ Fluent::Config.parse(text, '(test)', basepath, true).elements.find { |e| e.name == 'system' }
137
127
  end
138
128
 
139
- events = d.emits
140
- assert_equal(4, events.length)
141
- assert_equal({"message" => "test line 1"}, events[0][2])
142
- assert_equal({"message" => "test line 2"}, events[1][2])
143
- assert_equal({"unmatched_line" => "bad line 1"}, events[2][2])
144
- assert_equal({"message" => "test line 3"}, events[3][2])
129
+ def test_emit_with_system
130
+ system_conf = parse_system(CONFIG_SYSTEM)
131
+ sc = Fluent::SystemConfig.new(system_conf)
132
+ Fluent::Engine.init(sc)
133
+ File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
134
+ f.puts "test1"
135
+ f.puts "test2"
136
+ }
137
+
138
+ d = create_driver
139
+
140
+ d.run do
141
+ sleep 1
142
+
143
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
144
+ f.puts "test3"
145
+ f.puts "test4"
146
+ }
147
+ sleep 1
148
+ end
149
+
150
+ emits = d.emits
151
+ assert_equal(true, emits.length > 0)
152
+ assert_equal({"message" => "test3"}, emits[0][2])
153
+ assert_equal({"message" => "test4"}, emits[1][2])
154
+ assert(emits[0][1].is_a?(Fluent::EventTime))
155
+ assert(emits[1][1].is_a?(Fluent::EventTime))
156
+ assert_equal(1, d.emit_streams.size)
157
+ pos = d.instance.instance_variable_get(:@pf_file)
158
+ mode = "%o" % File.stat(pos).mode
159
+ assert_equal OVERRIDE_FILE_PERMISSION, mode[-3, 3].to_i
160
+ end
145
161
  end
146
162
 
147
163
  data('1' => [1, 2], '10' => [10, 1])
@@ -153,7 +169,7 @@ class TailInputTest < Test::Unit::TestCase
153
169
  d.run do
154
170
  sleep 1
155
171
 
156
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
172
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
157
173
  f.puts msg
158
174
  f.puts msg
159
175
  }
@@ -168,7 +184,7 @@ class TailInputTest < Test::Unit::TestCase
168
184
  end
169
185
 
170
186
  def test_emit_with_read_from_head
171
- File.open("#{TMP_DIR}/tail.txt", "w") {|f|
187
+ File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
172
188
  f.puts "test1"
173
189
  f.puts "test2"
174
190
  }
@@ -178,7 +194,7 @@ class TailInputTest < Test::Unit::TestCase
178
194
  d.run do
179
195
  sleep 1
180
196
 
181
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
197
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
182
198
  f.puts "test3"
183
199
  f.puts "test4"
184
200
  }
@@ -241,13 +257,13 @@ class TailInputTest < Test::Unit::TestCase
241
257
 
242
258
  def test_rotate_file_with_write_old
243
259
  emits = sub_test_rotate_file(SINGLE_LINE_CONFIG) { |rotated_file|
244
- File.open("#{TMP_DIR}/tail.txt", "w") { |f| }
260
+ File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
245
261
  rotated_file.puts "test7"
246
262
  rotated_file.puts "test8"
247
263
  rotated_file.flush
248
264
 
249
265
  sleep 1
250
- File.open("#{TMP_DIR}/tail.txt", "a") { |f|
266
+ File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
251
267
  f.puts "test5"
252
268
  f.puts "test6"
253
269
  }
@@ -275,7 +291,7 @@ class TailInputTest < Test::Unit::TestCase
275
291
  end
276
292
 
277
293
  def sub_test_rotate_file(config = nil)
278
- file = File.open("#{TMP_DIR}/tail.txt", "w")
294
+ file = Fluent::FileWrapper.open("#{TMP_DIR}/tail.txt", "wb")
279
295
  file.puts "test1"
280
296
  file.puts "test2"
281
297
  file.flush
@@ -295,10 +311,10 @@ class TailInputTest < Test::Unit::TestCase
295
311
  sleep 1
296
312
  else
297
313
  sleep 1
298
- File.open("#{TMP_DIR}/tail.txt", "w") { |f| }
314
+ File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
299
315
  sleep 1
300
316
 
301
- File.open("#{TMP_DIR}/tail.txt", "a") { |f|
317
+ File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
302
318
  f.puts "test5"
303
319
  f.puts "test6"
304
320
  }
@@ -312,69 +328,21 @@ class TailInputTest < Test::Unit::TestCase
312
328
 
313
329
  d.emits
314
330
  ensure
315
- file.close
316
- end
317
-
318
- def test_truncate_file
319
- File.open("#{TMP_DIR}/tail.txt", "w") {|f|
320
- f.puts "test1"
321
- f.puts "test2"
322
- }
323
-
324
- d = create_driver
325
- d.run do
326
- sleep 1
327
-
328
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
329
- f.puts "test3"
330
- f.puts "test4"
331
- }
332
- sleep 1
333
- File.truncate("#{TMP_DIR}/tail.txt", 6)
334
- sleep 1
335
- end
336
-
337
- emits = d.emits
338
- assert_equal(3, emits.length)
339
- assert_equal({"message" => "test3"}, emits[0][2])
340
- assert_equal({"message" => "test4"}, emits[1][2])
341
- assert_equal({"message" => "test1"}, emits[2][2])
342
- end
343
-
344
- def test_move_truncate_move_back
345
- File.open("#{TMP_DIR}/tail.txt", "w") {|f|
346
- f.puts "test1"
347
- f.puts "test2"
348
- }
349
-
350
- d = create_driver
351
- d.run do
352
- sleep 1
353
- FileUtils.mv("#{TMP_DIR}/tail.txt", "#{TMP_DIR}/tail2.txt")
354
- sleep 1
355
- File.truncate("#{TMP_DIR}/tail2.txt", 6)
356
- sleep 1
357
- FileUtils.mv("#{TMP_DIR}/tail2.txt", "#{TMP_DIR}/tail.txt")
358
- sleep 1
359
- end
360
-
361
- emits = d.emits
362
- assert_equal(1, emits.length)
363
- assert_equal({"message" => "test1"}, emits[0][2])
331
+ file.close if file
364
332
  end
365
333
 
366
334
  def test_lf
367
- File.open("#{TMP_DIR}/tail.txt", "w") {|f| }
335
+ File.open("#{TMP_DIR}/tail.txt", "wb") {|f| }
368
336
 
369
337
  d = create_driver
370
338
 
371
339
  d.run do
372
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
340
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
373
341
  f.print "test3"
374
342
  }
375
343
  sleep 1
376
344
 
377
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
345
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
378
346
  f.puts "test4"
379
347
  }
380
348
  sleep 1
@@ -386,14 +354,14 @@ class TailInputTest < Test::Unit::TestCase
386
354
  end
387
355
 
388
356
  def test_whitespace
389
- File.open("#{TMP_DIR}/tail.txt", "w") {|f| }
357
+ File.open("#{TMP_DIR}/tail.txt", "wb") {|f| }
390
358
 
391
359
  d = create_driver
392
360
 
393
361
  d.run do
394
362
  sleep 1
395
363
 
396
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
364
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
397
365
  f.puts " " # 4 spaces
398
366
  f.puts " 4 spaces"
399
367
  f.puts "4 spaces "
@@ -435,32 +403,10 @@ class TailInputTest < Test::Unit::TestCase
435
403
  assert_equal(encoding, emits[0][2]['message'].encoding)
436
404
  end
437
405
 
438
- def test_from_encoding
439
- d = create_driver %[
440
- format /(?<message>.*)/
441
- read_from_head true
442
- from_encoding cp932
443
- encoding utf-8
444
- ]
445
-
446
- d.run do
447
- sleep 1
448
-
449
- File.open("#{TMP_DIR}/tail.txt", "w:cp932") {|f|
450
- f.puts "\x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932)
451
- }
452
- sleep 1
453
- end
454
-
455
- emits = d.emits
456
- assert_equal("\x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932).encode(Encoding::UTF_8), emits[0][2]['message'])
457
- assert_equal(Encoding::UTF_8, emits[0][2]['message'].encoding)
458
- end
459
-
460
406
  # multiline mode test
461
407
 
462
408
  def test_multiline
463
- File.open("#{TMP_DIR}/tail.txt", "w") { |f| }
409
+ File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
464
410
 
465
411
  d = create_driver %[
466
412
  format multiline
@@ -468,7 +414,7 @@ class TailInputTest < Test::Unit::TestCase
468
414
  format_firstline /^[s]/
469
415
  ]
470
416
  d.run do
471
- File.open("#{TMP_DIR}/tail.txt", "a") { |f|
417
+ File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
472
418
  f.puts "f test1"
473
419
  f.puts "s test2"
474
420
  f.puts "f test3"
@@ -496,44 +442,6 @@ class TailInputTest < Test::Unit::TestCase
496
442
  assert_equal({"message1" => "test8"}, emits[3][2])
497
443
  end
498
444
 
499
- def test_multiline_with_emit_unmatched_lines_true
500
- File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
501
-
502
- d = create_driver %[
503
- format multiline
504
- format1 /^s (?<message1>[^\\n]+)(\\nf (?<message2>[^\\n]+))?(\\nf (?<message3>.*))?/
505
- format_firstline /^[s]/
506
- emit_unmatched_lines true
507
- ]
508
- d.run do
509
- File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
510
- f.puts "f test1"
511
- f.puts "s test2"
512
- f.puts "f test3"
513
- f.puts "f test4"
514
- f.puts "s test5"
515
- f.puts "s test6"
516
- f.puts "f test7"
517
- f.puts "s test8"
518
- }
519
- sleep 1
520
-
521
- events = d.emits
522
- assert_equal(4, events.length)
523
- assert_equal({"unmatched_line" => "f test1"}, events[0][2])
524
- assert_equal({"message1" => "test2", "message2" => "test3", "message3" => "test4"}, events[1][2])
525
- assert_equal({"message1" => "test5"}, events[2][2])
526
- assert_equal({"message1" => "test6", "message2" => "test7"}, events[3][2])
527
-
528
- sleep 3
529
- assert_equal(4, d.emits.length)
530
- end
531
-
532
- emits = d.emits
533
- assert_equal(5, emits.length)
534
- assert_equal({"message1" => "test8"}, emits[4][2])
535
- end
536
-
537
445
  def test_multiline_with_flush_interval
538
446
  File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
539
447
 
@@ -599,33 +507,8 @@ class TailInputTest < Test::Unit::TestCase
599
507
  end
600
508
  end
601
509
 
602
- def test_multiline_from_encoding_of_flushed_record
603
- d = create_driver %[
604
- format multiline
605
- format1 /^s (?<message1>[^\\n]+)(\\nf (?<message2>[^\\n]+))?(\\nf (?<message3>.*))?/
606
- format_firstline /^[s]/
607
- multiline_flush_interval 2s
608
- read_from_head true
609
- from_encoding cp932
610
- encoding utf-8
611
- ]
612
-
613
- d.run do
614
- sleep 1
615
- File.open("#{TMP_DIR}/tail.txt", "w:cp932") { |f|
616
- f.puts "s \x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932)
617
- }
618
-
619
- sleep 4
620
- emits = d.emits
621
- assert_equal(1, emits.length)
622
- assert_equal("\x82\xCD\x82\xEB\x81\x5B\x82\xED\x81\x5B\x82\xE9\x82\xC7".force_encoding(Encoding::CP932).encode(Encoding::UTF_8), emits[0][2]['message1'])
623
- assert_equal(Encoding::UTF_8, emits[0][2]['message1'].encoding)
624
- end
625
- end
626
-
627
510
  def test_multiline_with_multiple_formats
628
- File.open("#{TMP_DIR}/tail.txt", "w") { |f| }
511
+ File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
629
512
 
630
513
  d = create_driver %[
631
514
  format multiline
@@ -635,7 +518,7 @@ class TailInputTest < Test::Unit::TestCase
635
518
  format_firstline /^[s]/
636
519
  ]
637
520
  d.run do
638
- File.open("#{TMP_DIR}/tail.txt", "a") { |f|
521
+ File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
639
522
  f.puts "f test1"
640
523
  f.puts "s test2"
641
524
  f.puts "f test3"
@@ -658,7 +541,7 @@ class TailInputTest < Test::Unit::TestCase
658
541
 
659
542
  def test_multilinelog_with_multiple_paths
660
543
  files = ["#{TMP_DIR}/tail1.txt", "#{TMP_DIR}/tail2.txt"]
661
- files.each { |file| File.open(file, "w") { |f| } }
544
+ files.each { |file| File.open(file, "wb") { |f| } }
662
545
 
663
546
  d = create_driver(%[
664
547
  path #{files[0]},#{files[1]}
@@ -669,7 +552,7 @@ class TailInputTest < Test::Unit::TestCase
669
552
  ], false)
670
553
  d.run do
671
554
  files.each do |file|
672
- File.open(file, 'a') { |f|
555
+ File.open(file, 'ab') { |f|
673
556
  f.puts "f #{file} line should be ignored"
674
557
  f.puts "s test1"
675
558
  f.puts "f test2"
@@ -689,7 +572,7 @@ class TailInputTest < Test::Unit::TestCase
689
572
  end
690
573
 
691
574
  def test_multiline_without_firstline
692
- File.open("#{TMP_DIR}/tail.txt", "w") { |f| }
575
+ File.open("#{TMP_DIR}/tail.txt", "wb") { |f| }
693
576
 
694
577
  d = create_driver %[
695
578
  format multiline
@@ -698,7 +581,7 @@ class TailInputTest < Test::Unit::TestCase
698
581
  format3 /(?<var3>baz \\d)/
699
582
  ]
700
583
  d.run do
701
- File.open("#{TMP_DIR}/tail.txt", "a") { |f|
584
+ File.open("#{TMP_DIR}/tail.txt", "ab") { |f|
702
585
  f.puts "foo 1"
703
586
  f.puts "bar 1"
704
587
  f.puts "baz 1"
@@ -747,32 +630,13 @@ class TailInputTest < Test::Unit::TestCase
747
630
  assert_equal EX_PATHS - [EX_PATHS.last], plugin.expand_paths.sort
748
631
  end
749
632
 
750
- def test_log_file_without_extension
751
- expected_files = [
752
- 'test/plugin/data/log/bar',
753
- 'test/plugin/data/log/foo/bar.log',
754
- 'test/plugin/data/log/foo/bar2',
755
- 'test/plugin/data/log/test.log'
756
- ]
757
-
758
- config = config_element("", "", {
759
- "tag" => "tail",
760
- "path" => "test/plugin/data/log/**/*",
761
- "format" => "none",
762
- "pos_file" => "#{TMP_DIR}/tail.pos"
763
- })
764
-
765
- plugin = create_driver(config, false).instance
766
- assert_equal expected_files, plugin.expand_paths.sort
767
- end
768
-
769
- def test_refresh_watchers
633
+ def test_z_refresh_watchers
770
634
  plugin = create_driver(EX_CONFIG, false).instance
771
635
  sio = StringIO.new
772
636
  plugin.instance_eval do
773
637
  @pf = Fluent::NewTailInput::PositionFile.parse(sio)
774
638
  @loop = Coolio::Loop.new
775
- end
639
+ end
776
640
 
777
641
  flexstub(Time) do |timeclass|
778
642
  timeclass.should_receive(:now).with_no_args.and_return(Time.new(2010, 1, 2, 3, 4, 5), Time.new(2010, 1, 2, 3, 4, 6), Time.new(2010, 1, 2, 3, 4, 7))
@@ -868,24 +732,12 @@ class TailInputTest < Test::Unit::TestCase
868
732
  engineclass.should_receive(:emit_stream).with('pre.foo.bar.log.post', any).once
869
733
  plugin.receive_lines(['foo', 'bar'], DummyWatcher.new('foo.bar.log'))
870
734
  end
871
-
872
- config = %[
873
- tag *
874
- path test/plugin/*/%Y/%m/%Y%m%d-%H%M%S.log,test/plugin/data/log/**/*.log
875
- format none
876
- read_from_head true
877
- ]
878
- plugin = create_driver(config, false).instance
879
- flexstub(plugin.router) do |engineclass|
880
- engineclass.should_receive(:emit_stream).with('foo.bar.log', any).once
881
- plugin.receive_lines(['foo', 'bar'], DummyWatcher.new('foo.bar.log'))
882
- end
883
735
  end
884
736
 
885
737
  # Ensure that no fatal exception is raised when a file is missing and that
886
738
  # files that do exist are still tailed as expected.
887
739
  def test_missing_file
888
- File.open("#{TMP_DIR}/tail.txt", "w") {|f|
740
+ File.open("#{TMP_DIR}/tail.txt", "wb") {|f|
889
741
  f.puts "test1"
890
742
  f.puts "test2"
891
743
  }
@@ -904,7 +756,7 @@ class TailInputTest < Test::Unit::TestCase
904
756
  d = create_driver(config, false)
905
757
  d.run do
906
758
  sleep 1
907
- File.open("#{TMP_DIR}/tail.txt", "a") {|f|
759
+ File.open("#{TMP_DIR}/tail.txt", "ab") {|f|
908
760
  f.puts "test3"
909
761
  f.puts "test4"
910
762
  }
@@ -919,7 +771,7 @@ class TailInputTest < Test::Unit::TestCase
919
771
 
920
772
  sub_test_case 'emit error cases' do
921
773
  def test_emit_error_with_buffer_queue_limit_error
922
- emits = execute_test(::Fluent::BufferQueueLimitError, "queue size exceeds limit")
774
+ emits = execute_test(Fluent::Plugin::Buffer::BufferOverflowError, "buffer space has too many data")
923
775
  assert_equal(10, emits.length)
924
776
  10.times { |i|
925
777
  assert_equal({"message" => "test#{i}"}, emits[i][2])
@@ -1073,43 +925,4 @@ class TailInputTest < Test::Unit::TestCase
1073
925
  assert_equal(files, [emits[2][2]["path"], emits[3][2]["path"]].sort)
1074
926
  end
1075
927
  end
1076
-
1077
- def test_limit_recently_modified
1078
- now = Time.new(2010, 1, 2, 3, 4, 5)
1079
- FileUtils.touch("#{TMP_DIR}/tail_unwatch.txt", mtime: (now - 3601))
1080
- FileUtils.touch("#{TMP_DIR}/tail_watch1.txt", mtime: (now - 3600))
1081
- FileUtils.touch("#{TMP_DIR}/tail_watch2.txt", mtime: now)
1082
-
1083
- config = config_element('', '', {
1084
- 'tag' => 'tail',
1085
- 'path' => "#{TMP_DIR}/*.txt",
1086
- 'format' => 'none',
1087
- 'limit_recently_modified' => '3600s'
1088
- })
1089
-
1090
- expected_files = [
1091
- "#{TMP_DIR}/tail_watch1.txt",
1092
- "#{TMP_DIR}/tail_watch2.txt"
1093
- ]
1094
-
1095
- Timecop.freeze(now) do
1096
- plugin = create_driver(config, false).instance
1097
- assert_equal expected_files, plugin.expand_paths.sort
1098
- end
1099
- end
1100
-
1101
- def test_skip_refresh_on_startup
1102
- FileUtils.touch("#{TMP_DIR}/tail.txt")
1103
- config = config_element('', '', {
1104
- 'tag' => 'tail',
1105
- 'path' => "#{TMP_DIR}/*.txt",
1106
- 'format' => 'none',
1107
- 'refresh_interval' => 1,
1108
- 'skip_refresh_on_startup' => true
1109
- })
1110
- d = create_driver(config, false)
1111
- d.run {
1112
- sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size == 1
1113
- }
1114
- end
1115
928
  end