fluent-plugin-tail_path 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -3
- data/CHANGELOG.md +10 -0
- data/{Gemfile.fluentd.lt.0.10.50 → Gemfile.fluentd.v10} +1 -1
- data/example/multiline.conf +25 -0
- data/{example.conf → example/singleline.conf} +4 -4
- data/fluent-plugin-tail_path.gemspec +3 -4
- data/lib/fluent/plugin/in_tail_path.rb +28 -68
- data/test/helper.rb +0 -1
- data/test/in_tail_path.rb +8 -0
- metadata +11 -24
- data/test/plugin/in_tail_path.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c83607c70652fd3de4fbf8b05a283ce1c2dc9b0
|
4
|
+
data.tar.gz: a4c0ce8ca8fbf9a19bfb2af4e7cc10484a75770a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65f3b4ff5fc2cd1852ffce114dba032d46301c584a27a30b1a9c6dec5cca250d061eaf17d4cd5be1546cb8c25aed42cd742bcf3b8b00b5c785e29f2bec6b402c
|
7
|
+
data.tar.gz: c735b9eb28f252b75f814ba063e7143c66804a2403ecd951bb5baea025eee773b32c0a9220bf67d089585e07d9ec74a18c2066ebf01a881e0c936e53f0e373d3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# /tmp/application.log
|
2
|
+
# ==firstline
|
3
|
+
# foo
|
4
|
+
# ==firstline
|
5
|
+
# bar
|
6
|
+
# ==firstline
|
7
|
+
# baz
|
8
|
+
|
9
|
+
<source>
|
10
|
+
type tail_path
|
11
|
+
format multiline
|
12
|
+
format_firstline /^==firstline/
|
13
|
+
format1 /^(?<message>.*)/
|
14
|
+
path /tmp/application.log
|
15
|
+
refresh_interval 5
|
16
|
+
# pos_file /tmp/application.pos
|
17
|
+
read_from_head true
|
18
|
+
tag raw.test
|
19
|
+
path_key path
|
20
|
+
</source>
|
21
|
+
|
22
|
+
<match raw.**>
|
23
|
+
type stdout
|
24
|
+
log_level trace
|
25
|
+
</match>
|
@@ -1,15 +1,15 @@
|
|
1
1
|
<source>
|
2
2
|
type tail_path
|
3
3
|
format none
|
4
|
-
path /
|
5
|
-
pos_file /
|
6
|
-
tag test
|
4
|
+
path /tmp/application.log
|
5
|
+
# pos_file /tmp/application.pos
|
7
6
|
rotate_wait 5
|
8
7
|
read_from_head true
|
9
8
|
refresh_interval 60
|
10
9
|
path_key path
|
10
|
+
tag raw.test
|
11
11
|
</source>
|
12
12
|
|
13
|
-
<match
|
13
|
+
<match raw.**>
|
14
14
|
type stdout
|
15
15
|
</match>
|
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-tail_path"
|
6
|
-
s.version = "0.0
|
6
|
+
s.version = "0.1.0"
|
7
7
|
s.authors = ["szhem", "Naotoshi Seo"]
|
8
8
|
s.email = ["sonots@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-tail_path"
|
@@ -15,8 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
|
-
s.add_runtime_dependency "fluentd", ">= 0.10.
|
18
|
+
s.add_runtime_dependency "fluentd", ">= 0.10.58"
|
19
19
|
s.add_development_dependency "rake"
|
20
|
-
s.add_development_dependency "
|
21
|
-
s.add_development_dependency "pry-nav"
|
20
|
+
s.add_development_dependency "test-unit"
|
22
21
|
end
|
@@ -1,83 +1,43 @@
|
|
1
1
|
require 'fluent/plugin/in_tail'
|
2
2
|
|
3
3
|
class Fluent::NewTailPathInput < Fluent::NewTailInput
|
4
|
-
|
5
|
-
|
6
|
-
config_param :path_key, :string, :default => nil
|
4
|
+
class RouterWrap
|
5
|
+
attr_accessor :tail_watcher
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
if method_defined?(:parse_line) # fluentd < 0.10.50
|
13
|
-
|
14
|
-
# Override to add path field
|
15
|
-
def convert_line_to_event(line, es, tail_watcher)
|
16
|
-
begin
|
17
|
-
line.chomp! # remove \n
|
18
|
-
time, record = parse_line(line)
|
19
|
-
if time && record
|
20
|
-
record[@path_key] ||= tail_watcher.path unless @path_key.nil? # custom
|
21
|
-
es.add(time, record)
|
22
|
-
else
|
23
|
-
log.warn "pattern not match: #{line.inspect}"
|
24
|
-
end
|
25
|
-
rescue => e
|
26
|
-
log.warn line.dump, :error => e.to_s
|
27
|
-
log.debug_backtrace(e)
|
28
|
-
end
|
7
|
+
def initialize(router, path_key)
|
8
|
+
@router = router
|
9
|
+
@path_key = path_key
|
10
|
+
@tail_watcher = nil
|
29
11
|
end
|
30
12
|
|
31
|
-
|
13
|
+
def emit(tag, time, record)
|
14
|
+
record[@path_key] = @tail_watcher.path unless @path_key.nil?
|
15
|
+
@router.emit(tag, time, record)
|
16
|
+
end
|
32
17
|
|
33
|
-
|
34
|
-
|
35
|
-
begin
|
36
|
-
line.chomp! # remove \n
|
37
|
-
@parser.parse(line) { |time, record|
|
38
|
-
if time && record
|
39
|
-
record[@path_key] ||= tail_watcher.path unless @path_key.nil? # custom
|
40
|
-
es.add(time, record)
|
41
|
-
else
|
42
|
-
log.warn "pattern not match: #{line.inspect}"
|
43
|
-
end
|
44
|
-
}
|
45
|
-
rescue => e
|
46
|
-
log.warn line.dump, :error => e.to_s
|
47
|
-
log.debug_backtrace(e)
|
48
|
-
end
|
18
|
+
def emit_array(tag, array)
|
19
|
+
@router.emit_array(tag, array)
|
49
20
|
end
|
50
21
|
|
22
|
+
def emit_stream(tag, es)
|
23
|
+
es.each {|time,record|
|
24
|
+
record[@path_key] = @tail_watcher.path unless @path_key.nil?
|
25
|
+
}
|
26
|
+
@router.emit_stream(tag, es)
|
27
|
+
end
|
51
28
|
end
|
52
29
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
30
|
+
Fluent::Plugin.register_input('tail_path', self)
|
31
|
+
|
32
|
+
config_param :path_key, :string, :default => nil
|
33
|
+
|
34
|
+
def configure(conf)
|
35
|
+
super
|
36
|
+
@router = RouterWrap.new(@router, @path_key)
|
60
37
|
end
|
61
38
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
es = ::Fluent::MultiEventStream.new
|
66
|
-
lines.each { |line|
|
67
|
-
if @parser.parser.firstline?(line)
|
68
|
-
if lb
|
69
|
-
convert_line_to_event(lb, es, tail_watcher)
|
70
|
-
end
|
71
|
-
lb = line
|
72
|
-
else
|
73
|
-
if lb.nil?
|
74
|
-
log.warn "got incomplete line before first line from #{tail_watcher.path}: #{lb.inspect}"
|
75
|
-
else
|
76
|
-
lb << line
|
77
|
-
end
|
78
|
-
end
|
79
|
-
}
|
80
|
-
tail_watcher.line_buffer = lb
|
81
|
-
es
|
39
|
+
def receive_lines(lines, tail_watcher)
|
40
|
+
@router.tail_watcher = tail_watcher
|
41
|
+
super
|
82
42
|
end
|
83
43
|
end
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-tail_path
|
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
|
- szhem
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.10.
|
20
|
+
version: 0.10.58
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: 0.10.
|
27
|
+
version: 0.10.58
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,21 +40,7 @@ dependencies:
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: pry-nav
|
43
|
+
name: test-unit
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
59
45
|
requirements:
|
60
46
|
- - ">="
|
@@ -78,15 +64,16 @@ files:
|
|
78
64
|
- ".travis.yml"
|
79
65
|
- CHANGELOG.md
|
80
66
|
- Gemfile
|
81
|
-
- Gemfile.fluentd.
|
67
|
+
- Gemfile.fluentd.v10
|
82
68
|
- LICENSE
|
83
69
|
- README.md
|
84
70
|
- Rakefile
|
85
|
-
- example.conf
|
71
|
+
- example/multiline.conf
|
72
|
+
- example/singleline.conf
|
86
73
|
- fluent-plugin-tail_path.gemspec
|
87
74
|
- lib/fluent/plugin/in_tail_path.rb
|
88
75
|
- test/helper.rb
|
89
|
-
- test/
|
76
|
+
- test/in_tail_path.rb
|
90
77
|
homepage: https://github.com/sonots/fluent-plugin-tail_path
|
91
78
|
licenses: []
|
92
79
|
metadata: {}
|
@@ -106,10 +93,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
93
|
version: '0'
|
107
94
|
requirements: []
|
108
95
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.5.1
|
110
97
|
signing_key:
|
111
98
|
specification_version: 4
|
112
99
|
summary: Fluentd in_tail extension to add `path` field
|
113
100
|
test_files:
|
114
101
|
- test/helper.rb
|
115
|
-
- test/
|
102
|
+
- test/in_tail_path.rb
|
data/test/plugin/in_tail_path.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require_relative '../helper'
|
2
|
-
|
3
|
-
class TailPathInputTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
Fluent::Test.setup
|
6
|
-
FileUtils.rm_rf(TMP_DIR)
|
7
|
-
FileUtils.mkdir_p(TMP_DIR)
|
8
|
-
end
|
9
|
-
|
10
|
-
TMP_DIR = File.dirname(__FILE__) + "/../tmp/tail#{ENV['TEST_ENV_NUMBER']}"
|
11
|
-
|
12
|
-
COMMON_CONFIG = %[
|
13
|
-
path #{TMP_DIR}/tail.txt
|
14
|
-
tag t1
|
15
|
-
rotate_wait 2s
|
16
|
-
pos_file #{TMP_DIR}/tail.pos
|
17
|
-
]
|
18
|
-
SINGLE_LINE_CONFIG = %[
|
19
|
-
format /(?<message>.*)/
|
20
|
-
]
|
21
|
-
|
22
|
-
def create_driver(conf = SINGLE_LINE_CONFIG, use_common_conf = true)
|
23
|
-
config = use_common_conf ? COMMON_CONFIG + conf : conf
|
24
|
-
Fluent::Test::InputTestDriver.new(Fluent::NewTailPathInput).configure(config)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_path_key
|
28
|
-
File.open("#{TMP_DIR}/tail.txt", "w") { |f| }
|
29
|
-
|
30
|
-
d = create_driver(%[
|
31
|
-
path #{TMP_DIR}/tail.txt
|
32
|
-
tag t1
|
33
|
-
format /(?<message>.*)/
|
34
|
-
path_key foobar
|
35
|
-
], false)
|
36
|
-
|
37
|
-
d.run do
|
38
|
-
sleep 1
|
39
|
-
|
40
|
-
File.open("#{TMP_DIR}/tail.txt", "a") {|f|
|
41
|
-
f.puts "test1"
|
42
|
-
f.puts "test2"
|
43
|
-
}
|
44
|
-
sleep 1
|
45
|
-
end
|
46
|
-
|
47
|
-
emits = d.emits
|
48
|
-
assert_equal(true, emits.length > 0)
|
49
|
-
assert_equal({"message"=>"test1", "foobar"=>"#{TMP_DIR}/tail.txt"}, emits[0][2])
|
50
|
-
assert_equal({"message"=>"test2", "foobar"=>"#{TMP_DIR}/tail.txt"}, emits[1][2])
|
51
|
-
end
|
52
|
-
end
|