fluent-plugin-elb-access-log 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa61c99c73fe15d923591e28868b58ac63537fbe
4
- data.tar.gz: 8fd24f9385d67df78c65b1396f7007e835544d50
3
+ metadata.gz: 797ad8f847603d045b5eca038c0f5afed8730332
4
+ data.tar.gz: cf272aa08b78a320f4b5845d2be210ad7df91272
5
5
  SHA512:
6
- metadata.gz: bfdb323b0785cc474b96f6019f6932a80658d3ba4c33713fea5d294e7582f607018ee04cc1640d9eb8eac306cc907bdf612b7498f030a2725eaa6d7f1ebd8ee3
7
- data.tar.gz: 5d755876a4d9c871751e66fa0a51d9ec2d2ed97000ed658cbb4fbd16ffb38ad7ac012aee0cda94692116e95cdf5ec9e37981b4cb73d309b824f432ae2eecdfd6
6
+ metadata.gz: 059252da8f5468d7e579f9edf8beab4cd14b20f55a99a8bce0e9aede7cbf30e5253ba66ac67b2872b145b678bc9762bb0cfdc42641ff1c4c7ee3ebb8545f7ca3
7
+ data.tar.gz: 73fa7e9b2e49b46bc6a45db1a932521fd137a42d6fe4c0c5e3fc88634ee265fcae99b247cddce55ec1a21bcf410e69ef35e9d8e1f1a2cbe5a87d70099efd370a
data/README.md CHANGED
@@ -41,6 +41,8 @@ Or install it yourself as:
41
41
  #tsfile_path /var/tmp/fluent-plugin-elb-access-log.ts
42
42
  #interval 300
43
43
  #start_datetime 2015/05/24 17:00
44
+ #buffer_sec 600
45
+ #history_length 100
44
46
  #debug false
45
47
  </source>
46
48
  ```
@@ -42,6 +42,8 @@ class Fluent::ElbAccessLogInput < Fluent::Input
42
42
  config_param :tsfile_path, :string, :default => '/var/tmp/fluent-plugin-elb-access-log.ts'
43
43
  config_param :interval, :time, :default => 300
44
44
  config_param :start_datetime, :string, :default => nil
45
+ config_param :buffer_sec, :time, :default => 600
46
+ config_param :history_length, :integer, :default => 100
45
47
  config_param :debug, :bool, :default => false
46
48
 
47
49
  def initialize
@@ -64,6 +66,8 @@ class Fluent::ElbAccessLogInput < Fluent::Input
64
66
  else
65
67
  @start_datetime = Time.parse(File.read(@tsfile_path)).utc rescue Time.now.utc
66
68
  end
69
+
70
+ @history = []
67
71
  end
68
72
 
69
73
  def start
@@ -78,10 +82,14 @@ class Fluent::ElbAccessLogInput < Fluent::Input
78
82
  timer = TimerWatcher.new(@interval, true, log) do
79
83
  new_timestamp = fetch(timestamp)
80
84
 
81
- if timestamp != new_timestamp
85
+ if new_timestamp > timestamp
82
86
  save_timestamp(new_timestamp)
83
87
  timestamp = new_timestamp
84
88
  end
89
+
90
+ if @history.length > @history_length
91
+ @history.shift(history.length - @history_length)
92
+ end
85
93
  end
86
94
 
87
95
  @loop.attach(timer)
@@ -111,13 +119,16 @@ class Fluent::ElbAccessLogInput < Fluent::Input
111
119
  account_id, logfile_const, region, elb_name, logfile_datetime, ip, logfile_suffix = obj.key.split('_', 7)
112
120
  logfile_datetime = Time.parse(logfile_datetime)
113
121
 
114
- if logfile_suffix !~ /\.log\z/ or logfile_datetime <= timestamp
122
+ if logfile_suffix !~ /\.log\z/ or logfile_datetime <= (timestamp - @buffer_sec)
115
123
  next
116
124
  end
117
125
 
118
- access_log = client.get_object(bucket: @s3_bucket, key: obj.key).first.body.string
119
- emit_access_log(access_log)
120
- last_timestamp = logfile_datetime
126
+ unless @history.include?(obj.key)
127
+ access_log = client.get_object(bucket: @s3_bucket, key: obj.key).first.body.string
128
+ emit_access_log(access_log)
129
+ last_timestamp = logfile_datetime
130
+ @history.push(obj.key)
131
+ end
121
132
  end
122
133
  end
123
134
  end
@@ -1,3 +1,3 @@
1
1
  module FluentPluginElbAccessLog
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -36,6 +36,8 @@ describe 'Fluent::ElbAccessLogInput#configure' do
36
36
  expect(driver.instance.tsfile_path).to eq '/var/tmp/fluent-plugin-elb-access-log.ts'
37
37
  expect(driver.instance.interval).to eq 300
38
38
  expect(driver.instance.start_datetime).to eq today
39
+ expect(driver.instance.buffer_sec).to eq 600
40
+ expect(driver.instance.history_length).to eq 100
39
41
  expect(driver.instance.debug).to be_falsey
40
42
  end
41
43
  end
@@ -51,6 +53,8 @@ describe 'Fluent::ElbAccessLogInput#configure' do
51
53
  let(:tsfile_path) { '/tmp/foo' }
52
54
  let(:interval) { 500 }
53
55
  let(:start_datetime) { today - 3600 }
56
+ let(:buffer_sec) { 1200 }
57
+ let(:history_length) { 200 }
54
58
 
55
59
  let(:fluentd_conf) do
56
60
  {
@@ -67,6 +71,8 @@ describe 'Fluent::ElbAccessLogInput#configure' do
67
71
  tsfile_path: tsfile_path,
68
72
  interval: interval,
69
73
  start_datetime: start_datetime,
74
+ buffer_sec: buffer_sec,
75
+ history_length: history_length,
70
76
  debug: true,
71
77
  }
72
78
  end
@@ -84,6 +90,8 @@ describe 'Fluent::ElbAccessLogInput#configure' do
84
90
  expect(driver.instance.tsfile_path).to eq tsfile_path
85
91
  expect(driver.instance.interval).to eq interval
86
92
  expect(driver.instance.start_datetime).to eq start_datetime
93
+ expect(driver.instance.buffer_sec).to eq buffer_sec
94
+ expect(driver.instance.history_length).to eq history_length
87
95
  expect(driver.instance.debug).to be_truthy
88
96
  end
89
97
  end
@@ -225,15 +225,15 @@ describe Fluent::ElbAccessLogInput do
225
225
  EOS
226
226
  end
227
227
 
228
- let(:fluentd_conf) do
229
- {
230
- account_id: account_id,
231
- s3_bucket: s3_bucket,
232
- region: region,
233
- start_datetime: (today - 1).to_s,
234
- tag: 'any.tag'
235
- }
236
- end
228
+ let(:fluentd_conf) do
229
+ {
230
+ account_id: account_id,
231
+ s3_bucket: s3_bucket,
232
+ region: region,
233
+ start_datetime: (today - 1).to_s,
234
+ tag: 'any.tag'
235
+ }
236
+ end
237
237
 
238
238
  before do
239
239
  expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
@@ -287,4 +287,119 @@ describe Fluent::ElbAccessLogInput do
287
287
 
288
288
  it { is_expected.to eq expected_emits }
289
289
  end
290
+
291
+ context 'when access old log exists' do
292
+ let(:today_access_log) do
293
+ <<-EOS
294
+ 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.000053 0.000913 0.000036 200 200 0 3 "GET http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/ HTTP/1.1" "curl/7.30.0" - -
295
+ EOS
296
+ end
297
+
298
+ let(:today_object_key) { "#{today_prefix}#{account_id}_elasticloadbalancing_ap-northeast-1_hoge_#{(today - 600).iso8601}_52.68.51.1_8hSqR3o4.log" }
299
+
300
+ before do
301
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
302
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
303
+
304
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
305
+ [double('today_objects', contents: [double('today_object', key: today_object_key)])]
306
+ end
307
+
308
+ expect(client).to receive(:get_object).with(bucket: s3_bucket, key: today_object_key) do
309
+ [double('today_s3_object', body: StringIO.new(today_access_log))]
310
+ end
311
+
312
+ expect(driver.instance).to_not receive(:save_timestamp)
313
+
314
+ driver.run
315
+ end
316
+
317
+ let(:expected_emits) do
318
+ [["elb.access_log",
319
+ Time.parse('2015-05-24 19:55:36 UTC').to_i,
320
+ {"timestamp"=>"2015-05-24T19:55:36.000000Z",
321
+ "elb"=>"hoge",
322
+ "client"=>"14.14.124.20",
323
+ "client_port"=>57673,
324
+ "backend"=>"10.0.199.184",
325
+ "backend_port"=>80,
326
+ "request_processing_time"=>5.3e-05,
327
+ "backend_processing_time"=>0.000913,
328
+ "response_processing_time"=>3.6e-05,
329
+ "elb_status_code"=>200,
330
+ "backend_status_code"=>200,
331
+ "received_bytes"=>0,
332
+ "sent_bytes"=>3,
333
+ "request"=>
334
+ "GET http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/ HTTP/1.1",
335
+ "request.method"=>"GET",
336
+ "request.uri"=>
337
+ "http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/",
338
+ "request.http_version"=>"HTTP/1.1",
339
+ "request.uri.scheme"=>"http",
340
+ "request.uri.userinfo"=>nil,
341
+ "request.uri.host"=>"hoge-1876938939.ap-northeast-1.elb.amazonaws.com",
342
+ "request.uri.port"=>80,
343
+ "request.uri.registry"=>nil,
344
+ "request.uri.path"=>"/",
345
+ "request.uri.opaque"=>nil,
346
+ "request.uri.query"=>nil,
347
+ "request.uri.fragment"=>nil}]]
348
+ end
349
+
350
+ it { is_expected.to eq expected_emits }
351
+ end
352
+
353
+ context 'when access old log exists (timeout)' do
354
+ let(:today_access_log) do
355
+ <<-EOS
356
+ 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.000053 0.000913 0.000036 200 200 0 3 "GET http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/ HTTP/1.1" "curl/7.30.0" - -
357
+ EOS
358
+ end
359
+
360
+ let(:today_object_key) { "#{today_prefix}#{account_id}_elasticloadbalancing_ap-northeast-1_hoge_#{(today - 601).iso8601}_52.68.51.1_8hSqR3o4.log" }
361
+
362
+ before do
363
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
364
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
365
+
366
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
367
+ [double('today_objects', contents: [double('today_object', key: today_object_key)])]
368
+ end
369
+
370
+ expect(client).to_not receive(:get_object)
371
+ expect(driver.instance).to_not receive(:save_timestamp)
372
+
373
+ driver.run
374
+ end
375
+
376
+ it { is_expected.to be_empty }
377
+ end
378
+
379
+ context 'when emitted log exists' do
380
+ let(:today_access_log) do
381
+ <<-EOS
382
+ 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.000053 0.000913 0.000036 200 200 0 3 "GET http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/ HTTP/1.1" "curl/7.30.0" - -
383
+ EOS
384
+ end
385
+
386
+ before do
387
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
388
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
389
+
390
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
391
+ [double('today_objects', contents: [double('today_object', key: today_object_key)])]
392
+ end
393
+
394
+ expect(client).to_not receive(:get_object)
395
+
396
+ history = driver.instance.instance_variable_get(:@history)
397
+ history << today_object_key
398
+ expect(driver.instance).to_not receive(:save_timestamp)
399
+
400
+ driver.run
401
+ end
402
+
403
+ it { is_expected.to be_empty }
404
+ end
290
405
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-elb-access-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-25 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd