fluent-plugin-elb-log 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71fea708525f12dea801f2e95871eae3e3361faa
4
- data.tar.gz: b43655a000f3509012cfb5530839ca88c5201fcc
3
+ metadata.gz: 1072c05095bf58f28fcc18c5d2c2dd74de3b761f
4
+ data.tar.gz: a6584249f0bef727d7495870d86f70db2deb8f78
5
5
  SHA512:
6
- metadata.gz: a6e9a47ae3fd4cc4bc25e2c6b702bdcf6524b998f8844d7afa22f86fbb22e3220e984f4e44092a333112f64f5b081fcd8f42f174ccdbe99e3bf0770864292f15
7
- data.tar.gz: c2654c3fc22772b407fe9ca0d06022373544e0011782b5d29f32c662b4b30a344d0fe8b8b991b0a3c0a2e0285842ba87609f3f8e075b2e9e415ca2304c32042f
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.2"
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[:elb_timestamp_unixtime])
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
- get_object_keys_from_s3.each do |object_key|
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
- # snip old items
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: 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[:elb_timestamp_unixtime] <=> b[:elb_timestamp_unixtime]
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') do |tfile|
242
- s3_client.get_object(bucket: @s3_bucketname, key: object_name) do |chunk|
243
- tfile.write(chunk)
244
- end
245
- tfile.close
246
-
247
- if File.extname(object_name) != '.gz'
248
- FileUtils.cp(tfile.path, @buf_file)
249
- else
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}"
@@ -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-ap-northeast-1.amazonaws.com',
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.2
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-16 00:00:00.000000000 Z
11
+ date: 2017-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd