fluent-plugin-file-alternative 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -12
- data/fluent-plugin-file-alternative.gemspec +2 -1
- data/lib/fluent/plugin/out_file_alternative.rb +8 -1
- data/test/plugin/test_out_file_alternative.rb +20 -3
- metadata +18 -5
- data/test/plugin/test_out_file_original.rb +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea52057a062ad50131a6e1cf865c06c7bb8b69d2
|
4
|
+
data.tar.gz: efd08dcdc758d6f6ffab1b1767ecf613ea9a7cc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c78ef8f78cb7cbaf29ae78287beaba67d6267624599b3116bf9aa69050a158175e5fba4ec50c125ed9adb1a959f398dd20e55aa0e32d6b231b651023e9bb6f30
|
7
|
+
data.tar.gz: 3d618956f885a15c80984cec1da9425783e8332fa3912bc0218e56e3b6c5d8a30a705865e271cc9c02055b1279d1affe0819d2dd0e116616bbd9f2590ed67f3f
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# fluent-plugin-file-alternative
|
2
2
|
|
3
|
-
File output plugin alternative implementation
|
4
|
-
[Fluentd](http://fluentd.org) built-in 'out_file'**, and added many options to format output as you want.
|
3
|
+
File output plugin alternative implementation.
|
5
4
|
|
6
5
|
FileAlternativeOutput slices data by time (for specified units), and store these data as plain text on local file. You can specify to:
|
7
6
|
|
@@ -14,19 +13,19 @@ FileAlternativeOutput slices data by time (for specified units), and store these
|
|
14
13
|
And you can specify output file path as:
|
15
14
|
|
16
15
|
* Standard out_file way
|
17
|
-
* configure
|
18
|
-
* and
|
19
|
-
* got
|
16
|
+
* configure `path /path/to/dir/access`
|
17
|
+
* and `time_slice_format %Y%m%d`
|
18
|
+
* got `/path/to/dir/access.20120316.log`
|
19
|
+
* Standard out_file way (alternative)
|
20
|
+
* configure `path /path/to/dir/access.*.log`
|
21
|
+
* and `time_slice_format %Y%m%d`
|
22
|
+
* got `/path/to/dir/access.20120316.log`
|
20
23
|
* Alternative style
|
21
|
-
* configure
|
22
|
-
* got
|
24
|
+
* configure `path /path/to/dir/access.%Y%m%d.log` only (don't include `*`)
|
25
|
+
* got `/path/to/dir/access.20120316.log`
|
23
26
|
|
24
27
|
And, gzip compression is also supported.
|
25
28
|
|
26
|
-
-### Why this is not a patch for out_file?
|
27
|
-
-
|
28
|
-
-`fluent-plugin-file-alternative` has optimized buffer data structure to make faster to write data on disk. But that buffer structure is not compatible with `out_file`'s one. That's tha reason why this plugin is an another plugin from `out_file`.
|
29
|
-
|
30
29
|
## Configuration
|
31
30
|
|
32
31
|
### FileAlternativeOutput
|
@@ -36,7 +35,7 @@ Standard out_file way (hourly log, compression, time-tag-json):
|
|
36
35
|
<match out.**>
|
37
36
|
type file_alternative
|
38
37
|
path /var/log/service/access.*.log
|
39
|
-
|
38
|
+
time_slice_format %Y%m%d_%H
|
40
39
|
compress gzip
|
41
40
|
</match>
|
42
41
|
|
@@ -57,6 +56,8 @@ If you don't want fluentd-time and tag in written file, and messages with single
|
|
57
56
|
output_include_tag false
|
58
57
|
output_data_type attr:message
|
59
58
|
add_newline false
|
59
|
+
symlink_path /var/log/service/access_latest.log
|
60
|
+
dir_mode 0777
|
60
61
|
</match>
|
61
62
|
|
62
63
|
Then, you will get:
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "fluent-plugin-file-alternative"
|
5
|
-
gem.version = "0.
|
5
|
+
gem.version = "0.2.0"
|
6
6
|
|
7
7
|
gem.authors = ["TAGOMORI Satoshi"]
|
8
8
|
gem.email = ["tagomoris@gmail.com"]
|
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_runtime_dependency "fluentd", ">= 0.10.39" # This version for @buffer.symlink_path
|
20
20
|
gem.add_runtime_dependency "fluent-mixin-plaintextformatter"
|
21
21
|
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "test-unit"
|
22
23
|
end
|
@@ -27,6 +27,8 @@ class Fluent::FileAlternativeOutput < Fluent::TimeSlicedOutput
|
|
27
27
|
|
28
28
|
config_param :symlink_path, :string, :default => nil
|
29
29
|
|
30
|
+
config_param :dir_mode, :string, :default => '0777'
|
31
|
+
|
30
32
|
include Fluent::Mixin::PlainTextFormatter
|
31
33
|
|
32
34
|
def initialize
|
@@ -133,7 +135,12 @@ class Fluent::FileAlternativeOutput < Fluent::TimeSlicedOutput
|
|
133
135
|
path = path_format(chunk.key)
|
134
136
|
|
135
137
|
begin
|
136
|
-
|
138
|
+
require 'pathname'
|
139
|
+
|
140
|
+
Pathname.new(path).descend {|p|
|
141
|
+
FileUtils.mkdir_p( File.dirname(p)) unless File.directory?(p)
|
142
|
+
FileUtils.chmod @dir_mode.to_i(8), File.dirname(p) unless File.directory?(p)
|
143
|
+
}
|
137
144
|
|
138
145
|
case @compress
|
139
146
|
when :gz
|
@@ -31,6 +31,7 @@ class FileAlternativeOutputTest < Test::Unit::TestCase
|
|
31
31
|
|
32
32
|
d = create_driver %[
|
33
33
|
path #{TMP_DIR}/accesslog.%Y-%m-%d-%H-%M-%S
|
34
|
+
dir_mode 0700
|
34
35
|
]
|
35
36
|
assert_equal '%Y%m%d%H%M%S', d.instance.time_slice_format
|
36
37
|
assert_nil d.instance.compress
|
@@ -39,6 +40,7 @@ class FileAlternativeOutputTest < Test::Unit::TestCase
|
|
39
40
|
assert_equal 'json', d.instance.output_data_type
|
40
41
|
assert_equal true, d.instance.add_newline
|
41
42
|
assert_equal "TAB", d.instance.field_separator
|
43
|
+
assert_equal '0700', d.instance.dir_mode
|
42
44
|
assert_nil d.instance.remove_prefix
|
43
45
|
end
|
44
46
|
|
@@ -109,7 +111,7 @@ class FileAlternativeOutputTest < Test::Unit::TestCase
|
|
109
111
|
d2.expect_format %[123-456-789\n]
|
110
112
|
path = d2.run
|
111
113
|
assert_equal "#{TMP_DIR}/accesslog.2011-01-02-13-14-15", path[0]
|
112
|
-
|
114
|
+
|
113
115
|
d3 = create_driver %[
|
114
116
|
path #{TMP_DIR}/accesslog.%Y-%m-%d-%H-%M-%S
|
115
117
|
compress gzip
|
@@ -129,6 +131,20 @@ class FileAlternativeOutputTest < Test::Unit::TestCase
|
|
129
131
|
d3.expect_format %[app01,info,Send response\n]
|
130
132
|
path = d3.run
|
131
133
|
assert_equal "#{TMP_DIR}/accesslog.2011-01-02-13-14-15.gz", path[0]
|
134
|
+
|
135
|
+
d4 = create_driver %[
|
136
|
+
path #{TMP_DIR}/path_to_test/%Y/%m/%d/accesslog.%Y-%m-%d-%H-%M-%S
|
137
|
+
dir_mode 0700
|
138
|
+
]
|
139
|
+
|
140
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
141
|
+
d4.emit({"server" => "www01", "level" => "warn", "log" => "Exception\n"}, time)
|
142
|
+
path = d4.run
|
143
|
+
assert_equal '40700', File.stat(File.dirname(File.dirname(File.dirname(path[0])))).mode.to_s(8)
|
144
|
+
assert_equal '40700', File.stat(File.dirname(File.dirname(path[0]))).mode.to_s(8)
|
145
|
+
assert_equal '40700', File.stat(File.dirname(path[0])).mode.to_s(8)
|
146
|
+
assert_equal "#{TMP_DIR}/path_to_test/2011/01/02/accesslog.2011-01-02-13-14-15", path[0]
|
147
|
+
|
132
148
|
end
|
133
149
|
|
134
150
|
def test_write_with_symlink
|
@@ -143,16 +159,17 @@ class FileAlternativeOutputTest < Test::Unit::TestCase
|
|
143
159
|
d.run
|
144
160
|
assert File.exists?(symlink_path)
|
145
161
|
assert File.symlink?(symlink_path)
|
146
|
-
|
162
|
+
|
147
163
|
d.instance.start
|
148
164
|
begin
|
149
165
|
10.times { sleep 0.05 }
|
150
166
|
d.instance.enqueue_buffer
|
151
|
-
|
167
|
+
|
152
168
|
assert !File.exists?(symlink_path)
|
153
169
|
assert File.symlink?(symlink_path)
|
154
170
|
ensure
|
155
171
|
d.instance.shutdown
|
156
172
|
end
|
157
173
|
end
|
174
|
+
|
158
175
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-file-alternative
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAGOMORI Satoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: alternative implementation of out_file, with various configurations
|
56
70
|
email:
|
57
71
|
- tagomoris@gmail.com
|
@@ -69,7 +83,6 @@ files:
|
|
69
83
|
- lib/fluent/plugin/out_file_alternative.rb
|
70
84
|
- test/helper.rb
|
71
85
|
- test/plugin/test_out_file_alternative.rb
|
72
|
-
- test/plugin/test_out_file_original.rb
|
73
86
|
homepage: https://github.com/tagomoris/fluent-plugin-file-alternative
|
74
87
|
licenses:
|
75
88
|
- APLv2
|
@@ -90,11 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
103
|
version: '0'
|
91
104
|
requirements: []
|
92
105
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.4.5
|
94
107
|
signing_key:
|
95
108
|
specification_version: 4
|
96
109
|
summary: alternative implementation of out_file
|
97
110
|
test_files:
|
98
111
|
- test/helper.rb
|
99
112
|
- test/plugin/test_out_file_alternative.rb
|
100
|
-
|
113
|
+
has_rdoc:
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'fluent/test'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
class FileOutputTest < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
Fluent::Test.setup
|
8
|
-
FileUtils.rm_rf(TMP_DIR)
|
9
|
-
FileUtils.mkdir_p(TMP_DIR)
|
10
|
-
end
|
11
|
-
|
12
|
-
TMP_DIR = File.dirname(__FILE__) + "/../tmp"
|
13
|
-
|
14
|
-
CONFIG = %[
|
15
|
-
path #{TMP_DIR}/out_file_test
|
16
|
-
compress gz
|
17
|
-
utc
|
18
|
-
]
|
19
|
-
|
20
|
-
def create_driver(conf = CONFIG)
|
21
|
-
Fluent::Test::BufferedOutputTestDriver.new(Fluent::FileOutput).configure(conf)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_configure
|
25
|
-
d = create_driver %[
|
26
|
-
path test_path
|
27
|
-
compress gz
|
28
|
-
]
|
29
|
-
assert_equal 'test_path', d.instance.path
|
30
|
-
assert_equal :gz, d.instance.compress
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_format
|
34
|
-
d = create_driver
|
35
|
-
|
36
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
37
|
-
d.emit({"a"=>1}, time)
|
38
|
-
d.emit({"a"=>2}, time)
|
39
|
-
|
40
|
-
d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
|
41
|
-
d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
|
42
|
-
|
43
|
-
d.run
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_write
|
47
|
-
d = create_driver
|
48
|
-
|
49
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
50
|
-
d.emit({"a"=>1}, time)
|
51
|
-
d.emit({"a"=>2}, time)
|
52
|
-
|
53
|
-
# FileOutput#write returns path
|
54
|
-
path = d.run
|
55
|
-
expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
|
56
|
-
assert_equal expect_path, path
|
57
|
-
|
58
|
-
data = Zlib::GzipReader.open(expect_path) {|f| f.read }
|
59
|
-
assert_equal %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n] +
|
60
|
-
%[2011-01-02T13:14:15Z\ttest\t{"a":2}\n],
|
61
|
-
data
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_write_path_increment
|
65
|
-
d = create_driver
|
66
|
-
|
67
|
-
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
68
|
-
d.emit({"a"=>1}, time)
|
69
|
-
d.emit({"a"=>2}, time)
|
70
|
-
|
71
|
-
# FileOutput#write returns path
|
72
|
-
path = d.run
|
73
|
-
assert_equal "#{TMP_DIR}/out_file_test._0.log.gz", path
|
74
|
-
|
75
|
-
path = d.run
|
76
|
-
assert_equal "#{TMP_DIR}/out_file_test._1.log.gz", path
|
77
|
-
|
78
|
-
path = d.run
|
79
|
-
assert_equal "#{TMP_DIR}/out_file_test._2.log.gz", path
|
80
|
-
end
|
81
|
-
end
|