fluent-plugin-cat-sweep 0.0.1 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +18 -1
- data/fluent-plugin-cat-sweep.gemspec +1 -1
- data/lib/fluent/plugin/in_cat_sweep.rb +39 -14
- data/test/test_in_cat_sweep.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d379d06372f06e8fc8930c01c1cb35126344f56
|
4
|
+
data.tar.gz: 12bc664edebb79f7d0db631234b2cd2077b86bcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c09d4acc0ecc381aa599b15995275b637f5c55def2df29ec2ede02e5c296d45923527bb39b7449875ed9515f94991136ffff520f44936411e9d05a7630a6b9c
|
7
|
+
data.tar.gz: 317727c30f4d959895db9e60ce2f995456000df1524c4907bfb4c50354aba22e904c51761c062d9be03727bda1cb3d4c934f7a957f56cb826a728388f46fe4a1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# fluent-plugin-cat-sweep
|
2
2
|
|
3
|
-
[](http://travis-ci.org/civitaspo/fluent-plugin-cat-sweep)
|
3
|
+
[](https://circleci.com/gh/civitaspo/fluent-plugin-cat-sweep) [](http://travis-ci.org/civitaspo/fluent-plugin-cat-sweep)
|
4
4
|
|
5
5
|
Fluentd plugin to read data from files and to remove or move after processing.
|
6
6
|
|
@@ -20,6 +20,23 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
$ gem install fluent-plugin-cat-sweep
|
22
22
|
|
23
|
+
## Basic Behavior
|
24
|
+
|
25
|
+
Assume that an application outputs logs into `/tmp/test` directory as
|
26
|
+
|
27
|
+
```
|
28
|
+
tmp/test
|
29
|
+
├── accesss.log.201509151611
|
30
|
+
├── accesss.log.201509151612
|
31
|
+
└── accesss.log.201509151613
|
32
|
+
```
|
33
|
+
|
34
|
+
in every one minute interval.
|
35
|
+
|
36
|
+
This plugin watches the directory (`file_path_with_glob tmp/test/access.log.*`), and reads the contents and sweep (deafault: remove) for files whose mtime are passed in 60 seconds (can be configured with `waiting_seconds`).
|
37
|
+
|
38
|
+
Our assumption is that this mechanism should provide more durability than `in_tail` (batch read overcomes than streaming read).
|
39
|
+
|
23
40
|
## Configuration
|
24
41
|
|
25
42
|
```
|
@@ -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.0
|
7
|
+
spec.version = "0.1.0"
|
8
8
|
spec.authors = ["Civitaspo(takahiro.nakayama)"]
|
9
9
|
spec.email = ["civitaspo@gmail.com"]
|
10
10
|
|
@@ -50,8 +50,20 @@ module Fluent
|
|
50
50
|
raise Fluent::ConfigError, "in_cat_sweep: `line_terminated_by` must has some letters."
|
51
51
|
end
|
52
52
|
|
53
|
-
if !remove_file?
|
54
|
-
|
53
|
+
if !remove_file?
|
54
|
+
first_filename = Dir.glob(@file_path_with_glob).first
|
55
|
+
dirname = first_filename ? move_dirname(first_filename) : @move_to
|
56
|
+
if Dir.exist?(dirname)
|
57
|
+
if !File.writable?(dirname)
|
58
|
+
raise Fluent::ConfigError, "in_cat_sweep: `move_to` directory (#{dirname}) must be writable."
|
59
|
+
end
|
60
|
+
else
|
61
|
+
begin
|
62
|
+
FileUtils.mkdir_p(dirname)
|
63
|
+
rescue => e
|
64
|
+
raise Fluent::ConfigError, "in_cat_sweep: `move_to` directory (#{dirname}) must be writable."
|
65
|
+
end
|
66
|
+
end
|
55
67
|
end
|
56
68
|
|
57
69
|
@read_bytes_once = 262144 # 256 KB
|
@@ -82,10 +94,9 @@ module Fluent
|
|
82
94
|
after_processing(processing_filename)
|
83
95
|
end
|
84
96
|
rescue => e
|
85
|
-
log.error "in_cat_sweep: processing
|
86
|
-
:error => e, :error_class => e.class
|
97
|
+
log.error "in_cat_sweep: processing: #{processing_filename}", :error => e, :error_class => e.class
|
87
98
|
log.error_backtrace
|
88
|
-
safe_fail(processing_filename)
|
99
|
+
safe_fail(e, processing_filename)
|
89
100
|
end
|
90
101
|
end
|
91
102
|
end
|
@@ -112,19 +123,26 @@ module Fluent
|
|
112
123
|
def get_processing_filename(filename)
|
113
124
|
tmpfile = String.new
|
114
125
|
tmpfile << filename << '.' << Process.pid.to_s << '.'
|
115
|
-
tmpfile << Time.now.to_i.to_s <<
|
126
|
+
tmpfile << Time.now.to_i.to_s << @processing_file_suffix
|
127
|
+
end
|
128
|
+
|
129
|
+
def revert_processing_filename(processing_filename)
|
130
|
+
tmpfile = processing_filename.dup
|
131
|
+
tmpfile.chomp!(@processing_file_suffix)
|
132
|
+
tmpfile.gsub!(/\.\d+\.\d+$/, '')
|
116
133
|
end
|
117
134
|
|
118
|
-
def get_error_filename(filename)
|
135
|
+
def get_error_filename(e, filename)
|
119
136
|
errfile = String.new
|
120
|
-
errfile << filename <<
|
137
|
+
errfile << filename << "." << e.class.to_s << @error_file_suffix
|
121
138
|
end
|
122
139
|
|
123
|
-
def safe_fail(filename)
|
140
|
+
def safe_fail(e, filename)
|
124
141
|
begin
|
125
|
-
|
142
|
+
error_filename = get_error_filename(e, filename)
|
143
|
+
lock_with_renaming(filename, error_filename)
|
126
144
|
rescue => e
|
127
|
-
log.error "in_cat_sweep: rename #{filename} to error
|
145
|
+
log.error "in_cat_sweep: rename #{filename} to error filename #{error_filename}",
|
128
146
|
:error => e, :error_class => e.class
|
129
147
|
log.error_backtrace
|
130
148
|
end
|
@@ -201,11 +219,18 @@ module Fluent
|
|
201
219
|
end
|
202
220
|
end
|
203
221
|
|
204
|
-
def
|
222
|
+
def move_dirname(filename)
|
223
|
+
File.join(@move_to, File.dirname(File.expand_path(filename)))
|
224
|
+
end
|
225
|
+
|
226
|
+
def after_processing(processing_filename)
|
205
227
|
if remove_file?
|
206
|
-
FileUtils.rm(
|
228
|
+
FileUtils.rm(processing_filename)
|
207
229
|
else
|
208
|
-
|
230
|
+
dirname = move_dirname(processing_filename)
|
231
|
+
FileUtils.mkdir_p(dirname)
|
232
|
+
filename = revert_processing_filename(File.basename(processing_filename))
|
233
|
+
FileUtils.mv(processing_filename, File.join(dirname, filename))
|
209
234
|
end
|
210
235
|
end
|
211
236
|
end
|
data/test/test_in_cat_sweep.rb
CHANGED
@@ -117,11 +117,11 @@ class CatSweepInputTest < Test::Unit::TestCase
|
|
117
117
|
|
118
118
|
assert(Dir.glob("#{TMP_DIR_FROM}/test_move_file*").empty?)
|
119
119
|
assert_match(
|
120
|
-
%r{\A#{TMP_DIR_TO}/test_move_file
|
121
|
-
Dir.glob("#{TMP_DIR_TO}/test_move_file*").first)
|
120
|
+
%r{\A#{TMP_DIR_TO}#{TMP_DIR_FROM}/test_move_file},
|
121
|
+
Dir.glob("#{TMP_DIR_TO}#{TMP_DIR_FROM}/test_move_file*").first)
|
122
122
|
assert_equal(
|
123
123
|
test_cases.map{|t|t['msg']}.join.to_s,
|
124
|
-
File.read(Dir.glob("#{TMP_DIR_TO}/test_move_file*").first))
|
124
|
+
File.read(Dir.glob("#{TMP_DIR_TO}#{TMP_DIR_FROM}/test_move_file*").first))
|
125
125
|
end
|
126
126
|
|
127
127
|
def test_oneline_max_bytes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-cat-sweep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Civitaspo(takahiro.nakayama)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|