fluentd 0.14.8 → 0.14.9

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/CONTRIBUTING.md +6 -1
  4. data/ChangeLog +38 -0
  5. data/Rakefile +21 -0
  6. data/example/out_exec_filter.conf +42 -0
  7. data/lib/fluent/agent.rb +2 -2
  8. data/lib/fluent/command/binlog_reader.rb +1 -1
  9. data/lib/fluent/command/cat.rb +5 -2
  10. data/lib/fluent/compat/output.rb +7 -8
  11. data/lib/fluent/compat/parser.rb +139 -11
  12. data/lib/fluent/config/configure_proxy.rb +2 -11
  13. data/lib/fluent/config/section.rb +7 -0
  14. data/lib/fluent/configurable.rb +1 -3
  15. data/lib/fluent/log.rb +1 -1
  16. data/lib/fluent/plugin/base.rb +17 -0
  17. data/lib/fluent/plugin/filter_parser.rb +108 -0
  18. data/lib/fluent/plugin/filter_record_transformer.rb +4 -7
  19. data/lib/fluent/plugin/filter_stdout.rb +1 -1
  20. data/lib/fluent/plugin/formatter.rb +5 -0
  21. data/lib/fluent/plugin/formatter_msgpack.rb +4 -0
  22. data/lib/fluent/plugin/formatter_stdout.rb +3 -2
  23. data/lib/fluent/plugin/formatter_tsv.rb +34 -0
  24. data/lib/fluent/plugin/in_exec.rb +48 -93
  25. data/lib/fluent/plugin/in_forward.rb +25 -105
  26. data/lib/fluent/plugin/in_http.rb +68 -65
  27. data/lib/fluent/plugin/in_syslog.rb +29 -51
  28. data/lib/fluent/plugin/multi_output.rb +1 -3
  29. data/lib/fluent/plugin/out_exec.rb +58 -71
  30. data/lib/fluent/plugin/out_exec_filter.rb +199 -279
  31. data/lib/fluent/plugin/out_file.rb +155 -80
  32. data/lib/fluent/plugin/out_forward.rb +44 -47
  33. data/lib/fluent/plugin/out_stdout.rb +6 -21
  34. data/lib/fluent/plugin/output.rb +23 -17
  35. data/lib/fluent/plugin/parser.rb +121 -61
  36. data/lib/fluent/plugin/parser_csv.rb +9 -3
  37. data/lib/fluent/plugin/parser_json.rb +37 -35
  38. data/lib/fluent/plugin/parser_ltsv.rb +11 -19
  39. data/lib/fluent/plugin/parser_msgpack.rb +50 -0
  40. data/lib/fluent/plugin/parser_regexp.rb +15 -42
  41. data/lib/fluent/plugin/parser_tsv.rb +8 -3
  42. data/lib/fluent/plugin_helper.rb +8 -1
  43. data/lib/fluent/plugin_helper/child_process.rb +139 -73
  44. data/lib/fluent/plugin_helper/compat_parameters.rb +93 -4
  45. data/lib/fluent/plugin_helper/event_emitter.rb +14 -1
  46. data/lib/fluent/plugin_helper/extract.rb +16 -4
  47. data/lib/fluent/plugin_helper/formatter.rb +9 -11
  48. data/lib/fluent/plugin_helper/inject.rb +4 -0
  49. data/lib/fluent/plugin_helper/parser.rb +3 -3
  50. data/lib/fluent/root_agent.rb +1 -1
  51. data/lib/fluent/test/driver/base.rb +51 -37
  52. data/lib/fluent/test/driver/base_owner.rb +18 -8
  53. data/lib/fluent/test/driver/multi_output.rb +2 -1
  54. data/lib/fluent/test/driver/output.rb +29 -6
  55. data/lib/fluent/test/helpers.rb +3 -1
  56. data/lib/fluent/test/log.rb +4 -0
  57. data/lib/fluent/test/startup_shutdown.rb +13 -0
  58. data/lib/fluent/time.rb +14 -8
  59. data/lib/fluent/version.rb +1 -1
  60. data/test/command/test_binlog_reader.rb +5 -1
  61. data/test/config/test_configurable.rb +173 -0
  62. data/test/config/test_configure_proxy.rb +0 -43
  63. data/test/plugin/test_base.rb +16 -0
  64. data/test/plugin/test_filter_parser.rb +665 -0
  65. data/test/plugin/test_filter_record_transformer.rb +11 -3
  66. data/test/plugin/test_filter_stdout.rb +18 -27
  67. data/test/plugin/test_in_dummy.rb +1 -1
  68. data/test/plugin/test_in_exec.rb +206 -94
  69. data/test/plugin/test_in_forward.rb +310 -327
  70. data/test/plugin/test_in_http.rb +310 -186
  71. data/test/plugin/test_out_exec.rb +223 -68
  72. data/test/plugin/test_out_exec_filter.rb +520 -169
  73. data/test/plugin/test_out_file.rb +620 -177
  74. data/test/plugin/test_out_forward.rb +110 -132
  75. data/test/plugin/test_out_null.rb +1 -1
  76. data/test/plugin/test_out_secondary_file.rb +4 -2
  77. data/test/plugin/test_out_stdout.rb +14 -35
  78. data/test/plugin/test_parser.rb +359 -0
  79. data/test/plugin/test_parser_csv.rb +1 -2
  80. data/test/plugin/test_parser_json.rb +3 -4
  81. data/test/plugin/test_parser_labeled_tsv.rb +1 -2
  82. data/test/plugin/test_parser_none.rb +1 -2
  83. data/test/plugin/test_parser_regexp.rb +8 -4
  84. data/test/plugin/test_parser_tsv.rb +4 -3
  85. data/test/plugin_helper/test_child_process.rb +184 -0
  86. data/test/plugin_helper/test_compat_parameters.rb +88 -1
  87. data/test/plugin_helper/test_extract.rb +0 -1
  88. data/test/plugin_helper/test_formatter.rb +5 -2
  89. data/test/plugin_helper/test_parser.rb +6 -5
  90. data/test/test_output.rb +24 -2
  91. data/test/test_plugin_classes.rb +20 -0
  92. data/test/test_root_agent.rb +139 -0
  93. data/test/test_test_drivers.rb +132 -0
  94. metadata +12 -4
  95. data/test/plugin/test_parser_base.rb +0 -32
@@ -250,7 +250,11 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
250
250
  ]
251
251
  filtered = filter(config)
252
252
  filtered.each do |t, r|
253
- assert_equal(Time.at(@time).localtime.to_s, r['message'])
253
+ if enable_ruby == "yes"
254
+ assert_equal(Time.at(@time).localtime, r['message'])
255
+ else
256
+ assert_equal(Time.at(@time).localtime.to_s, r['message'])
257
+ end
254
258
  end
255
259
  end
256
260
 
@@ -499,15 +503,19 @@ class RecordTransformerFilterTest < Test::Unit::TestCase
499
503
  }
500
504
  end
501
505
 
502
- test 'failed to expand (enable_ruby yes)' do
506
+ data(auto_typecast_yes: ["yes", "unknown['bar']"],
507
+ auto_typecast_no: ["no", "%Q[\#{unknown['bar']}]"])
508
+ test 'failed to expand (enable_ruby yes)' do |(param, expected_log)|
509
+
503
510
  config = %[
504
511
  enable_ruby yes
512
+ auto_typecast #{param}
505
513
  <record>
506
514
  message ${unknown['bar']}
507
515
  </record>
508
516
  ]
509
517
  filtered = filter(config) { |d|
510
- mock(d.instance.log).warn("failed to expand `%Q[\#{unknown['bar']}]`", anything)
518
+ mock(d.instance.log).warn("failed to expand `#{expected_log}`", anything)
511
519
  }
512
520
  filtered.each do |t, r|
513
521
  assert_nil(r['message'])
@@ -67,10 +67,9 @@ class StdoutFilterTest < Test::Unit::TestCase
67
67
 
68
68
  def test_output_type_json
69
69
  d = create_driver(CONFIG + config_element("", "", { "output_type" => "json" }))
70
- etime = event_time
71
- time = Time.at(etime.sec)
70
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
72
71
  out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
73
- assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out
72
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\":\"test\"}\n", out
74
73
 
75
74
  # NOTE: Float::NAN is not jsonable
76
75
  d = create_driver(CONFIG + config_element("", "", { "output_type" => "json" }))
@@ -80,15 +79,14 @@ class StdoutFilterTest < Test::Unit::TestCase
80
79
 
81
80
  def test_output_type_hash
82
81
  d = create_driver(CONFIG + config_element("", "", { "output_type" => "hash" }))
83
- etime = event_time
84
- time = Time.at(etime.sec)
82
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
85
83
  out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
86
- assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out
84
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>\"test\"}\n", out
87
85
 
88
86
  # NOTE: Float::NAN is not jsonable, but hash string can output it.
89
87
  d = create_driver(CONFIG + config_element("", "", { "output_type" => "hash" }))
90
88
  out = capture_log(d) { filter(d, etime, {'test' => Float::NAN}) }
91
- assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out
89
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>NaN}\n", out
92
90
  end
93
91
 
94
92
  # Use include_time_key to output the message's time
@@ -99,11 +97,9 @@ class StdoutFilterTest < Test::Unit::TestCase
99
97
  "localtime" => false
100
98
  })
101
99
  d = create_driver(config)
102
- etime = event_time
103
- time = Time.at(etime.sec)
104
- message_time = event_time("2011-01-02 13:14:15 UTC")
105
- out = capture_log(d) { filter(d, message_time, {'test' => 'test'}) }
106
- assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out
100
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
101
+ out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
102
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\":\"test\",\"time\":\"2016-10-07T21:09:31Z\"}\n", out
107
103
  end
108
104
 
109
105
  # out_stdout formatter itself can also be replaced
@@ -150,10 +146,9 @@ class StdoutFilterTest < Test::Unit::TestCase
150
146
  conf = config_element
151
147
  conf.elements << config_element("format", "", { "@type" => "stdout", "output_type" => "json" })
152
148
  d = create_driver(conf)
153
- etime = event_time
154
- time = Time.at(etime.sec)
149
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
155
150
  out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
156
- assert_equal "#{time.localtime} filter.test: {\"test\":\"test\"}\n", out
151
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\":\"test\"}\n", out
157
152
  end
158
153
 
159
154
  def test_json_nan
@@ -161,7 +156,7 @@ class StdoutFilterTest < Test::Unit::TestCase
161
156
  conf = config_element
162
157
  conf.elements << config_element("format", "", { "@type" => "stdout", "output_type" => "json" })
163
158
  d = create_driver(conf)
164
- etime = event_time
159
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
165
160
  flexmock(d.instance.router).should_receive(:emit_error_event)
166
161
  filter(d, etime, {'test' => Float::NAN})
167
162
  end
@@ -170,10 +165,9 @@ class StdoutFilterTest < Test::Unit::TestCase
170
165
  conf = config_element
171
166
  conf.elements << config_element("format", "", { "@type" => "stdout", "output_type" => "hash" })
172
167
  d = create_driver(conf)
173
- etime = event_time
174
- time = Time.at(etime.sec)
168
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
175
169
  out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
176
- assert_equal "#{time.localtime} filter.test: {\"test\"=>\"test\"}\n", out
170
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>\"test\"}\n", out
177
171
  end
178
172
 
179
173
  def test_hash_nan
@@ -181,10 +175,9 @@ class StdoutFilterTest < Test::Unit::TestCase
181
175
  conf = config_element
182
176
  conf.elements << config_element("format", "", { "@type" => "stdout", "output_type" => "hash" })
183
177
  d = create_driver(conf)
184
- etime = event_time
185
- time = Time.at(etime.sec)
178
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
186
179
  out = capture_log(d) { filter(d, etime, {'test' => Float::NAN}) }
187
- assert_equal "#{time.localtime} filter.test: {\"test\"=>NaN}\n", out
180
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\"=>NaN}\n", out
188
181
  end
189
182
 
190
183
  # Use include_time_key to output the message's time
@@ -200,11 +193,9 @@ class StdoutFilterTest < Test::Unit::TestCase
200
193
  "localtime" => false
201
194
  })
202
195
  d = create_driver(conf)
203
- etime = event_time
204
- time = Time.at(etime.sec)
205
- message_time = event_time("2011-01-02 13:14:15 UTC")
206
- out = capture_log(d) { filter(d, message_time, {'test' => 'test'}) }
207
- assert_equal "#{time.localtime} filter.test: {\"test\":\"test\",\"time\":\"2011-01-02T13:14:15Z\"}\n", out
196
+ etime = event_time("2016-10-07 21:09:31.012345678 UTC")
197
+ out = capture_log(d) { filter(d, etime, {'test' => 'test'}) }
198
+ assert_equal "2016-10-07 21:09:31.012345678 +0000 filter.test: {\"test\":\"test\",\"time\":\"2016-10-07T21:09:31Z\"}\n", out
208
199
  end
209
200
  end
210
201
  end
@@ -15,7 +15,7 @@ class DummyTest < Test::Unit::TestCase
15
15
  sub_test_case 'configure' do
16
16
  test 'required parameters' do
17
17
  assert_raise_message("'tag' parameter is required") do
18
- create_driver('')
18
+ Fluent::Plugin::DummyInput.new.configure(config_element('ROOT',''))
19
19
  end
20
20
  end
21
21
 
@@ -1,133 +1,245 @@
1
1
  require_relative '../helper'
2
2
  require 'fluent/test/driver/input'
3
3
  require 'fluent/plugin/in_exec'
4
- require 'net/http'
4
+ require 'timecop'
5
5
 
6
6
  class ExecInputTest < Test::Unit::TestCase
7
+ SCRIPT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb'))
8
+ TEST_TIME = "2011-01-02 13:14:15"
9
+ TEST_UNIX_TIME = Time.parse(TEST_TIME)
10
+
7
11
  def setup
8
12
  Fluent::Test.setup
9
- @test_time = event_time("2011-01-02 13:14:15")
10
- @script = File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts', 'exec_script.rb'))
13
+ @test_time = event_time()
11
14
  end
12
15
 
13
- def create_driver(conf = tsv_config)
16
+ def create_driver(conf)
14
17
  Fluent::Test::Driver::Input.new(Fluent::Plugin::ExecInput).configure(conf)
15
18
  end
16
19
 
17
- def tsv_config
18
- %[
19
- command ruby #{@script} "2011-01-02 13:14:15" 0
20
+ DEFAULT_CONFIG_ONLY_WITH_KEYS = %[
21
+ command ruby #{SCRIPT_PATH} "#{TEST_TIME}" 0
22
+ run_interval 1s
23
+ tag "my.test.data"
24
+ <parse>
25
+ keys ["k1", "k2", "k3"]
26
+ </parse>
27
+ ]
28
+
29
+ TSV_CONFIG = %[
30
+ command ruby #{SCRIPT_PATH} "#{TEST_TIME}" 0
31
+ run_interval 1s
32
+ <parse>
33
+ @type tsv
34
+ keys time, tag, k1
35
+ </parse>
36
+ <extract>
37
+ tag_key tag
38
+ time_key time
39
+ time_type string
40
+ time_format %Y-%m-%d %H:%M:%S
41
+ </extract>
42
+ ]
43
+
44
+ JSON_CONFIG = %[
45
+ command ruby #{SCRIPT_PATH} #{TEST_UNIX_TIME.to_i} 1
46
+ run_interval 1s
47
+ <parse>
48
+ @type json
49
+ </parse>
50
+ <extract>
51
+ tag_key tag
52
+ time_key time
53
+ time_type unixtime
54
+ </extract>
55
+ ]
56
+
57
+ MSGPACK_CONFIG = %[
58
+ command ruby #{SCRIPT_PATH} #{TEST_UNIX_TIME.to_i} 2
59
+ run_interval 1s
60
+ <parse>
61
+ @type msgpack
62
+ </parse>
63
+ <extract>
64
+ tag_key tagger
65
+ time_key datetime
66
+ time_type unixtime
67
+ </extract>
68
+ ]
69
+
70
+ # here document for not de-quoting backslashes
71
+ REGEXP_CONFIG = %[
72
+ command ruby #{SCRIPT_PATH} "#{TEST_TIME}" 3
73
+ run_interval 1s
74
+ tag regex_tag
75
+ ] + <<'EOC'
76
+ <parse>
77
+ @type regexp
78
+ expression "(?<time>[^\\]]*) (?<message>[^ ]*)"
79
+ time_key time
80
+ time_type string
81
+ time_format %Y-%m-%d %H:%M:%S
82
+ </parse>
83
+ EOC
84
+
85
+ sub_test_case 'with configuration with sections' do
86
+ test 'configure with default tsv format without extract' do
87
+ d = create_driver DEFAULT_CONFIG_ONLY_WITH_KEYS
88
+ assert{ d.instance.parser.is_a? Fluent::Plugin::TSVParser }
89
+ assert_equal "my.test.data", d.instance.tag
90
+ assert_equal ["k1", "k2", "k3"], d.instance.parser.keys
91
+ end
92
+
93
+ test 'configure raises error if both of tag and extract.tag_key are missing' do
94
+ assert_raise Fluent::ConfigError.new("'tag' or 'tag_key' option is required on exec input") do
95
+ create_driver %[
96
+ command ruby -e 'puts "yay"'
97
+ <parse>
98
+ keys y1
99
+ </parse>
100
+ ]
101
+ end
102
+ end
103
+
104
+ test 'configure for tsv' do
105
+ d = create_driver TSV_CONFIG
106
+ assert{ d.instance.parser.is_a? Fluent::Plugin::TSVParser }
107
+ assert_equal ["time", "tag", "k1"], d.instance.parser.keys
108
+ assert_equal "tag", d.instance.extract_config.tag_key
109
+ assert_equal "time", d.instance.extract_config.time_key
110
+ assert_equal :string, d.instance.extract_config.time_type
111
+ assert_equal "%Y-%m-%d %H:%M:%S", d.instance.extract_config.time_format
112
+ end
113
+
114
+ test 'configure for json' do
115
+ d = create_driver JSON_CONFIG
116
+ assert{ d.instance.parser.is_a? Fluent::Plugin::JSONParser }
117
+ assert_equal "tag", d.instance.extract_config.tag_key
118
+ assert_equal "time", d.instance.extract_config.time_key
119
+ assert_equal :unixtime, d.instance.extract_config.time_type
120
+ end
121
+
122
+ test 'configure for msgpack' do
123
+ d = create_driver MSGPACK_CONFIG
124
+ assert{ d.instance.parser.is_a? Fluent::Plugin::MessagePackParser }
125
+ assert_equal "tagger", d.instance.extract_config.tag_key
126
+ assert_equal "datetime", d.instance.extract_config.time_key
127
+ assert_equal :unixtime, d.instance.extract_config.time_type
128
+ end
129
+
130
+ test 'configure for regexp' do
131
+ d = create_driver REGEXP_CONFIG
132
+ assert{ d.instance.parser.is_a? Fluent::Plugin::RegexpParser }
133
+ assert_equal "regex_tag", d.instance.tag
134
+ expression = <<'EXP'.chomp
135
+ (?<time>[^\]]*) (?<message>[^ ]*)
136
+ EXP
137
+ assert_equal expression, d.instance.parser.expression
138
+ assert_nil d.instance.extract_config
139
+ end
140
+ end
141
+
142
+ TSV_CONFIG_COMPAT = %[
143
+ command ruby #{SCRIPT_PATH} "#{TEST_TIME}" 0
20
144
  keys time,tag,k1
21
145
  time_key time
22
146
  tag_key tag
23
147
  time_format %Y-%m-%d %H:%M:%S
24
148
  run_interval 1s
25
- ]
26
- end
149
+ ]
27
150
 
28
- def json_config
29
- %[
30
- command ruby #{@script} #{@test_time} 1
151
+ JSON_CONFIG_COMPAT = %[
152
+ command ruby #{SCRIPT_PATH} #{TEST_UNIX_TIME.to_i} 1
31
153
  format json
32
154
  tag_key tag
33
155
  time_key time
34
156
  run_interval 1s
35
- ]
36
- end
157
+ ]
37
158
 
38
- def msgpack_config
39
- %[
40
- command ruby #{@script} #{@test_time} 2
159
+ MSGPACK_CONFIG_COMPAT = %[
160
+ command ruby #{SCRIPT_PATH} #{TEST_UNIX_TIME.to_i} 2
41
161
  format msgpack
42
162
  tag_key tagger
43
163
  time_key datetime
44
164
  run_interval 1s
45
- ]
46
- end
165
+ ]
47
166
 
48
- def regexp_config
49
- %[
50
- command ruby #{@script} "2011-01-02 13:14:15" 3
167
+ REGEXP_CONFIG_COMPAT = %[
168
+ command ruby #{SCRIPT_PATH} "#{TEST_TIME}" 3
51
169
  format /(?<time>[^\\\]]*) (?<message>[^ ]*)/
52
170
  tag regex_tag
53
171
  run_interval 1s
54
- ]
55
- end
56
-
57
- def test_configure
58
- d = create_driver
59
- assert_equal 'tsv', d.instance.format
60
- assert_equal ["time","tag","k1"], d.instance.keys
61
- assert_equal "tag", d.instance.tag_key
62
- assert_equal "time", d.instance.time_key
63
- assert_equal "%Y-%m-%d %H:%M:%S", d.instance.time_format
64
- end
65
-
66
- def test_configure_with_json
67
- d = create_driver json_config
68
- assert_equal 'json', d.instance.format
69
- assert_equal [], d.instance.keys
70
- end
71
-
72
- def test_configure_with_msgpack
73
- d = create_driver msgpack_config
74
- assert_equal 'msgpack', d.instance.format
75
- assert_equal [], d.instance.keys
172
+ ]
173
+
174
+ sub_test_case 'with traditional configuration' do
175
+ test 'configure' do
176
+ d = create_driver TSV_CONFIG_COMPAT
177
+ assert{ d.instance.parser.is_a? Fluent::Plugin::TSVParser }
178
+ assert_equal ["time","tag","k1"], d.instance.parser.keys
179
+ assert_equal "tag", d.instance.extract_config.tag_key
180
+ assert_equal "time", d.instance.extract_config.time_key
181
+ assert_equal "%Y-%m-%d %H:%M:%S", d.instance.extract_config.time_format
182
+ end
183
+
184
+ test 'configure_with_json' do
185
+ d = create_driver JSON_CONFIG_COMPAT
186
+ assert{ d.instance.parser.is_a? Fluent::Plugin::JSONParser }
187
+ end
188
+
189
+ test 'configure_with_msgpack' do
190
+ d = create_driver MSGPACK_CONFIG_COMPAT
191
+ assert{ d.instance.parser.is_a? Fluent::Plugin::MessagePackParser }
192
+ end
193
+
194
+ test 'configure_with_regexp' do
195
+ d = create_driver REGEXP_CONFIG_COMPAT
196
+ assert{ d.instance.parser.is_a? Fluent::Plugin::RegexpParser }
197
+ assert_equal '(?<time>[^\]]*) (?<message>[^ ]*)', d.instance.parser.expression
198
+ assert_equal 'regex_tag', d.instance.tag
199
+ end
76
200
  end
77
201
 
78
- def test_configure_with_regexp
79
- d = create_driver regexp_config
80
- assert_equal '/(?<time>[^\]]*) (?<message>[^ ]*)/', d.instance.format
81
- assert_equal 'regex_tag', d.instance.tag
202
+ sub_test_case 'with default configuration' do
203
+ setup do
204
+ @current_event_time = event_time('2016-10-31 20:01:30.123 -0700')
205
+ Timecop.freeze(Time.at(@current_event_time))
206
+ end
207
+
208
+ teardown do
209
+ Timecop.return
210
+ end
211
+
212
+ test 'emits events with current timestamp if time key is not specified' do
213
+ d = create_driver DEFAULT_CONFIG_ONLY_WITH_KEYS
214
+ d.run(expect_records: 2, timeout: 10)
215
+
216
+ assert{ d.events.length > 0 }
217
+ d.events.each do |event|
218
+ assert_equal ["my.test.data", @current_event_time, {"k1"=>"2011-01-02 13:14:15", "k2"=>"tag1", "k3"=>"ok"}], event
219
+ end
220
+ end
82
221
  end
83
222
 
84
- # TODO: Merge following tests into one case with parameters
85
-
86
- def test_emit
87
- d = create_driver
88
-
89
- d.run(expect_emits: 2)
90
-
91
- assert_equal true, d.events.length > 0
92
- d.events.each_with_index {|event, i|
93
- assert_equal ["tag1", @test_time, {"k1"=>"ok"}], event
94
- assert_equal_event_time(@test_time, event[1])
95
- }
96
- end
97
-
98
- def test_emit_json
99
- d = create_driver json_config
100
-
101
- d.run(expect_emits: 2)
102
-
103
- assert_equal true, d.events.length > 0
104
- d.events.each_with_index {|event, i|
105
- assert_equal ["tag1", @test_time, {"k1"=>"ok"}], event
106
- assert_equal_event_time(@test_time, event[1])
107
- }
108
- end
109
-
110
- def test_emit_msgpack
111
- d = create_driver msgpack_config
112
-
113
- d.run(expect_emits: 2)
114
-
115
- assert_equal true, d.events.length > 0
116
- d.events.each_with_index {|event, i|
117
- assert_equal ["tag1", @test_time, {"k1"=>"ok"}], event
118
- assert_equal_event_time(@test_time, event[1])
119
- }
120
- end
121
-
122
- def test_emit_regexp
123
- d = create_driver regexp_config
124
-
125
- d.run(expect_emits: 2)
126
-
127
- assert_equal true, d.events.length > 0
223
+ data(
224
+ 'default' => [TSV_CONFIG, "tag1", event_time("2011-01-02 13:14:15"), {"k1"=>"ok"}],
225
+ 'json' => [JSON_CONFIG, "tag1", event_time("2011-01-02 13:14:15"), {"k1"=>"ok"}],
226
+ 'msgpack' => [MSGPACK_CONFIG, "tag1", event_time("2011-01-02 13:14:15"), {"k1"=>"ok"}],
227
+ 'regexp' => [REGEXP_CONFIG, "regex_tag", event_time("2011-01-02 13:14:15"), {"message"=>"hello"}],
228
+ 'default_c' => [TSV_CONFIG_COMPAT, "tag1", event_time("2011-01-02 13:14:15"), {"k1"=>"ok"}],
229
+ 'json_c' => [JSON_CONFIG_COMPAT, "tag1", event_time("2011-01-02 13:14:15"), {"k1"=>"ok"}],
230
+ 'msgpack_c' => [MSGPACK_CONFIG_COMPAT, "tag1", event_time("2011-01-02 13:14:15"), {"k1"=>"ok"}],
231
+ 'regexp_c' => [REGEXP_CONFIG_COMPAT, "regex_tag", event_time("2011-01-02 13:14:15"), {"message"=>"hello"}],
232
+ )
233
+ test 'emit with formats' do |data|
234
+ config, tag, time, record = data
235
+ d = create_driver(config)
236
+
237
+ d.run(expect_emits: 2, timeout: 10)
238
+
239
+ assert{ d.events.length > 0 }
128
240
  d.events.each_with_index {|event, i|
129
- assert_equal ["regex_tag", @test_time, {"message"=>"hello"}], event
130
- assert_equal_event_time(@test_time, event[1])
241
+ assert_equal_event_time(time, event[1])
242
+ assert_equal [tag, time, record], event
131
243
  }
132
244
  end
133
245
  end