fluent-plugin-cat-sweep 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +5 -0
- data/fluent-plugin-cat-sweep.gemspec +1 -1
- data/lib/fluent/plugin/in_cat_sweep.rb +41 -11
- data/test/helper.rb +20 -0
- data/test/test_in_cat_sweep.rb +34 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c416b3c5df83179c396c4343661ca0d6edabf9c
|
4
|
+
data.tar.gz: 99f032ae97d3276572f4d83c986a2b8cf9ed47bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e04a78004b577267659870f282bca66eb6212892a013db0f2c1ada39d1c7b4829264afe1c2183c499e9b3a339f5da179fce52162119c8a5f17e564c5b595873
|
7
|
+
data.tar.gz: 29e6a7cc393cb249f9008c387f4b7d42740177b6c1908aecbce54b31b8181ca910bae46a1d282eea19707e9bb01cb1aff802984316e079988812b46061ea92f0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -81,6 +81,11 @@ Our assumption is that this mechanism should provide more durability than `in_ta
|
|
81
81
|
|
82
82
|
# Optional. default 5 seconds.
|
83
83
|
run_interval 10
|
84
|
+
|
85
|
+
# Optional. Emit entire file contents as an event, default emits each line as an event.
|
86
|
+
# This assures that fluentd emits the entire file contents together. Please note that buffer_chunk_limit
|
87
|
+
# must be larger than bytes in a file to be sent by buffered output plugins such as out_forward, out_s3.
|
88
|
+
file_event_stream false
|
84
89
|
</source>
|
85
90
|
```
|
86
91
|
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-cat-sweep"
|
7
|
-
spec.version = "0.1.
|
7
|
+
spec.version = "0.1.2"
|
8
8
|
spec.authors = ["Civitaspo(takahiro.nakayama)", "Naotoshi Seo"]
|
9
9
|
spec.email = ["civitaspo@gmail.com", "sonots@gmail.com"]
|
10
10
|
|
@@ -19,8 +19,8 @@ module Fluent
|
|
19
19
|
config_param :oneline_max_bytes, :integer, :default => 536870912 # 512MB
|
20
20
|
config_param :move_to, :string, :default => '/tmp'
|
21
21
|
config_param :remove_after_processing, :bool, :default => false
|
22
|
-
config_param :run_interval, :
|
23
|
-
|
22
|
+
config_param :run_interval, :time, :default => 5
|
23
|
+
config_param :file_event_stream, :bool, :default => false
|
24
24
|
|
25
25
|
# To support log_level option implemented by Fluentd v0.10.43
|
26
26
|
unless method_defined?(:log)
|
@@ -184,22 +184,52 @@ module Fluent
|
|
184
184
|
buffer_clean!
|
185
185
|
end
|
186
186
|
|
187
|
-
def
|
188
|
-
if
|
189
|
-
|
190
|
-
|
191
|
-
raise FormatError,
|
192
|
-
"in_cat_sweep: pattern not match: #{message.inspect}"
|
193
|
-
end
|
187
|
+
def emit_line(line)
|
188
|
+
if line
|
189
|
+
time, record = parse_line(line)
|
190
|
+
if time and record
|
194
191
|
router.emit(@tag, time, record)
|
195
192
|
end
|
196
193
|
end
|
197
194
|
end
|
198
195
|
|
196
|
+
def emit_file(fp)
|
197
|
+
entries = []
|
198
|
+
read_each_line(fp) do |line|
|
199
|
+
if line
|
200
|
+
entry = parse_line(line)
|
201
|
+
entries << entry if entry
|
202
|
+
end
|
203
|
+
end
|
204
|
+
unless entries.empty?
|
205
|
+
es = ArrayEventStream.new(entries)
|
206
|
+
router.emit_stream(@tag, es)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def parse_line(line)
|
211
|
+
entry = nil
|
212
|
+
@parser.parse(line) do |time, record|
|
213
|
+
if time && record
|
214
|
+
entry = [time, record]
|
215
|
+
else
|
216
|
+
# We want to fail an entire file on `pattern not match`
|
217
|
+
# This behavior makes it easy to recover with manual fix operation
|
218
|
+
raise FormatError,
|
219
|
+
"in_cat_sweep: pattern not match: #{line.inspect}"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
entry
|
223
|
+
end
|
224
|
+
|
199
225
|
def process(original_filename, processing_filename)
|
200
226
|
File.open(processing_filename, 'r') do |tfile|
|
201
|
-
|
202
|
-
|
227
|
+
if @file_event_stream
|
228
|
+
emit_file(tfile)
|
229
|
+
else
|
230
|
+
read_each_line(tfile) do |line|
|
231
|
+
emit_line(line)
|
232
|
+
end
|
203
233
|
end
|
204
234
|
log.debug { %[in_cat_sweep: process: {filename:"#{original_filename}",size:#{tfile.size}}] }
|
205
235
|
end
|
data/test/helper.rb
CHANGED
@@ -6,3 +6,23 @@ unless defined?(Test::Unit::AssertionFailedError)
|
|
6
6
|
class Test::Unit::AssertionFailedError < StandardError
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
# Reduce sleep period at
|
11
|
+
# https://github.com/fluent/fluentd/blob/a271b3ec76ab7cf89ebe4012aa5b3912333dbdb7/lib/fluent/test/base.rb#L81
|
12
|
+
module Fluent
|
13
|
+
module Test
|
14
|
+
class TestDriver
|
15
|
+
def run(num_waits = 10, &block)
|
16
|
+
@instance.start
|
17
|
+
begin
|
18
|
+
# wait until thread starts
|
19
|
+
# num_waits.times { sleep 0.05 }
|
20
|
+
sleep 0.05
|
21
|
+
return yield
|
22
|
+
ensure
|
23
|
+
@instance.shutdown
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/test/test_in_cat_sweep.rb
CHANGED
@@ -19,6 +19,12 @@ class CatSweepInputTest < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
CONFIG_BASE = %[
|
21
21
|
file_path_with_glob #{TMP_DIR_FROM}/*
|
22
|
+
run_interval 0.05
|
23
|
+
]
|
24
|
+
|
25
|
+
CONFIG_MINIMUM_REQUIRED = CONFIG_BASE + %[
|
26
|
+
format tsv
|
27
|
+
waiting_seconds 5
|
22
28
|
]
|
23
29
|
|
24
30
|
def create_driver(conf, use_v1 = true)
|
@@ -38,19 +44,24 @@ class CatSweepInputTest < Test::Unit::TestCase
|
|
38
44
|
d = create_driver(CONFIG_BASE + %[format tsv])
|
39
45
|
end
|
40
46
|
|
41
|
-
d = create_driver(
|
42
|
-
format tsv
|
43
|
-
waiting_seconds 5
|
44
|
-
])
|
47
|
+
d = create_driver(CONFIG_MINIMUM_REQUIRED)
|
45
48
|
|
46
49
|
assert_equal "#{TMP_DIR_FROM}/*", d.instance.instance_variable_get(:@file_path_with_glob)
|
47
50
|
assert_equal 'tsv', d.instance.instance_variable_get(:@format)
|
48
51
|
assert_equal 5, d.instance.instance_variable_get(:@waiting_seconds)
|
49
52
|
end
|
50
53
|
|
54
|
+
def test_configure_file_event_stream
|
55
|
+
d = create_driver(CONFIG_MINIMUM_REQUIRED)
|
56
|
+
assert { false == d.instance.file_event_stream }
|
57
|
+
|
58
|
+
d = create_driver(CONFIG_MINIMUM_REQUIRED + %[file_event_stream true])
|
59
|
+
assert { true == d.instance.file_event_stream }
|
60
|
+
end
|
61
|
+
|
51
62
|
def compare_test_result(emits, tests)
|
52
63
|
emits.each_index do |i|
|
53
|
-
|
64
|
+
assert { tests[i]['expected'] == emits[i][2]['message'] }
|
54
65
|
end
|
55
66
|
end
|
56
67
|
|
@@ -70,24 +81,27 @@ class CatSweepInputTest < Test::Unit::TestCase
|
|
70
81
|
]
|
71
82
|
}
|
72
83
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
84
|
+
[false, true].each do |file_event_stream|
|
85
|
+
TEST_CASES.each do |format, test_cases|
|
86
|
+
test_case_name = "test_msg_process_#{format}_file_event_stream_#{file_event_stream}"
|
87
|
+
define_method(test_case_name) do
|
88
|
+
File.open("#{TMP_DIR_FROM}/#{test_case_name}", 'w') do |io|
|
89
|
+
test_cases.each do |test|
|
90
|
+
io.write(test['msg'])
|
91
|
+
end
|
79
92
|
end
|
80
|
-
end
|
81
93
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
94
|
+
d = create_driver(CONFIG_BASE + %[
|
95
|
+
format #{format}
|
96
|
+
file_event_stream #{file_event_stream}
|
97
|
+
waiting_seconds 0
|
98
|
+
keys hdfs_path,unixtimestamp,label,message
|
99
|
+
])
|
100
|
+
d.run
|
88
101
|
|
89
|
-
|
90
|
-
|
102
|
+
compare_test_result(d.emits, test_cases)
|
103
|
+
assert { Dir.glob("#{TMP_DIR_FROM}/#{test_case_name}*").empty? }
|
104
|
+
end
|
91
105
|
end
|
92
106
|
end
|
93
107
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-cat-sweep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Civitaspo(takahiro.nakayama)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.4.5
|
153
|
+
rubygems_version: 2.4.5.1
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Fluentd plugin to cat files and move them.
|