fluent-plugin-elb-log 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-elb-log.gemspec +1 -1
- data/lib/fluent/plugin/in_elb_log.rb +38 -36
- data/test/plugin/in_elb_log.rb +5 -1
- 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: 1072c05095bf58f28fcc18c5d2c2dd74de3b761f
|
4
|
+
data.tar.gz: a6584249f0bef727d7495870d86f70db2deb8f78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5e800e7091a55b7144ff28b99263666fcee7980f6663dcda08cd411a49d35fee6508ea64dd4b4509db351e0fc5faf35d95b0a11dd609f6257c23b07ab41f116
|
7
|
+
data.tar.gz: fc32e6358c926b332b7796b8d636a4b153dafbfab3b0f9ee40be11a75f490ae0bfa7d232e9ac62e66cf08bbfa82d2eecaa592d03c1c95bf8a816cf4ea62a8cb7
|
@@ -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-elb-log"
|
7
|
-
spec.version = "0.4.
|
7
|
+
spec.version = "0.4.3"
|
8
8
|
spec.authors = ["shinsaka"]
|
9
9
|
spec.email = ["shinx1265@gmail.com"]
|
10
10
|
spec.summary = "Amazon ELB log input plugin"
|
@@ -137,26 +137,29 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
137
137
|
"key" => object_key[:key],
|
138
138
|
"prefix" => object_key[:prefix],
|
139
139
|
"elb_timestamp_unixtime" => object_key[:elb_timestamp_unixtime],
|
140
|
+
"s3_last_modified_unixtime" => object_key[:s3_last_modified_unixtime],
|
140
141
|
}
|
141
142
|
|
142
143
|
get_file_from_s3(object_key[:key])
|
143
144
|
emit_lines_from_buffer_file(record_common)
|
144
145
|
|
145
|
-
put_timestamp_file(object_key[:
|
146
|
+
put_timestamp_file(object_key[:s3_last_modified_unixtime])
|
146
147
|
end
|
147
148
|
end
|
148
149
|
|
149
150
|
def get_object_keys(timestamp)
|
150
151
|
begin
|
151
152
|
object_keys = []
|
152
|
-
|
153
|
+
get_object_contents.each do |content|
|
154
|
+
# snip old items
|
155
|
+
s3_last_modified_unixtime = content.last_modified.to_i
|
156
|
+
next if s3_last_modified_unixtime <= timestamp
|
157
|
+
|
158
|
+
object_key = content.key
|
153
159
|
matches = LOGFILE_REGEXP.match(object_key)
|
154
160
|
next unless matches
|
155
161
|
|
156
|
-
|
157
|
-
elb_timestamp_unixtime = Time.parse(matches[:elb_timestamp]).to_i
|
158
|
-
next if elb_timestamp_unixtime <= timestamp
|
159
|
-
|
162
|
+
log.debug "matched"
|
160
163
|
log.debug object_key
|
161
164
|
object_keys << {
|
162
165
|
key: object_key,
|
@@ -168,7 +171,8 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
168
171
|
elb_timestamp: matches[:elb_timestamp],
|
169
172
|
elb_ip_address: matches[:elb_ip_address],
|
170
173
|
logfile_hash: matches[:logfile_hash],
|
171
|
-
elb_timestamp_unixtime:
|
174
|
+
elb_timestamp_unixtime: Time.parse(matches[:elb_timestamp]).to_i,
|
175
|
+
s3_last_modified_unixtime: s3_last_modified_unixtime,
|
172
176
|
}
|
173
177
|
end
|
174
178
|
return object_keys
|
@@ -177,22 +181,10 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
177
181
|
end
|
178
182
|
end
|
179
183
|
|
180
|
-
def get_object_keys_from_s3
|
181
|
-
begin
|
182
|
-
object_keys = []
|
183
|
-
get_object_contents().each do |content|
|
184
|
-
object_keys << content.key
|
185
|
-
end
|
186
|
-
return object_keys
|
187
|
-
rescue => e
|
188
|
-
log.warn "error occurred: #{e.message}"
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
184
|
def sort_object_key(src_object_keys)
|
193
185
|
begin
|
194
186
|
src_object_keys.sort do |a, b|
|
195
|
-
a[:
|
187
|
+
a[:s3_last_modified_unixtime] <=> b[:s3_last_modified_unixtime]
|
196
188
|
end
|
197
189
|
rescue => e
|
198
190
|
log.warn "error occurred: #{e.message}"
|
@@ -220,7 +212,7 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
220
212
|
contents << content
|
221
213
|
end
|
222
214
|
|
223
|
-
if !resp.is_truncated
|
215
|
+
if !resp.is_truncated
|
224
216
|
return contents
|
225
217
|
end
|
226
218
|
|
@@ -234,25 +226,35 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
234
226
|
return contents
|
235
227
|
end
|
236
228
|
|
229
|
+
def inflate(srcfile, dstfile)
|
230
|
+
File.open(dstfile, File::WRONLY|File::CREAT|File::TRUNC) do |bfile|
|
231
|
+
File.open(srcfile) do |file|
|
232
|
+
zio = file
|
233
|
+
loop do
|
234
|
+
io = Zlib::GzipReader.new zio
|
235
|
+
bfile.write io.read
|
236
|
+
unused = io.unused
|
237
|
+
io.finish
|
238
|
+
break if unused.nil?
|
239
|
+
zio.pos -= unused.length
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
237
245
|
def get_file_from_s3(object_name)
|
238
246
|
begin
|
239
247
|
log.debug "getting object from s3 name is #{object_name}"
|
240
248
|
|
241
|
-
Tempfile.create('fluent-elblog')
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
File.open(@buf_file, File::WRONLY|File::CREAT|File::TRUNC) do |bfile|
|
251
|
-
Zlib::GzipReader.open(tfile.path) do |gz|
|
252
|
-
bfile.write gz.read
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
249
|
+
tfile = Tempfile.create('fluent-elblog')
|
250
|
+
tfile.close
|
251
|
+
|
252
|
+
s3_client.get_object(bucket: @s3_bucketname, key: object_name, response_target: tfile.path)
|
253
|
+
|
254
|
+
if File.extname(object_name) != '.gz'
|
255
|
+
FileUtils.cp(tfile.path, @buf_file)
|
256
|
+
else
|
257
|
+
inflate(tfile.path, @buf_file)
|
256
258
|
end
|
257
259
|
rescue => e
|
258
260
|
log.warn "error occurred: #{e.message}, #{e.backtrace}"
|
data/test/plugin/in_elb_log.rb
CHANGED
@@ -9,7 +9,7 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
9
9
|
DEFAULT_CONFIG = {
|
10
10
|
access_key_id: 'dummy_access_key_id',
|
11
11
|
secret_access_key: 'dummy_secret_access_key',
|
12
|
-
s3_endpoint: 's3
|
12
|
+
s3_endpoint: 's3.ap-northeast-1.amazonaws.com',
|
13
13
|
s3_bucketname: 'dummy_bucket',
|
14
14
|
s3_prefix: 'test',
|
15
15
|
region: 'ap-northeast-1',
|
@@ -51,11 +51,15 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def s3bucket_ok
|
54
|
+
stub_request(:get, 'https://s3.ap-northeast-1.amazonaws.com/dummy_bucket?encoding-type=url&max-keys=1&prefix=test')
|
55
|
+
.to_return(status: 200, body: "", headers: {})
|
54
56
|
stub_request(:get, 'https://s3-ap-northeast-1.amazonaws.com/dummy_bucket?encoding-type=url&max-keys=1&prefix=test')
|
55
57
|
.to_return(status: 200, body: "", headers: {})
|
56
58
|
end
|
57
59
|
|
58
60
|
def s3bucket_not_found
|
61
|
+
stub_request(:get, 'https://s3.ap-northeast-1.amazonaws.com/dummy_bucket?encoding-type=url&max-keys=1&prefix=test')
|
62
|
+
.to_return(status: 404, body: "", headers: {})
|
59
63
|
stub_request(:get, 'https://s3-ap-northeast-1.amazonaws.com/dummy_bucket?encoding-type=url&max-keys=1&prefix=test')
|
60
64
|
.to_return(status: 404, body: "", headers: {})
|
61
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elb-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shinsaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|