fluentd 0.10.62 → 0.12.0.pre.1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.travis.yml +0 -4
- data/ChangeLog +0 -72
- data/Gemfile +0 -6
- data/Rakefile +12 -3
- data/example/in_http.conf +14 -0
- data/example/in_syslog.conf +15 -0
- data/example/in_tail.conf +14 -0
- data/example/in_tcp.conf +13 -0
- data/example/in_udp.conf +13 -0
- data/example/out_copy.conf +20 -0
- data/example/out_file.conf +13 -0
- data/example/out_forward.conf +30 -0
- data/fluent.conf +2 -12
- data/fluentd.gemspec +8 -11
- data/lib/fluent/agent.rb +180 -0
- data/lib/fluent/buffer.rb +6 -12
- data/lib/fluent/command/cat.rb +1 -3
- data/lib/fluent/command/debug.rb +1 -3
- data/lib/fluent/command/fluentd.rb +0 -10
- data/lib/fluent/config.rb +9 -3
- data/lib/fluent/config/basic_parser.rb +1 -6
- data/lib/fluent/config/configure_proxy.rb +25 -61
- data/lib/fluent/config/dsl.rb +16 -0
- data/lib/fluent/config/element.rb +21 -2
- data/lib/fluent/config/error.rb +16 -0
- data/lib/fluent/config/literal_parser.rb +9 -27
- data/lib/fluent/config/parser.rb +16 -0
- data/lib/fluent/config/section.rb +16 -2
- data/lib/fluent/config/types.rb +16 -1
- data/lib/fluent/config/v1_parser.rb +4 -12
- data/lib/fluent/configurable.rb +16 -0
- data/lib/fluent/engine.rb +43 -163
- data/lib/fluent/env.rb +16 -1
- data/lib/fluent/event.rb +20 -48
- data/lib/fluent/event_router.rb +187 -0
- data/lib/fluent/filter.rb +32 -0
- data/lib/fluent/formatter.rb +29 -101
- data/lib/fluent/input.rb +6 -4
- data/lib/fluent/label.rb +18 -0
- data/lib/fluent/load.rb +1 -3
- data/lib/fluent/log.rb +1 -3
- data/lib/fluent/match.rb +12 -19
- data/lib/fluent/mixin.rb +9 -25
- data/lib/fluent/output.rb +27 -45
- data/lib/fluent/parser.rb +93 -99
- data/lib/fluent/plugin.rb +22 -48
- data/lib/fluent/plugin/buf_file.rb +10 -7
- data/lib/fluent/plugin/buf_memory.rb +2 -3
- data/lib/fluent/plugin/buf_zfile.rb +75 -0
- data/lib/fluent/plugin/exec_util.rb +16 -0
- data/lib/fluent/plugin/in_debug_agent.rb +2 -3
- data/lib/fluent/plugin/in_exec.rb +2 -9
- data/lib/fluent/plugin/in_forward.rb +4 -22
- data/lib/fluent/plugin/in_gc_stat.rb +2 -3
- data/lib/fluent/plugin/in_http.rb +19 -59
- data/lib/fluent/plugin/in_monitor_agent.rb +21 -47
- data/lib/fluent/plugin/in_object_space.rb +2 -3
- data/lib/fluent/plugin/in_status.rb +2 -3
- data/lib/fluent/plugin/in_stream.rb +6 -16
- data/lib/fluent/plugin/in_syslog.rb +8 -17
- data/lib/fluent/plugin/in_tail.rb +17 -24
- data/lib/fluent/plugin/in_tcp.rb +16 -0
- data/lib/fluent/plugin/in_udp.rb +16 -0
- data/lib/fluent/plugin/out_copy.rb +3 -4
- data/lib/fluent/plugin/out_exec.rb +2 -4
- data/lib/fluent/plugin/out_exec_filter.rb +2 -13
- data/lib/fluent/plugin/out_file.rb +5 -6
- data/lib/fluent/plugin/out_forward.rb +4 -5
- data/lib/fluent/plugin/out_null.rb +2 -3
- data/lib/fluent/plugin/out_relabel.rb +26 -0
- data/lib/fluent/plugin/out_roundrobin.rb +3 -4
- data/lib/fluent/plugin/out_stdout.rb +2 -3
- data/lib/fluent/plugin/out_stream.rb +2 -3
- data/{test/scripts → lib}/fluent/plugin/out_test.rb +2 -3
- data/lib/fluent/plugin/socket_util.rb +19 -10
- data/lib/fluent/process.rb +4 -6
- data/lib/fluent/registry.rb +16 -0
- data/lib/fluent/root_agent.rb +212 -0
- data/lib/fluent/status.rb +2 -3
- data/lib/fluent/supervisor.rb +33 -54
- data/lib/fluent/test.rb +16 -0
- data/lib/fluent/test/base.rb +3 -17
- data/lib/fluent/test/input_test.rb +52 -7
- data/lib/fluent/test/output_test.rb +4 -20
- data/lib/fluent/version.rb +17 -1
- data/spec/config/config_parser_spec.rb +314 -0
- data/spec/config/configurable_spec.rb +524 -0
- data/spec/config/configure_proxy_spec.rb +96 -0
- data/spec/config/dsl_spec.rb +239 -0
- data/spec/config/helper.rb +49 -0
- data/spec/config/literal_parser_spec.rb +222 -0
- data/spec/config/section_spec.rb +97 -0
- data/spec/config/system_config_spec.rb +49 -0
- data/test/helper.rb +0 -25
- data/test/plugin/test_in_exec.rb +1 -1
- data/test/plugin/test_in_forward.rb +2 -1
- data/test/plugin/test_in_gc_stat.rb +1 -1
- data/test/plugin/test_in_http.rb +3 -78
- data/test/plugin/test_in_object_space.rb +1 -1
- data/test/plugin/test_in_status.rb +1 -1
- data/test/plugin/test_in_stream.rb +2 -1
- data/test/plugin/test_in_syslog.rb +2 -1
- data/test/plugin/test_in_tail.rb +6 -11
- data/test/plugin/test_in_tcp.rb +2 -1
- data/test/plugin/test_in_udp.rb +2 -1
- data/test/plugin/test_out_copy.rb +1 -12
- data/test/plugin/test_out_exec.rb +1 -1
- data/test/plugin/test_out_exec_filter.rb +1 -1
- data/test/plugin/test_out_file.rb +7 -96
- data/test/plugin/test_out_forward.rb +2 -1
- data/test/plugin/test_out_roundrobin.rb +1 -12
- data/test/plugin/test_out_stdout.rb +1 -1
- data/test/plugin/test_out_stream.rb +2 -1
- data/test/scripts/fluent/plugin/formatter_known.rb +1 -4
- data/test/scripts/fluent/plugin/parser_known.rb +1 -2
- data/test/test_config.rb +1 -1
- data/test/test_configdsl.rb +2 -1
- data/test/test_formatter.rb +3 -395
- data/test/test_match.rb +2 -1
- data/test/test_mixin.rb +3 -75
- data/test/test_output.rb +1 -112
- data/test/test_parser.rb +85 -152
- metadata +58 -167
- data/example/v1_literal_example.conf +0 -36
- data/lib/fluent/plugin/in_dummy.rb +0 -103
- data/lib/fluent/timezone.rb +0 -131
- data/test/config/assertions.rb +0 -42
- data/test/config/test_config_parser.rb +0 -389
- data/test/config/test_configurable.rb +0 -652
- data/test/config/test_configure_proxy.rb +0 -99
- data/test/config/test_dsl.rb +0 -237
- data/test/config/test_literal_parser.rb +0 -295
- data/test/config/test_section.rb +0 -112
- data/test/config/test_system_config.rb +0 -99
- data/test/config/test_types.rb +0 -63
- data/test/plugin/test_in_dummy.rb +0 -95
- data/test/test_event.rb +0 -168
- data/test/test_input.rb +0 -21
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative '../helper'
|
2
1
|
require 'fluent/test'
|
3
2
|
require 'fileutils'
|
4
3
|
require 'time'
|
@@ -64,41 +63,6 @@ class FileOutputTest < Test::Unit::TestCase
|
|
64
63
|
d.run
|
65
64
|
end
|
66
65
|
|
67
|
-
def test_timezone_1
|
68
|
-
d = create_driver %[
|
69
|
-
path #{TMP_DIR}/out_file_test
|
70
|
-
timezone Asia/Taipei
|
71
|
-
]
|
72
|
-
|
73
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
74
|
-
|
75
|
-
d.emit({"a"=>1}, time)
|
76
|
-
d.expect_format %[2011-01-02T21:14:15+08:00\ttest\t{"a":1}\n]
|
77
|
-
d.run
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_timezone_2
|
81
|
-
d = create_driver %[
|
82
|
-
path #{TMP_DIR}/out_file_test
|
83
|
-
timezone -03:30
|
84
|
-
]
|
85
|
-
|
86
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
87
|
-
|
88
|
-
d.emit({"a"=>1}, time)
|
89
|
-
d.expect_format %[2011-01-02T09:44:15-03:30\ttest\t{"a":1}\n]
|
90
|
-
d.run
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_timezone_invalid
|
94
|
-
assert_raise(Fluent::ConfigError) do
|
95
|
-
create_driver %[
|
96
|
-
path #{TMP_DIR}/out_file_test
|
97
|
-
timezone Invalid/Invalid
|
98
|
-
]
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
66
|
def check_gzipped_result(path, expect)
|
103
67
|
# Zlib::GzipReader has a bug of concatenated file: https://bugs.ruby-lang.org/issues/9790
|
104
68
|
# Following code from https://www.ruby-forum.com/topic/971591#979520
|
@@ -126,7 +90,7 @@ class FileOutputTest < Test::Unit::TestCase
|
|
126
90
|
|
127
91
|
# FileOutput#write returns path
|
128
92
|
path = d.run
|
129
|
-
expect_path = "#{TMP_DIR}/out_file_test.
|
93
|
+
expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
|
130
94
|
assert_equal expect_path, path
|
131
95
|
|
132
96
|
check_gzipped_result(path, %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] + %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n])
|
@@ -178,13 +142,13 @@ class FileOutputTest < Test::Unit::TestCase
|
|
178
142
|
|
179
143
|
# FileOutput#write returns path
|
180
144
|
path = d.run
|
181
|
-
assert_equal "#{TMP_DIR}/out_file_test.
|
145
|
+
assert_equal "#{TMP_DIR}/out_file_test._0.log.gz", path
|
182
146
|
check_gzipped_result(path, formatted_lines)
|
183
147
|
path = d.run
|
184
|
-
assert_equal "#{TMP_DIR}/out_file_test.
|
148
|
+
assert_equal "#{TMP_DIR}/out_file_test._1.log.gz", path
|
185
149
|
check_gzipped_result(path, formatted_lines)
|
186
150
|
path = d.run
|
187
|
-
assert_equal "#{TMP_DIR}/out_file_test.
|
151
|
+
assert_equal "#{TMP_DIR}/out_file_test._2.log.gz", path
|
188
152
|
check_gzipped_result(path, formatted_lines)
|
189
153
|
end
|
190
154
|
|
@@ -203,13 +167,13 @@ class FileOutputTest < Test::Unit::TestCase
|
|
203
167
|
|
204
168
|
# FileOutput#write returns path
|
205
169
|
path = d.run
|
206
|
-
assert_equal "#{TMP_DIR}/out_file_test
|
170
|
+
assert_equal "#{TMP_DIR}/out_file_test..log.gz", path
|
207
171
|
check_gzipped_result(path, formatted_lines)
|
208
172
|
path = d.run
|
209
|
-
assert_equal "#{TMP_DIR}/out_file_test
|
173
|
+
assert_equal "#{TMP_DIR}/out_file_test..log.gz", path
|
210
174
|
check_gzipped_result(path, formatted_lines * 2)
|
211
175
|
path = d.run
|
212
|
-
assert_equal "#{TMP_DIR}/out_file_test
|
176
|
+
assert_equal "#{TMP_DIR}/out_file_test..log.gz", path
|
213
177
|
check_gzipped_result(path, formatted_lines * 3)
|
214
178
|
end
|
215
179
|
|
@@ -241,58 +205,5 @@ class FileOutputTest < Test::Unit::TestCase
|
|
241
205
|
FileUtils.rm_rf(symlink_path)
|
242
206
|
end
|
243
207
|
end
|
244
|
-
|
245
|
-
sub_test_case 'path' do
|
246
|
-
test 'normal' do
|
247
|
-
d = create_driver(%[
|
248
|
-
path #{TMP_DIR}/out_file_test
|
249
|
-
time_slice_format %Y-%m-%d-%H
|
250
|
-
utc true
|
251
|
-
])
|
252
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
253
|
-
d.emit({"a"=>1}, time)
|
254
|
-
# FileOutput#write returns path
|
255
|
-
path = d.run
|
256
|
-
assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13_0.log", path
|
257
|
-
end
|
258
|
-
|
259
|
-
test 'normal with append' do
|
260
|
-
d = create_driver(%[
|
261
|
-
path #{TMP_DIR}/out_file_test
|
262
|
-
time_slice_format %Y-%m-%d-%H
|
263
|
-
utc true
|
264
|
-
append true
|
265
|
-
])
|
266
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
267
|
-
d.emit({"a"=>1}, time)
|
268
|
-
path = d.run
|
269
|
-
assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13.log", path
|
270
|
-
end
|
271
|
-
|
272
|
-
test '*' do
|
273
|
-
d = create_driver(%[
|
274
|
-
path #{TMP_DIR}/out_file_test.*.txt
|
275
|
-
time_slice_format %Y-%m-%d-%H
|
276
|
-
utc true
|
277
|
-
])
|
278
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
279
|
-
d.emit({"a"=>1}, time)
|
280
|
-
path = d.run
|
281
|
-
assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13_0.txt", path
|
282
|
-
end
|
283
|
-
|
284
|
-
test '* with append' do
|
285
|
-
d = create_driver(%[
|
286
|
-
path #{TMP_DIR}/out_file_test.*.txt
|
287
|
-
time_slice_format %Y-%m-%d-%H
|
288
|
-
utc true
|
289
|
-
append true
|
290
|
-
])
|
291
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
292
|
-
d.emit({"a"=>1}, time)
|
293
|
-
path = d.run
|
294
|
-
assert_equal "#{TMP_DIR}/out_file_test.2011-01-02-13.txt", path
|
295
|
-
end
|
296
|
-
end
|
297
208
|
end
|
298
209
|
|
@@ -1,17 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'fluent/test'
|
2
2
|
|
3
3
|
class RoundRobinOutputTest < Test::Unit::TestCase
|
4
|
-
class << self
|
5
|
-
def startup
|
6
|
-
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'scripts'))
|
7
|
-
require 'fluent/plugin/out_test'
|
8
|
-
end
|
9
|
-
|
10
|
-
def shutdown
|
11
|
-
$LOAD_PATH.shift
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
4
|
def setup
|
16
5
|
Fluent::Test.setup
|
17
6
|
end
|
@@ -1,8 +1,5 @@
|
|
1
1
|
module Fluent
|
2
|
-
TextFormatter.register_template('
|
3
|
-
"#{tag}:#{time}:#{record.size}"
|
4
|
-
})
|
5
|
-
Plugin.register_formatter('known', Proc.new { |tag, time, record|
|
2
|
+
TextFormatter.register_template('known', Proc.new { |tag, time, record|
|
6
3
|
"#{tag}:#{time}:#{record.size}"
|
7
4
|
})
|
8
5
|
end
|
data/test/test_config.rb
CHANGED
data/test/test_configdsl.rb
CHANGED
data/test/test_formatter.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'helper'
|
2
2
|
require 'fluent/test'
|
3
3
|
require 'fluent/formatter'
|
4
4
|
|
@@ -29,25 +29,6 @@ module FormatterTest
|
|
29
29
|
{'message' => 'awesome'}
|
30
30
|
end
|
31
31
|
|
32
|
-
def with_timezone(tz)
|
33
|
-
oldtz, ENV['TZ'] = ENV['TZ'], tz
|
34
|
-
yield
|
35
|
-
ensure
|
36
|
-
ENV['TZ'] = oldtz
|
37
|
-
end
|
38
|
-
|
39
|
-
class BaseFormatterTest < ::Test::Unit::TestCase
|
40
|
-
include FormatterTest
|
41
|
-
|
42
|
-
def test_call
|
43
|
-
formatter = Formatter.new
|
44
|
-
formatter.configure({})
|
45
|
-
assert_raise NotImplementedError do
|
46
|
-
formatter.format('tag', Engine.now, {})
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
32
|
class OutFileFormatterTest < ::Test::Unit::TestCase
|
52
33
|
include FormatterTest
|
53
34
|
|
@@ -132,49 +113,6 @@ module FormatterTest
|
|
132
113
|
end
|
133
114
|
end
|
134
115
|
|
135
|
-
class MessagePackFormatterTest < ::Test::Unit::TestCase
|
136
|
-
include FormatterTest
|
137
|
-
|
138
|
-
def setup
|
139
|
-
@formatter = TextFormatter::MessagePackFormatter.new
|
140
|
-
@time = Engine.now
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_format
|
144
|
-
@formatter.configure({})
|
145
|
-
formatted = @formatter.format(tag, @time, record)
|
146
|
-
|
147
|
-
assert_equal(record.to_msgpack, formatted)
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_format_with_include_tag
|
151
|
-
@formatter.configure('include_tag_key' => 'true', 'tag_key' => 'foo')
|
152
|
-
formatted = @formatter.format(tag, @time, record.dup)
|
153
|
-
|
154
|
-
r = record
|
155
|
-
r['foo'] = tag
|
156
|
-
assert_equal(r.to_msgpack, formatted)
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_format_with_include_time
|
160
|
-
@formatter.configure('include_time_key' => 'true', 'localtime' => '')
|
161
|
-
formatted = @formatter.format(tag, @time, record.dup)
|
162
|
-
|
163
|
-
r = record
|
164
|
-
r['time'] = time2str(@time, true)
|
165
|
-
assert_equal(r.to_msgpack, formatted)
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_format_with_include_time_as_number
|
169
|
-
@formatter.configure('include_time_key' => 'true', 'time_as_epoch' => 'true', 'time_key' => 'epoch')
|
170
|
-
formatted = @formatter.format(tag, @time, record.dup)
|
171
|
-
|
172
|
-
r = record
|
173
|
-
r['epoch'] = @time
|
174
|
-
assert_equal(r.to_msgpack, formatted)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
116
|
class LabeledTSVFormatterTest < ::Test::Unit::TestCase
|
179
117
|
include FormatterTest
|
180
118
|
|
@@ -229,118 +167,6 @@ module FormatterTest
|
|
229
167
|
end
|
230
168
|
end
|
231
169
|
|
232
|
-
class CsvFormatterTest < ::Test::Unit::TestCase
|
233
|
-
include FormatterTest
|
234
|
-
|
235
|
-
def setup
|
236
|
-
@formatter = TextFormatter::CsvFormatter.new
|
237
|
-
@time = Engine.now
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_config_params
|
241
|
-
assert_equal ',', @formatter.delimiter
|
242
|
-
assert_equal true, @formatter.force_quotes
|
243
|
-
assert_equal [], @formatter.fields
|
244
|
-
end
|
245
|
-
|
246
|
-
data(
|
247
|
-
'tab_char' => ["\t", '\t'],
|
248
|
-
'tab_string' => ["\t", 'TAB'],
|
249
|
-
'pipe' => ['|', '|'])
|
250
|
-
def test_config_params_with_customized_delimiters(data)
|
251
|
-
expected, target = data
|
252
|
-
@formatter.configure('delimiter' => target)
|
253
|
-
assert_equal expected, @formatter.delimiter
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_format
|
257
|
-
@formatter.configure('fields' => 'message,message2')
|
258
|
-
formatted = @formatter.format(tag, @time, {
|
259
|
-
'message' => 'awesome',
|
260
|
-
'message2' => 'awesome2'
|
261
|
-
})
|
262
|
-
assert_equal("\"awesome\",\"awesome2\"\n", formatted)
|
263
|
-
end
|
264
|
-
|
265
|
-
def test_format_with_tag
|
266
|
-
@formatter.configure(
|
267
|
-
'fields' => 'tag,message,message2',
|
268
|
-
'include_tag_key' => 'true'
|
269
|
-
)
|
270
|
-
formatted = @formatter.format(tag, @time, {
|
271
|
-
'message' => 'awesome',
|
272
|
-
'message2' => 'awesome2'
|
273
|
-
})
|
274
|
-
assert_equal("\"tag\",\"awesome\",\"awesome2\"\n", formatted)
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_format_with_time
|
278
|
-
@formatter.configure(
|
279
|
-
'fields' => 'time,message,message2',
|
280
|
-
'include_time_key' => 'true',
|
281
|
-
'time_format' => '%Y'
|
282
|
-
)
|
283
|
-
formatted = @formatter.format(tag, @time, {
|
284
|
-
'message' => 'awesome',
|
285
|
-
'message2' => 'awesome2'
|
286
|
-
})
|
287
|
-
assert_equal("\"#{Time.now.year}\",\"awesome\",\"awesome2\"\n",
|
288
|
-
formatted)
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_format_with_customized_delimiters
|
292
|
-
@formatter.configure(
|
293
|
-
'fields' => 'message,message2',
|
294
|
-
'delimiter' => '\t'
|
295
|
-
)
|
296
|
-
formatted = @formatter.format(tag, @time, {
|
297
|
-
'message' => 'awesome',
|
298
|
-
'message2' => 'awesome2'
|
299
|
-
})
|
300
|
-
assert_equal("\"awesome\"\t\"awesome2\"\n", formatted)
|
301
|
-
end
|
302
|
-
|
303
|
-
def test_format_with_non_quote
|
304
|
-
@formatter.configure(
|
305
|
-
'fields' => 'message,message2',
|
306
|
-
'force_quotes' => 'false'
|
307
|
-
)
|
308
|
-
formatted = @formatter.format(tag, @time, {
|
309
|
-
'message' => 'awesome',
|
310
|
-
'message2' => 'awesome2'
|
311
|
-
})
|
312
|
-
assert_equal("awesome,awesome2\n", formatted)
|
313
|
-
end
|
314
|
-
|
315
|
-
data(
|
316
|
-
'nil' => {
|
317
|
-
'message' => 'awesome',
|
318
|
-
'message2' => nil,
|
319
|
-
'message3' => 'awesome3'
|
320
|
-
},
|
321
|
-
'blank' => {
|
322
|
-
'message' => 'awesome',
|
323
|
-
'message2' => '',
|
324
|
-
'message3' => 'awesome3'
|
325
|
-
})
|
326
|
-
def test_format_with_empty_fields(data)
|
327
|
-
@formatter.configure(
|
328
|
-
'fields' => 'message,message2,message3'
|
329
|
-
)
|
330
|
-
formatted = @formatter.format(tag, @time, data)
|
331
|
-
assert_equal("\"awesome\",\"\",\"awesome3\"\n", formatted)
|
332
|
-
end
|
333
|
-
|
334
|
-
data(
|
335
|
-
'normally' => 'one,two,three',
|
336
|
-
'white_space' => 'one , two , three',
|
337
|
-
'blank' => 'one,,two,three')
|
338
|
-
def test_config_params_with_fields(data)
|
339
|
-
@formatter.configure('fields' => data)
|
340
|
-
assert_equal %w(one two three), @formatter.fields
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
170
|
class SingleValueFormatterTest < ::Test::Unit::TestCase
|
345
171
|
include FormatterTest
|
346
172
|
|
@@ -383,228 +209,10 @@ module FormatterTest
|
|
383
209
|
end
|
384
210
|
end
|
385
211
|
|
386
|
-
|
387
|
-
def test_find_formatter(data)
|
212
|
+
def test_find_formatter
|
388
213
|
$LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), 'scripts'))
|
389
214
|
assert_nothing_raised ConfigError do
|
390
|
-
TextFormatter::TEMPLATE_REGISTRY.lookup(
|
391
|
-
end
|
392
|
-
$LOAD_PATH.shift
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
class TimeFormatterTest < ::Test::Unit::TestCase
|
397
|
-
include FormatterTest
|
398
|
-
|
399
|
-
def setup
|
400
|
-
@time = Time.new(2014, 9, 27, 0, 0, 0, 0).to_i
|
401
|
-
@fmt = "%Y%m%d %H%M%z" # YYYYMMDD HHMM[+-]HHMM
|
402
|
-
end
|
403
|
-
|
404
|
-
def format(format, localtime, timezone)
|
405
|
-
formatter = Fluent::TimeFormatter.new(format, localtime, timezone)
|
406
|
-
formatter.format(@time)
|
407
|
-
end
|
408
|
-
|
409
|
-
def test_default_utc_nil
|
410
|
-
assert_equal("2014-09-27T00:00:00Z", format(nil, false, nil))
|
411
|
-
end
|
412
|
-
|
413
|
-
def test_default_utc_pHH_MM
|
414
|
-
assert_equal("2014-09-27T01:30:00+01:30", format(nil, false, "+01:30"))
|
415
|
-
end
|
416
|
-
|
417
|
-
def test_default_utc_nHH_MM
|
418
|
-
assert_equal("2014-09-26T22:30:00-01:30", format(nil, false, "-01:30"))
|
419
|
-
end
|
420
|
-
|
421
|
-
def test_default_utc_pHHMM
|
422
|
-
assert_equal("2014-09-27T02:30:00+02:30", format(nil, false, "+0230"))
|
423
|
-
end
|
424
|
-
|
425
|
-
def test_default_utc_nHHMM
|
426
|
-
assert_equal("2014-09-26T21:30:00-02:30", format(nil, false, "-0230"))
|
427
|
-
end
|
428
|
-
|
429
|
-
def test_default_utc_pHH
|
430
|
-
assert_equal("2014-09-27T03:00:00+03:00", format(nil, false, "+03"))
|
431
|
-
end
|
432
|
-
|
433
|
-
def test_default_utc_nHH
|
434
|
-
assert_equal("2014-09-26T21:00:00-03:00", format(nil, false, "-03"))
|
435
|
-
end
|
436
|
-
|
437
|
-
def test_default_utc_timezone_1
|
438
|
-
# Asia/Tokyo (+09:00) does not have daylight saving time.
|
439
|
-
assert_equal("2014-09-27T09:00:00+09:00", format(nil, false, "Asia/Tokyo"))
|
440
|
-
end
|
441
|
-
|
442
|
-
def test_default_utc_timezone_2
|
443
|
-
# Pacific/Honolulu (-10:00) does not have daylight saving time.
|
444
|
-
assert_equal("2014-09-26T14:00:00-10:00", format(nil, false, "Pacific/Honolulu"))
|
445
|
-
end
|
446
|
-
|
447
|
-
def test_default_utc_timezone_3
|
448
|
-
# America/Argentina/Buenos_Aires (-03:00) does not have daylight saving time.
|
449
|
-
assert_equal("2014-09-26T21:00:00-03:00", format(nil, false, "America/Argentina/Buenos_Aires"))
|
450
|
-
end
|
451
|
-
|
452
|
-
def test_default_utc_timezone_4
|
453
|
-
# Europe/Paris has daylight saving time. Its UTC offset is +01:00 and its
|
454
|
-
# UTC offset in DST is +02:00. In September, Europe/Paris is in DST.
|
455
|
-
assert_equal("2014-09-27T02:00:00+02:00", format(nil, false, "Europe/Paris"))
|
456
|
-
end
|
457
|
-
|
458
|
-
def test_default_utc_timezone_5
|
459
|
-
# Europe/Paris has daylight saving time. Its UTC offset is +01:00 and its
|
460
|
-
# UTC offset in DST is +02:00. In January, Europe/Paris is not in DST.
|
461
|
-
@time = Time.new(2014, 1, 24, 0, 0, 0, 0).to_i
|
462
|
-
assert_equal("2014-01-24T01:00:00+01:00", format(nil, false, "Europe/Paris"))
|
463
|
-
end
|
464
|
-
|
465
|
-
def test_default_utc_invalid
|
466
|
-
assert_equal("2014-09-27T00:00:00Z", format(nil, false, "Invalid"))
|
467
|
-
end
|
468
|
-
|
469
|
-
def test_default_localtime_nil_1
|
470
|
-
with_timezone("UTC-04") do
|
471
|
-
assert_equal("2014-09-27T04:00:00+04:00", format(nil, true, nil))
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
def test_default_localtime_nil_2
|
476
|
-
with_timezone("UTC+05") do
|
477
|
-
assert_equal("2014-09-26T19:00:00-05:00", format(nil, true, nil))
|
478
|
-
end
|
479
|
-
end
|
480
|
-
|
481
|
-
def test_default_localtime_timezone
|
482
|
-
# 'timezone' takes precedence over 'localtime'.
|
483
|
-
with_timezone("UTC-06") do
|
484
|
-
assert_equal("2014-09-27T07:00:00+07:00", format(nil, true, "+07"))
|
485
|
-
end
|
486
|
-
end
|
487
|
-
|
488
|
-
def test_specific_utc_nil
|
489
|
-
assert_equal("20140927 0000+0000", format(@fmt, false, nil))
|
490
|
-
end
|
491
|
-
|
492
|
-
def test_specific_utc_pHH_MM
|
493
|
-
assert_equal("20140927 0830+0830", format(@fmt, false, "+08:30"))
|
494
|
-
end
|
495
|
-
|
496
|
-
def test_specific_utc_nHH_MM
|
497
|
-
assert_equal("20140926 1430-0930", format(@fmt, false, "-09:30"))
|
498
|
-
end
|
499
|
-
|
500
|
-
def test_specific_utc_pHHMM
|
501
|
-
assert_equal("20140927 1030+1030", format(@fmt, false, "+1030"))
|
502
|
-
end
|
503
|
-
|
504
|
-
def test_specific_utc_nHHMM
|
505
|
-
assert_equal("20140926 1230-1130", format(@fmt, false, "-1130"))
|
506
|
-
end
|
507
|
-
|
508
|
-
def test_specific_utc_pHH
|
509
|
-
assert_equal("20140927 1200+1200", format(@fmt, false, "+12"))
|
510
|
-
end
|
511
|
-
|
512
|
-
def test_specific_utc_nHH
|
513
|
-
assert_equal("20140926 1100-1300", format(@fmt, false, "-13"))
|
514
|
-
end
|
515
|
-
|
516
|
-
def test_specific_utc_timezone_1
|
517
|
-
# Europe/Moscow (+04:00) does not have daylight saving time.
|
518
|
-
assert_equal("20140927 0400+0400", format(@fmt, false, "Europe/Moscow"))
|
519
|
-
end
|
520
|
-
|
521
|
-
def test_specific_utc_timezone_2
|
522
|
-
# Pacific/Galapagos (-06:00) does not have daylight saving time.
|
523
|
-
assert_equal("20140926 1800-0600", format(@fmt, false, "Pacific/Galapagos"))
|
524
|
-
end
|
525
|
-
|
526
|
-
def test_specific_utc_timezone_3
|
527
|
-
# America/Argentina/Buenos_Aires (-03:00) does not have daylight saving time.
|
528
|
-
assert_equal("20140926 2100-0300", format(@fmt, false, "America/Argentina/Buenos_Aires"))
|
529
|
-
end
|
530
|
-
|
531
|
-
def test_specific_utc_timezone_4
|
532
|
-
# America/Los_Angeles has daylight saving time. Its UTC offset is -08:00 and its
|
533
|
-
# UTC offset in DST is -07:00. In September, America/Los_Angeles is in DST.
|
534
|
-
assert_equal("20140926 1700-0700", format(@fmt, false, "America/Los_Angeles"))
|
535
|
-
end
|
536
|
-
|
537
|
-
def test_specific_utc_timezone_5
|
538
|
-
# America/Los_Angeles has daylight saving time. Its UTC offset is -08:00 and its
|
539
|
-
# UTC offset in DST is -07:00. In January, America/Los_Angeles is not in DST.
|
540
|
-
@time = Time.new(2014, 1, 24, 0, 0, 0, 0).to_i
|
541
|
-
assert_equal("20140123 1600-0800", format(@fmt, false, "America/Los_Angeles"))
|
542
|
-
end
|
543
|
-
|
544
|
-
def test_specific_utc_invalid
|
545
|
-
assert_equal("20140927 0000+0000", format(@fmt, false, "Invalid"))
|
546
|
-
end
|
547
|
-
|
548
|
-
def test_specific_localtime_nil_1
|
549
|
-
with_timezone("UTC-07") do
|
550
|
-
assert_equal("20140927 0700+0700", format(@fmt, true, nil))
|
551
|
-
end
|
552
|
-
end
|
553
|
-
|
554
|
-
def test_specific_localtime_nil_2
|
555
|
-
with_timezone("UTC+08") do
|
556
|
-
assert_equal("20140926 1600-0800", format(@fmt, true, nil))
|
557
|
-
end
|
558
|
-
end
|
559
|
-
|
560
|
-
def test_specific_localtime_timezone
|
561
|
-
# 'timezone' takes precedence over 'localtime'.
|
562
|
-
with_timezone("UTC-09") do
|
563
|
-
assert_equal("20140926 1400-1000", format(@fmt, true, "-10"))
|
564
|
-
end
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
class TimeConfigTest < ::Test::Unit::TestCase
|
569
|
-
include FormatterTest
|
570
|
-
|
571
|
-
def setup
|
572
|
-
@formatter = TextFormatter::LabeledTSVFormatter.new
|
573
|
-
@time = Time.new(2014, 9, 27, 0, 0, 0, 0).to_i
|
574
|
-
end
|
575
|
-
|
576
|
-
def format(conf)
|
577
|
-
@formatter.configure({'include_time_key' => true}.merge(conf))
|
578
|
-
formatted = @formatter.format("tag", @time, {})
|
579
|
-
# Drop the leading "time:" and the trailing "\n".
|
580
|
-
formatted[5..-2]
|
581
|
-
end
|
582
|
-
|
583
|
-
def test_none
|
584
|
-
with_timezone("UTC-01") do
|
585
|
-
# 'localtime' is true by default.
|
586
|
-
assert_equal("2014-09-27T01:00:00+01:00", format({}))
|
587
|
-
end
|
588
|
-
end
|
589
|
-
|
590
|
-
def test_utc
|
591
|
-
with_timezone("UTC-01") do
|
592
|
-
# 'utc' takes precedence over 'localtime'.
|
593
|
-
assert_equal("2014-09-27T00:00:00Z", format("utc" => true))
|
594
|
-
end
|
595
|
-
end
|
596
|
-
|
597
|
-
def test_timezone
|
598
|
-
with_timezone("UTC-01") do
|
599
|
-
# 'timezone' takes precedence over 'localtime'.
|
600
|
-
assert_equal("2014-09-27T02:00:00+02:00", format("timezone" => "+02"))
|
601
|
-
end
|
602
|
-
end
|
603
|
-
|
604
|
-
def test_utc_timezone
|
605
|
-
with_timezone("UTC-01") do
|
606
|
-
# 'timezone' takes precedence over 'utc'.
|
607
|
-
assert_equal("2014-09-27T09:00:00+09:00", format("utc" => true, "timezone" => "Asia/Tokyo"))
|
215
|
+
TextFormatter::TEMPLATE_REGISTRY.lookup('known')
|
608
216
|
end
|
609
217
|
end
|
610
218
|
end
|