fluent-plugin-concat 0.3.1 → 0.4.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 +11 -0
- data/fluent-plugin-concat.gemspec +2 -1
- data/lib/fluent/plugin/filter_concat.rb +64 -10
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53cd1a90ba28d88202ca99243dc4df5aaff6662a
|
4
|
+
data.tar.gz: 4cba9d7d4c63ef8429c304f4255cbb239c87c8e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9161c7af7c16cadd1a991a3e120d87ff681aadfe30b9c493764d993a50d73c00fe3be1b5ac84a712a1484b5d94706c51d9c95939eed510a3ea4fce19675e41f7
|
7
|
+
data.tar.gz: 1521cff3d1a0b54dc22d5e207f679216db987651fe981234a39f43e9d58d8c99342468679e8d0f3a992396721e4dfc1ec919887e5bf92b3d5359acee8876cd44
|
data/README.md
CHANGED
@@ -71,6 +71,17 @@ Specify first line of multiline by regular expression.
|
|
71
71
|
</filter>
|
72
72
|
```
|
73
73
|
|
74
|
+
You can handle timeout events and remaining buffers on shutdown this plugin.
|
75
|
+
|
76
|
+
```aconf
|
77
|
+
<label @ERROR>
|
78
|
+
<match docker.log>
|
79
|
+
@type file
|
80
|
+
path /path/to/error.log
|
81
|
+
</match>
|
82
|
+
</label>
|
83
|
+
```
|
84
|
+
|
74
85
|
## Contributing
|
75
86
|
|
76
87
|
1. Fork it
|
@@ -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-concat"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.4.0"
|
8
8
|
spec.authors = ["Kenji Okimoto"]
|
9
9
|
spec.email = ["okimoto@clear-code.com"]
|
10
10
|
|
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.11"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
22
|
spec.add_development_dependency "test-unit", ">= 3.1.0"
|
23
|
+
spec.add_development_dependency "test-unit-rr"
|
23
24
|
end
|
@@ -14,11 +14,17 @@ module Fluent
|
|
14
14
|
config_param :multiline_end_regexp, :string, default: nil
|
15
15
|
desc "The key to determine which stream an event belongs to"
|
16
16
|
config_param :stream_identity_key, :string, default: nil
|
17
|
+
desc "The interval between data flushes"
|
18
|
+
config_param :flush_interval, :time, default: 60
|
19
|
+
|
20
|
+
class TimeoutError < StandardError
|
21
|
+
end
|
17
22
|
|
18
23
|
def initialize
|
19
24
|
super
|
20
25
|
|
21
|
-
@buffer = Hash.new{|h, k| h[k] = [] }
|
26
|
+
@buffer = Hash.new {|h, k| h[k] = [] }
|
27
|
+
@timeout_map = Hash.new {|h, k| h[k] = Fluent::Engine.now }
|
22
28
|
end
|
23
29
|
|
24
30
|
def configure(conf)
|
@@ -44,9 +50,22 @@ module Fluent
|
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
53
|
+
def start
|
54
|
+
super
|
55
|
+
@finished = false
|
56
|
+
@loop = Coolio::Loop.new
|
57
|
+
timer = TimeoutTimer.new(1, method(:on_timer))
|
58
|
+
@loop.attach(timer)
|
59
|
+
@thread = Thread.new(@loop, &:run)
|
60
|
+
end
|
61
|
+
|
47
62
|
def shutdown
|
48
63
|
super
|
49
|
-
|
64
|
+
@finished = true
|
65
|
+
@loop.watchers.each(&:detach)
|
66
|
+
@loop.stop
|
67
|
+
@thread.join
|
68
|
+
flush_remaining_buffer
|
50
69
|
end
|
51
70
|
|
52
71
|
def filter_stream(tag, es)
|
@@ -64,12 +83,18 @@ module Fluent
|
|
64
83
|
|
65
84
|
private
|
66
85
|
|
86
|
+
def on_timer
|
87
|
+
return if @finished
|
88
|
+
flush_timeout_buffer
|
89
|
+
end
|
90
|
+
|
67
91
|
def process(tag, time, record)
|
68
92
|
if @stream_identity_key
|
69
|
-
stream_identity = record[@stream_identity_key]
|
93
|
+
stream_identity = "#{tag}:#{record[@stream_identity_key]}"
|
70
94
|
else
|
71
|
-
stream_identity = "default"
|
95
|
+
stream_identity = "#{tag}:default"
|
72
96
|
end
|
97
|
+
@timeout_map[stream_identity] = Fluent::Engine.now
|
73
98
|
case @mode
|
74
99
|
when :line
|
75
100
|
@buffer[stream_identity] << [tag, time, record]
|
@@ -91,6 +116,7 @@ module Fluent
|
|
91
116
|
if @buffer[stream_identity].empty?
|
92
117
|
return record
|
93
118
|
else
|
119
|
+
# Continuation of the previous line
|
94
120
|
@buffer[stream_identity] << [tag, time, record]
|
95
121
|
end
|
96
122
|
end
|
@@ -107,7 +133,7 @@ module Fluent
|
|
107
133
|
end
|
108
134
|
|
109
135
|
def flush_buffer(stream_identity, new_element = nil)
|
110
|
-
lines = @buffer[stream_identity].map{|_tag, _time, record| record[@key] }
|
136
|
+
lines = @buffer[stream_identity].map {|_tag, _time, record| record[@key] }
|
111
137
|
new_record = {
|
112
138
|
@key => lines.join(@separator)
|
113
139
|
}
|
@@ -116,19 +142,47 @@ module Fluent
|
|
116
142
|
new_record
|
117
143
|
end
|
118
144
|
|
119
|
-
def
|
145
|
+
def flush_timeout_buffer
|
146
|
+
now = Fluent::Engine.now
|
147
|
+
timeout_stream_identities = []
|
148
|
+
@timeout_map.each do |stream_identity, previous_timestamp|
|
149
|
+
next unless @flush_interval > (now - previous_timestamp)
|
150
|
+
timeout_stream_identities << stream_identity
|
151
|
+
flushed_record = flush_buffer(stream_identity)
|
152
|
+
tag = stream_identity.split(":").first
|
153
|
+
message = "Timeout flush: #{stream_identity}"
|
154
|
+
router.emit_error_event(tag, now, flushed_record, TimeoutError.new(message))
|
155
|
+
log.info message
|
156
|
+
end
|
157
|
+
@timeout_map.reject! do |stream_identity, _|
|
158
|
+
timeout_stream_identities.include?(stream_identity)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def flush_remaining_buffer
|
120
163
|
@buffer.each do |stream_identity, elements|
|
121
164
|
next if elements.empty?
|
122
|
-
|
123
|
-
lines = elements.map{|_tag, _time, record| record[@key] }
|
165
|
+
|
166
|
+
lines = elements.map {|_tag, _time, record| record[@key] }
|
124
167
|
new_record = {
|
125
168
|
@key => lines.join(@separator)
|
126
169
|
}
|
127
170
|
tag, time, record = elements.last
|
128
|
-
|
129
|
-
router.
|
171
|
+
message = "Flush remaining buffer: #{stream_identity}"
|
172
|
+
router.emit_error_event(tag, time, record.merge(new_record), TimeoutError.new(message))
|
130
173
|
end
|
131
174
|
@buffer.clear
|
132
175
|
end
|
176
|
+
|
177
|
+
class TimeoutTimer < Coolio::TimerWatcher
|
178
|
+
def initialize(interval, callback)
|
179
|
+
super(interval, true)
|
180
|
+
@callback = callback
|
181
|
+
end
|
182
|
+
|
183
|
+
def on_timer
|
184
|
+
@callback.call
|
185
|
+
end
|
186
|
+
end
|
133
187
|
end
|
134
188
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-concat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenji Okimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 3.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-unit-rr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Fluentd Filter plugin to concat multiple event messages
|
70
84
|
email:
|
71
85
|
- okimoto@clear-code.com
|