fluent-plugin-elb-access-log 0.1.8 → 0.2.0

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: 96510ed8b34e1025ead147d989eefc4459404ae8
4
- data.tar.gz: f44e0a4c33aa20267fa604fe181f1861c24b1ed5
3
+ metadata.gz: 08f77efb6afe4e6a4ff1e3c2d9fb956eb4cbb5a5
4
+ data.tar.gz: 5f4249955cf58fc6c77c7281a1911014e7572940
5
5
  SHA512:
6
- metadata.gz: a0375b94759d747d2f3bbdf0cec1b048cb1ec81149f1db9f111edc66726563b4cb75316ecb45a3c87b248ae8215076f0b32b00457779aacb3c04e6b635d2d495
7
- data.tar.gz: 573db4ec038fb669d091e4125a7f09d0c485d619f28db67aea3e120f2439d9d9386d1f065790ebd085bd0f1e90c286fde90b224c95f56182474abc5ed8453a4f
6
+ metadata.gz: c5216d607dce35496ecc0a1ee43472d38932b70b8dacf4b2d1e0d7284e6eaac3297948edb87f4660fc75570e1650b84d0a49eeabecf37c94743fe3dfcda4faaf
7
+ data.tar.gz: 7936a97c6014943af80f42ecb952672012957d5d8a4de93327e0d2ebaa4d98821cb01b1ed82d0d12edc5f66996e699bd89f58bd9fc3c28054ed3dbf4eb99180b
data/README.md CHANGED
@@ -39,6 +39,7 @@ Or install it yourself as:
39
39
 
40
40
  #tag elb.access_log
41
41
  #tsfile_path /var/tmp/fluent-plugin-elb-access-log.ts
42
+ #histfile_path /var/tmp/fluent-plugin-elb-access-log.history
42
43
  #interval 300
43
44
  #start_datetime 2015/05/24 17:00
44
45
  #buffer_sec 600
@@ -40,6 +40,7 @@ class Fluent::ElbAccessLogInput < Fluent::Input
40
40
  config_param :s3_prefix, :string, :default => nil
41
41
  config_param :tag, :string, :default => 'elb.access_log'
42
42
  config_param :tsfile_path, :string, :default => '/var/tmp/fluent-plugin-elb-access-log.ts'
43
+ config_param :histfile_path, :string, :default => '/var/tmp/fluent-plugin-elb-access-log.history'
43
44
  config_param :interval, :time, :default => 300
44
45
  config_param :start_datetime, :string, :default => nil
45
46
  config_param :buffer_sec, :time, :default => 600
@@ -61,6 +62,7 @@ class Fluent::ElbAccessLogInput < Fluent::Input
61
62
  super
62
63
 
63
64
  FileUtils.touch(@tsfile_path)
65
+ FileUtils.touch(@histfile_path)
64
66
 
65
67
  if @start_datetime
66
68
  @start_datetime = Time.parse(@start_datetime).utc
@@ -68,7 +70,7 @@ class Fluent::ElbAccessLogInput < Fluent::Input
68
70
  @start_datetime = Time.parse(File.read(@tsfile_path)).utc rescue Time.now.utc
69
71
  end
70
72
 
71
- @history = []
73
+ @history = load_history
72
74
  end
73
75
 
74
76
  def start
@@ -91,6 +93,8 @@ class Fluent::ElbAccessLogInput < Fluent::Input
91
93
  if @history.length > @history_length
92
94
  @history.shift(@history.length - @history_length)
93
95
  end
96
+
97
+ save_history
94
98
  end
95
99
 
96
100
  @loop.attach(timer)
@@ -205,6 +209,16 @@ class Fluent::ElbAccessLogInput < Fluent::Input
205
209
  end
206
210
  end
207
211
 
212
+ def load_history
213
+ File.read(@histfile_path).split("\n")
214
+ end
215
+
216
+ def save_history
217
+ open(@histfile_path, 'w') do |histfile|
218
+ histfile << @history.join("\n")
219
+ end
220
+ end
221
+
208
222
  def client
209
223
  return @client if @client
210
224
 
@@ -1,3 +1,3 @@
1
1
  module FluentPluginElbAccessLog
2
- VERSION = '0.1.8'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -11,6 +11,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
11
11
  Timecop.freeze(today)
12
12
  allow(FileUtils).to receive(:touch)
13
13
  allow(File).to receive(:read) { nil }
14
+ allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:load_history) { [] }
14
15
  end
15
16
 
16
17
  context 'when default' do
@@ -34,6 +35,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
34
35
  expect(driver.instance.s3_prefix).to be_nil
35
36
  expect(driver.instance.tag).to eq 'elb.access_log'
36
37
  expect(driver.instance.tsfile_path).to eq '/var/tmp/fluent-plugin-elb-access-log.ts'
38
+ expect(driver.instance.histfile_path).to eq '/var/tmp/fluent-plugin-elb-access-log.history'
37
39
  expect(driver.instance.interval).to eq 300
38
40
  expect(driver.instance.start_datetime).to eq today
39
41
  expect(driver.instance.buffer_sec).to eq 600
@@ -52,6 +54,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
52
54
  let(:s3_prefix) { 's3-prefix' }
53
55
  let(:tag) { 'any.tag' }
54
56
  let(:tsfile_path) { '/tmp/foo' }
57
+ let(:histfile_path) { '/tmp/bar' }
55
58
  let(:interval) { 500 }
56
59
  let(:start_datetime) { today - 3600 }
57
60
  let(:buffer_sec) { 1200 }
@@ -71,6 +74,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
71
74
  s3_prefix: s3_prefix,
72
75
  tag: tag,
73
76
  tsfile_path: tsfile_path,
77
+ histfile_path: histfile_path,
74
78
  interval: interval,
75
79
  start_datetime: start_datetime,
76
80
  buffer_sec: buffer_sec,
@@ -91,6 +95,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
91
95
  expect(driver.instance.s3_prefix).to eq s3_prefix
92
96
  expect(driver.instance.tag).to eq tag
93
97
  expect(driver.instance.tsfile_path).to eq tsfile_path
98
+ expect(driver.instance.histfile_path).to eq histfile_path
94
99
  expect(driver.instance.interval).to eq interval
95
100
  expect(driver.instance.start_datetime).to eq start_datetime
96
101
  expect(driver.instance.buffer_sec).to eq buffer_sec
@@ -29,6 +29,7 @@ describe Fluent::ElbAccessLogInput do
29
29
  before do
30
30
  Timecop.freeze(today)
31
31
  allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:client) { client }
32
+ allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:load_history) { [] }
32
33
  allow(FileUtils).to receive(:touch)
33
34
  end
34
35
 
@@ -44,6 +45,7 @@ describe Fluent::ElbAccessLogInput do
44
45
  expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) { [] }
45
46
  expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
46
47
  expect(driver.instance).to_not receive(:save_timestamp).with(today)
48
+ expect(driver.instance).to receive(:save_history)
47
49
 
48
50
  driver.run
49
51
  end
@@ -88,6 +90,7 @@ describe Fluent::ElbAccessLogInput do
88
90
  end
89
91
 
90
92
  expect(driver.instance).to receive(:save_timestamp).with(tomorrow)
93
+ expect(driver.instance).to receive(:save_history)
91
94
 
92
95
  driver.run
93
96
  end
@@ -391,6 +394,7 @@ describe Fluent::ElbAccessLogInput do
391
394
  end
392
395
 
393
396
  expect(driver.instance).to receive(:save_timestamp).with(today)
397
+ expect(driver.instance).to receive(:save_history)
394
398
 
395
399
  driver.run
396
400
  end
@@ -453,6 +457,7 @@ describe Fluent::ElbAccessLogInput do
453
457
  end
454
458
 
455
459
  expect(driver.instance).to_not receive(:save_timestamp)
460
+ expect(driver.instance).to receive(:save_history)
456
461
 
457
462
  driver.run
458
463
  end
@@ -512,6 +517,7 @@ describe Fluent::ElbAccessLogInput do
512
517
 
513
518
  expect(client).to_not receive(:get_object)
514
519
  expect(driver.instance).to_not receive(:save_timestamp)
520
+ expect(driver.instance).to receive(:save_history)
515
521
 
516
522
  driver.run
517
523
  end
@@ -539,6 +545,7 @@ describe Fluent::ElbAccessLogInput do
539
545
  history = driver.instance.instance_variable_get(:@history)
540
546
  history << today_object_key
541
547
  expect(driver.instance).to_not receive(:save_timestamp)
548
+ expect(driver.instance).to receive(:save_history)
542
549
 
543
550
  driver.run
544
551
  end
@@ -568,6 +575,7 @@ describe Fluent::ElbAccessLogInput do
568
575
  end
569
576
 
570
577
  expect(driver.instance).to receive(:save_timestamp).with(today)
578
+ expect(driver.instance).to receive(:save_history)
571
579
  end
572
580
 
573
581
  subject { history.length }
metadata CHANGED
@@ -1,7 +1,7 @@
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.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara