fluent-plugin-elb-access-log 0.4.0 → 0.4.1

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: 1c73cb54a193ee0d843ee5d038d2f7cf4e8c7cdf
4
- data.tar.gz: 4da300a290b3d16f5eeffad7b4e5ee3ccbf66264
3
+ metadata.gz: 48b23acb9715aceaba32535f3ee24da9c672e1e0
4
+ data.tar.gz: 161ce0f55e79b042af34171060d3e4d611f6acdb
5
5
  SHA512:
6
- metadata.gz: aed16e4faac1a13e8f9138443d925645f06110cd3168df5726596549896f2242a68e241c38e062c0c898f5c494cfc4d18888070630ec64367851fd0df0a09368
7
- data.tar.gz: 2cb130b4b344352c6ebfa514288cf7705ca1c4da5893e7ff1d51594b416f34bb3d53b4bfa6c2994a837922c976a71e5e5ffda5ede54118dd3402228dc62c5a03
6
+ metadata.gz: a9542814648731d30041c6bf7c9c30bfd822d3be137429628c2eb77aae0f02a7aeda538090065f5be6825cef415c1d60b18e62c07ea3b8edd3623d5be522a03f
7
+ data.tar.gz: db0422ee4c1b5478eca4ee1531ae947685eb8584942ff264646dfa918147cce605b54625cb69e005caa90910819550a963d5adc8f8377bffa292546c31f71cb9
data/.travis.yml CHANGED
@@ -1,9 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1
4
- - 2.2
5
- - 2.3.4
6
- - 2.4.1
3
+ - 2.1.10
4
+ - 2.2.9
5
+ - 2.3.6
6
+ - 2.4.3
7
+ - 2.5.0
8
+ before_install:
9
+ - gem update --system
7
10
  script:
8
11
  - bundle install
9
12
  - bundle exec rake
data/README.md CHANGED
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
 
27
27
  ```apache
28
28
  <source>
29
- type elb_access_log
29
+ @type elb_access_log
30
30
  #aws_key_id YOUR_ACCESS_KEY_ID
31
31
  #aws_sec_key YOUR_SECRET_ACCESS_KEY
32
32
  #profile PROFILE_NAME
@@ -58,7 +58,6 @@ Or install it yourself as:
58
58
  see http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/access-log-collection.html
59
59
 
60
60
  ```json
61
- // elb.access_log:
62
61
  {
63
62
  "timestamp":"2015-05-24T08:25:36.229576Z",
64
63
  "elb":"hoge",
@@ -134,6 +134,7 @@ class Fluent::Plugin::ElbAccessLogInput < Fluent::Input
134
134
 
135
135
  def shutdown
136
136
  @loop.stop
137
+ @thread.kill
137
138
  @thread.join
138
139
  super
139
140
  end
@@ -161,16 +162,17 @@ class Fluent::Plugin::ElbAccessLogInput < Fluent::Input
161
162
  end
162
163
 
163
164
  unless @history.include?(obj.key)
164
- access_log = client.get_object(bucket: @s3_bucket, key: obj.key).body.string
165
+ access_log = client.get_object(bucket: @s3_bucket, key: obj.key).body
165
166
 
166
167
  if obj.key.end_with?('.gz')
167
168
  begin
168
- inflated = Zlib::Inflate.inflate(access_log)
169
- access_log = inflated
169
+ access_log = Zlib::GzipReader.wrap(access_log, &:read)
170
170
  rescue Zlib::Error => e
171
171
  @log.warn("#{e.message}: #{access_log.inspect.slice(0, 64)}")
172
172
  next
173
173
  end
174
+ else
175
+ access_log = access_log.string
174
176
  end
175
177
 
176
178
  emit_access_log(access_log)
@@ -1,3 +1,3 @@
1
1
  module FluentPluginElbAccessLog
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
@@ -7,6 +7,7 @@ describe Fluent::Plugin::ElbAccessLogInput do
7
7
 
8
8
  let(:fluentd_conf) do
9
9
  {
10
+ interval: 0,
10
11
  account_id: account_id,
11
12
  s3_bucket: s3_bucket,
12
13
  region: region,
@@ -48,7 +49,6 @@ describe Fluent::Plugin::ElbAccessLogInput do
48
49
  expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) { [] }
49
50
  expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
50
51
  expect(driver.instance).to_not receive(:save_timestamp).with(today)
51
- expect(driver.instance).to receive(:save_history)
52
52
  expect(driver.instance.log).to_not receive(:warn)
53
53
 
54
54
  driver_run(driver)
@@ -59,14 +59,14 @@ describe Fluent::Plugin::ElbAccessLogInput do
59
59
 
60
60
  context 'when access log exists' do
61
61
  let(:today_access_log) do
62
- Zlib::Deflate.deflate(<<-EOS)
62
+ gzip(<<-EOS)
63
63
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
64
64
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
65
65
  EOS
66
66
  end
67
67
 
68
68
  let(:tomorrow_access_log) do
69
- Zlib::Deflate.deflate(<<-EOS)
69
+ gzip(<<-EOS)
70
70
  https 2015-05-25T19: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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
71
71
  https 2015-05-25T19: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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
72
72
  EOS
@@ -94,7 +94,6 @@ https 2015-05-25T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
94
94
  end
95
95
 
96
96
  expect(driver.instance).to receive(:save_timestamp).with(tomorrow)
97
- expect(driver.instance).to receive(:save_history)
98
97
  expect(driver.instance.log).to_not receive(:warn)
99
98
 
100
99
  driver_run(driver)
@@ -260,6 +259,7 @@ https 2015-05-25T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
260
259
  context 'when sampling' do
261
260
  let(:fluentd_conf) do
262
261
  {
262
+ interval: 0,
263
263
  account_id: account_id,
264
264
  s3_bucket: s3_bucket,
265
265
  region: region,
@@ -279,7 +279,7 @@ https 2015-05-25T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
279
279
 
280
280
  context 'when include bad URI' do
281
281
  let(:today_access_log) do
282
- Zlib::Deflate.deflate(<<-EOS)
282
+ gzip(<<-EOS)
283
283
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
284
284
  EOS
285
285
  end
@@ -297,7 +297,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
297
297
  end
298
298
 
299
299
  expect(driver.instance).to receive(:save_timestamp).with(today)
300
- expect(driver.instance).to receive(:save_history)
301
300
 
302
301
  allow(Addressable::URI).to receive(:parse).and_raise('parse error')
303
302
  expect(driver.instance.log).to receive(:warn).with('parse error: http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/')
@@ -344,13 +343,14 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
344
343
 
345
344
  context 'when access log exists (with tag option)' do
346
345
  let(:today_access_log) do
347
- Zlib::Deflate.deflate(<<-EOS)
346
+ gzip(<<-EOS)
348
347
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
349
348
  EOS
350
349
  end
351
350
 
352
351
  let(:fluentd_conf) do
353
352
  {
353
+ interval: 0,
354
354
  account_id: account_id,
355
355
  s3_bucket: s3_bucket,
356
356
  region: region,
@@ -373,7 +373,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
373
373
  end
374
374
 
375
375
  expect(driver.instance).to receive(:save_timestamp).with(today)
376
- expect(driver.instance).to receive(:save_history)
377
376
  expect(driver.instance.log).to_not receive(:warn)
378
377
 
379
378
  driver_run(driver)
@@ -426,7 +425,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
426
425
 
427
426
  context 'when access old log exists' do
428
427
  let(:today_access_log) do
429
- Zlib::Deflate.deflate(<<-EOS)
428
+ gzip(<<-EOS)
430
429
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
431
430
  EOS
432
431
  end
@@ -446,7 +445,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
446
445
  end
447
446
 
448
447
  expect(driver.instance).to_not receive(:save_timestamp)
449
- expect(driver.instance).to receive(:save_history)
450
448
  expect(driver.instance.log).to_not receive(:warn)
451
449
 
452
450
  driver_run(driver)
@@ -498,7 +496,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
498
496
 
499
497
  context 'when parse error' do
500
498
  let(:today_access_log) do
501
- Zlib::Deflate.deflate(<<-EOS)
499
+ gzip(<<-EOS)
502
500
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
503
501
  EOS
504
502
  end
@@ -516,7 +514,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
516
514
  end
517
515
 
518
516
  expect(driver.instance).to receive(:save_timestamp).with(today)
519
- expect(driver.instance).to receive(:save_history)
520
517
 
521
518
  expect(CSV).to receive(:parse_line).and_raise('parse error')
522
519
  expect(driver.instance.log).to_not receive(:warn)
@@ -569,7 +566,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
569
566
 
570
567
  context 'when no user_agent' do
571
568
  let(:today_access_log) do
572
- Zlib::Deflate.deflate(<<-EOS)
569
+ gzip(<<-EOS)
573
570
  https 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"
574
571
  EOS
575
572
  end
@@ -590,7 +587,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
590
587
 
591
588
  context 'when access old log exists (timeout)' do
592
589
  let(:today_access_log) do
593
- Zlib::Deflate.deflate(<<-EOS)
590
+ gzip(<<-EOS)
594
591
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
595
592
  EOS
596
593
  end
@@ -607,7 +604,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
607
604
 
608
605
  expect(client).to_not receive(:get_object)
609
606
  expect(driver.instance).to_not receive(:save_timestamp)
610
- expect(driver.instance).to receive(:save_history)
611
607
  expect(driver.instance.log).to_not receive(:warn)
612
608
 
613
609
  driver_run(driver)
@@ -618,7 +614,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
618
614
 
619
615
  context 'when emitted log exists' do
620
616
  let(:today_access_log) do
621
- Zlib::Deflate.deflate(<<-EOS)
617
+ gzip(<<-EOS)
622
618
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
623
619
  EOS
624
620
  end
@@ -636,7 +632,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
636
632
  history = driver.instance.instance_variable_get(:@history)
637
633
  history << today_object_key
638
634
  expect(driver.instance).to_not receive(:save_timestamp)
639
- expect(driver.instance).to receive(:save_history)
640
635
  expect(driver.instance.log).to_not receive(:warn)
641
636
 
642
637
  driver_run(driver)
@@ -647,7 +642,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
647
642
 
648
643
  describe 'history#length' do
649
644
  let(:today_access_log) do
650
- Zlib::Deflate.deflate(<<-EOS)
645
+ gzip(<<-EOS)
651
646
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
652
647
  EOS
653
648
  end
@@ -667,7 +662,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
667
662
  end
668
663
 
669
664
  expect(driver.instance).to receive(:save_timestamp).with(today)
670
- expect(driver.instance).to receive(:save_history)
671
665
  expect(driver.instance.log).to_not receive(:warn)
672
666
  end
673
667
 
@@ -693,7 +687,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
693
687
 
694
688
  context 'when no user_agent' do
695
689
  let(:today_access_log) do
696
- Zlib::Deflate.deflate(<<-EOS)
690
+ gzip(<<-EOS)
697
691
  https 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" arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
698
692
  EOS
699
693
  end
@@ -711,7 +705,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
711
705
  end
712
706
 
713
707
  expect(driver.instance).to receive(:save_timestamp).with(today)
714
- expect(driver.instance).to receive(:save_history)
715
708
  expect(driver.instance.log).to_not receive(:warn)
716
709
 
717
710
  driver_run(driver)
@@ -780,18 +773,17 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
780
773
  double('today_s3_object', body: StringIO.new(today_access_log))
781
774
  end
782
775
 
783
- expect(driver.instance).to receive(:save_history)
784
776
  end
785
777
 
786
778
  specify do
787
- expect(driver.instance.log).to receive(:warn).with('incorrect header check: "https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.')
779
+ expect(driver.instance.log).to receive(:warn).with(/not in gzip format: /)
788
780
  driver_run(driver)
789
781
  end
790
782
  end
791
783
 
792
784
  context 'when bad timestamp' do
793
785
  let(:today_access_log) do
794
- Zlib::Deflate.deflate(<<-EOS)
786
+ gzip(<<-EOS)
795
787
  https xxx 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
796
788
  EOS
797
789
  end
@@ -809,7 +801,6 @@ https xxx hoge 14.14.124.20:57673 10.0.199.184:80 0.000053 0.000913 0.000036 200
809
801
  end
810
802
 
811
803
  expect(driver.instance).to receive(:save_timestamp).with(today)
812
- expect(driver.instance).to receive(:save_history)
813
804
  end
814
805
 
815
806
  specify do
@@ -821,7 +812,7 @@ https xxx hoge 14.14.124.20:57673 10.0.199.184:80 0.000053 0.000913 0.000036 200
821
812
 
822
813
  context 'when unquote fails' do
823
814
  let(:today_access_log) do
824
- Zlib::Deflate.deflate(<<-EOS)
815
+ gzip(<<-EOS)
825
816
  https 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" ssl_cipher ssl_protocol arn:aws:elasticloadbalancing:ap-northeast-1:123456789012:targetgroup/app/xxx "Root=xxx" "-" "arn:aws:acm:ap-northeast-1:123456789012:certificate/xxx"
826
817
  EOS
827
818
  end
@@ -839,7 +830,6 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
839
830
  end
840
831
 
841
832
  expect(driver.instance).to receive(:save_timestamp).with(today)
842
- expect(driver.instance).to receive(:save_history)
843
833
 
844
834
  expect(CSV).to receive(:parse_line).and_raise('parse error')
845
835
  expect(driver.instance).to receive(:unquote).and_raise('unquote error')
@@ -7,6 +7,7 @@ describe Fluent::Plugin::ElbAccessLogInput do
7
7
 
8
8
  let(:fluentd_conf) do
9
9
  {
10
+ interval: 0,
10
11
  account_id: account_id,
11
12
  s3_bucket: s3_bucket,
12
13
  region: region,
@@ -231,6 +232,7 @@ describe Fluent::Plugin::ElbAccessLogInput do
231
232
  context 'when sampling' do
232
233
  let(:fluentd_conf) do
233
234
  {
235
+ interval: 0,
234
236
  account_id: account_id,
235
237
  s3_bucket: s3_bucket,
236
238
  region: region,
@@ -314,6 +316,7 @@ describe Fluent::Plugin::ElbAccessLogInput do
314
316
 
315
317
  let(:fluentd_conf) do
316
318
  {
319
+ interval: 0,
317
320
  account_id: account_id,
318
321
  s3_bucket: s3_bucket,
319
322
  region: region,
@@ -0,0 +1,133 @@
1
+ describe 'Fluent::Plugin::ElbAccessLogInput#client' do
2
+ let(:account_id) { '123456789012' }
3
+ let(:s3_bucket) { 'my-bucket' }
4
+ let(:region) { 'us-west-1' }
5
+ let(:driver) { create_driver(fluentd_conf) }
6
+ let!(:client){ Aws::S3::Client.new(stub_responses: true) }
7
+
8
+ let(:fluentd_conf) do
9
+ {
10
+ account_id: account_id,
11
+ s3_bucket: s3_bucket,
12
+ region: region,
13
+ start_datetime: (today - 1).to_s,
14
+ }
15
+ end
16
+
17
+ let(:today) { Time.parse('2015/05/24 18:30 UTC') }
18
+ let(:yesterday) { today - 86400 }
19
+ let(:tomorrow) { today + 86400 }
20
+
21
+ let(:today_prefix) { "AWSLogs/#{account_id}/elasticloadbalancing/#{region}/#{today.strftime('%Y/%m/%d')}/" }
22
+ let(:yesterday_prefix) { "AWSLogs/#{account_id}/elasticloadbalancing/#{region}/#{yesterday.strftime('%Y/%m/%d')}/" }
23
+ let(:tomorrow_prefix) { "AWSLogs/#{account_id}/elasticloadbalancing/#{region}/#{tomorrow.strftime('%Y/%m/%d')}/" }
24
+
25
+ let(:today_object_key) { "#{today_prefix}#{account_id}_elasticloadbalancing_ap-northeast-1_hoge_#{today.iso8601}_52.68.51.1_8hSqR3o4.log" }
26
+ let(:yesterday_object_key) { "#{yesterday_prefix}#{account_id}_elasticloadbalancing_ap-northeast-1_hoge_#{yesterday.iso8601}_52.68.51.1_8hSqR3o4.log" }
27
+ let(:tomorrow_object_key) { "#{tomorrow_prefix}#{account_id}_elasticloadbalancing_ap-northeast-1_hoge_#{tomorrow.iso8601}_52.68.51.1_8hSqR3o4.log" }
28
+
29
+ before do
30
+ Timecop.freeze(today)
31
+ allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:load_history) { [] }
32
+ allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:parse_tsfile) { nil }
33
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
34
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) { [] }
35
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
36
+ allow(FileUtils).to receive(:touch)
37
+ expect(driver.instance).to_not receive(:save_timestamp).with(today)
38
+ expect(driver.instance).to receive(:save_history)
39
+ expect(driver.instance.log).to_not receive(:error)
40
+ expect(driver.instance.log).to_not receive(:warn)
41
+ end
42
+
43
+ after do
44
+ Timecop.return
45
+ end
46
+
47
+ context 'when create client without credentials' do
48
+ specify do
49
+ expect(Aws::S3::Client).to receive(:new).with(
50
+ region: region,
51
+ user_agent_suffix: Fluent::Plugin::ElbAccessLogInput::USER_AGENT_SUFFIX,
52
+ ).and_return(client)
53
+
54
+ driver_run(driver)
55
+ end
56
+ end
57
+
58
+ context 'when create client with aws_key_id/aws_sec_key' do
59
+ let(:aws_key_id) { 'akid' }
60
+ let(:aws_sec_key) { 'secret' }
61
+
62
+ let(:fluentd_conf) do
63
+ {
64
+ account_id: account_id,
65
+ s3_bucket: s3_bucket,
66
+ region: region,
67
+ start_datetime: (today - 1).to_s,
68
+ aws_key_id: aws_key_id,
69
+ aws_sec_key: aws_sec_key,
70
+ }
71
+ end
72
+
73
+ specify do
74
+ expect(Aws::S3::Client).to receive(:new).with(
75
+ region: region,
76
+ user_agent_suffix: Fluent::Plugin::ElbAccessLogInput::USER_AGENT_SUFFIX,
77
+ access_key_id: aws_key_id,
78
+ secret_access_key: aws_sec_key,
79
+ ).and_return(client)
80
+
81
+ driver_run(driver)
82
+ end
83
+ end
84
+
85
+ context 'when create client with profile/credentials_path' do
86
+ let(:profile) { 'my-profile' }
87
+ let(:credentials_path) { '/foo/bar/zoo' }
88
+
89
+ let(:fluentd_conf) do
90
+ {
91
+ account_id: account_id,
92
+ s3_bucket: s3_bucket,
93
+ region: region,
94
+ start_datetime: (today - 1).to_s,
95
+ profile: profile,
96
+ credentials_path: credentials_path,
97
+ }
98
+ end
99
+
100
+ specify do
101
+ expect(Aws::S3::Client).to receive(:new) do |options|
102
+ credentials = options.fetch(:credentials)
103
+ expect(credentials.profile_name).to eq profile
104
+ expect(credentials.path).to eq credentials_path
105
+ client
106
+ end
107
+
108
+ driver_run(driver)
109
+ end
110
+ end
111
+
112
+ context 'when create client with debug' do
113
+ let(:fluentd_conf) do
114
+ {
115
+ account_id: account_id,
116
+ s3_bucket: s3_bucket,
117
+ region: region,
118
+ start_datetime: (today - 1).to_s,
119
+ debug: true,
120
+ }
121
+ end
122
+
123
+ specify do
124
+ expect(Aws::S3::Client).to receive(:new) do |options|
125
+ expect(options.fetch(:log_level)).to eq :debug
126
+ expect(options.fetch(:logger)).to be_a(Logger)
127
+ client
128
+ end
129
+
130
+ driver_run(driver)
131
+ end
132
+ end
133
+ end
data/spec/spec_helper.rb CHANGED
@@ -47,9 +47,20 @@ def driver_run(driver)
47
47
  driver.run do
48
48
  coolio_loop = driver.instance.instance_variable_get(:@loop)
49
49
  sleep 0.1 until coolio_loop.instance_variable_get(:@running)
50
+ sleep 0.1
50
51
  end
51
52
  end
52
53
 
54
+ def gzip(str)
55
+ io = StringIO.new
56
+
57
+ Zlib::GzipWriter.wrap(io) do |gz|
58
+ gz << str
59
+ end
60
+
61
+ io.string
62
+ end
63
+
53
64
  # prevent Test::Unit's AutoRunner from executing during RSpec's rake task
54
65
  # ref: https://github.com/rspec/rspec-rails/issues/1171
55
66
  Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-28 00:00:00.000000000 Z
11
+ date: 2017-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -171,6 +171,7 @@ files:
171
171
  - lib/fluent_plugin_elb_access_log/version.rb
172
172
  - spec/in_elb_access_log_alb_spec.rb
173
173
  - spec/in_elb_access_log_clb_spec.rb
174
+ - spec/in_elb_access_log_client_spec.rb
174
175
  - spec/in_elb_access_log_config_spec.rb
175
176
  - spec/spec_helper.rb
176
177
  homepage: https://github.com/winebarrel/fluent-plugin-elb-access-log
@@ -200,5 +201,6 @@ summary: Fluentd input plugin for AWS ELB Access Logs.
200
201
  test_files:
201
202
  - spec/in_elb_access_log_alb_spec.rb
202
203
  - spec/in_elb_access_log_clb_spec.rb
204
+ - spec/in_elb_access_log_client_spec.rb
203
205
  - spec/in_elb_access_log_config_spec.rb
204
206
  - spec/spec_helper.rb