fluent-plugin-elb-access-log 0.3.7 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.simplecov +4 -0
- data/README.md +5 -1
- data/fluent-plugin-elb-access-log.gemspec +1 -1
- data/lib/fluent/plugin/in_elb_access_log.rb +32 -49
- data/lib/fluent_plugin_elb_access_log/version.rb +1 -1
- data/spec/in_elb_access_log_alb_spec.rb +107 -17
- data/spec/in_elb_access_log_clb_spec.rb +50 -18
- data/spec/in_elb_access_log_config_spec.rb +5 -5
- data/spec/spec_helper.rb +12 -12
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c73cb54a193ee0d843ee5d038d2f7cf4e8c7cdf
|
4
|
+
data.tar.gz: 4da300a290b3d16f5eeffad7b4e5ee3ccbf66264
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aed16e4faac1a13e8f9138443d925645f06110cd3168df5726596549896f2242a68e241c38e062c0c898f5c494cfc4d18888070630ec64367851fd0df0a09368
|
7
|
+
data.tar.gz: 2cb130b4b344352c6ebfa514288cf7705ca1c4da5893e7ff1d51594b416f34bb3d53b4bfa6c2994a837922c976a71e5e5ffda5ede54118dd3402228dc62c5a03
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.simplecov
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# fluent-plugin-elb-access-log
|
2
2
|
|
3
|
-
Fluentd input plugin for
|
3
|
+
Fluentd input plugin for AWS ELB Access Logs.
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/fluent-plugin-elb-access-log.svg)](http://badge.fury.io/rb/fluent-plugin-elb-access-log)
|
6
6
|
[![Build Status](https://travis-ci.org/winebarrel/fluent-plugin-elb-access-log.svg?branch=master)](https://travis-ci.org/winebarrel/fluent-plugin-elb-access-log)
|
@@ -55,6 +55,8 @@ Or install it yourself as:
|
|
55
55
|
|
56
56
|
### CLB
|
57
57
|
|
58
|
+
see http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/access-log-collection.html
|
59
|
+
|
58
60
|
```json
|
59
61
|
// elb.access_log:
|
60
62
|
{
|
@@ -90,6 +92,8 @@ Or install it yourself as:
|
|
90
92
|
|
91
93
|
### ALB
|
92
94
|
|
95
|
+
see http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html
|
96
|
+
|
93
97
|
```json
|
94
98
|
{
|
95
99
|
"type": "https",
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'fluentd'
|
21
|
+
spec.add_dependency 'fluentd', '>= 0.14'
|
22
22
|
spec.add_dependency 'aws-sdk-s3', '~> 1.8'
|
23
23
|
spec.add_dependency 'addressable'
|
24
24
|
spec.add_development_dependency 'bundler'
|
@@ -1,7 +1,15 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'logger'
|
4
|
+
require 'time'
|
5
|
+
require 'addressable/uri'
|
6
|
+
require 'aws-sdk-s3'
|
7
|
+
require 'zlib'
|
8
|
+
|
1
9
|
require 'fluent/input'
|
2
10
|
require 'fluent_plugin_elb_access_log/version'
|
3
11
|
|
4
|
-
class Fluent::ElbAccessLogInput < Fluent::Input
|
12
|
+
class Fluent::Plugin::ElbAccessLogInput < Fluent::Input
|
5
13
|
Fluent::Plugin.register_input('elb_access_log', self)
|
6
14
|
|
7
15
|
USER_AGENT_SUFFIX = "fluent-plugin-elb-access-log/#{FluentPluginElbAccessLog::VERSION}"
|
@@ -52,14 +60,6 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
52
60
|
|
53
61
|
ELB_TYPES = %(clb alb)
|
54
62
|
|
55
|
-
unless method_defined?(:log)
|
56
|
-
define_method('log') { $log }
|
57
|
-
end
|
58
|
-
|
59
|
-
unless method_defined?(:router)
|
60
|
-
define_method('router') { Fluent::Engine }
|
61
|
-
end
|
62
|
-
|
63
63
|
config_param :elb_type, :string, default: 'clb'
|
64
64
|
config_param :aws_key_id, :string, default: nil, secret: true
|
65
65
|
config_param :aws_sec_key, :string, default: nil, secret: true
|
@@ -80,17 +80,6 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
80
80
|
config_param :sampling_interval, :integer, default: 1
|
81
81
|
config_param :debug, :bool, default: false
|
82
82
|
|
83
|
-
def initialize
|
84
|
-
super
|
85
|
-
require 'csv'
|
86
|
-
require 'fileutils'
|
87
|
-
require 'logger'
|
88
|
-
require 'time'
|
89
|
-
require 'addressable/uri'
|
90
|
-
require 'aws-sdk-s3'
|
91
|
-
require 'zlib'
|
92
|
-
end
|
93
|
-
|
94
83
|
def configure(conf)
|
95
84
|
super
|
96
85
|
|
@@ -212,8 +201,13 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
212
201
|
records = parse_log(access_log)
|
213
202
|
|
214
203
|
records.each do |record|
|
215
|
-
|
216
|
-
|
204
|
+
begin
|
205
|
+
time = Time.parse(record['timestamp'])
|
206
|
+
router.emit(@tag, time.to_i, record)
|
207
|
+
rescue ArgumentError => e
|
208
|
+
@log.warn("#{e.message}: #{record}")
|
209
|
+
@log.warn('A record that has bad timestamp is not emitted.')
|
210
|
+
end
|
217
211
|
end
|
218
212
|
end
|
219
213
|
|
@@ -226,9 +220,6 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
226
220
|
line = parse_clb_line(line)
|
227
221
|
when 'alb'
|
228
222
|
line = parse_alb_line(line)
|
229
|
-
else
|
230
|
-
# It is a bug if an exception is thrown
|
231
|
-
raise 'must not happen'
|
232
223
|
end
|
233
224
|
|
234
225
|
parsed_access_log << line if line
|
@@ -238,32 +229,24 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
238
229
|
access_log_fields = ACCESS_LOG_FIELDS.fetch(@elb_type)
|
239
230
|
|
240
231
|
parsed_access_log.each do |row|
|
241
|
-
|
242
|
-
record = Hash[access_log_fields.keys.zip(row)]
|
232
|
+
record = Hash[access_log_fields.keys.zip(row)]
|
243
233
|
|
244
|
-
|
245
|
-
|
246
|
-
|
234
|
+
access_log_fields.each do |name, conv|
|
235
|
+
record[name] = record[name].send(conv) if conv
|
236
|
+
end
|
247
237
|
|
248
|
-
|
238
|
+
split_address_port!(record, 'client')
|
249
239
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
# It is a bug if an exception is thrown
|
257
|
-
raise 'must not happen'
|
258
|
-
end
|
240
|
+
case @elb_type
|
241
|
+
when 'clb'
|
242
|
+
split_address_port!(record, 'backend')
|
243
|
+
when 'alb'
|
244
|
+
split_address_port!(record, 'target')
|
245
|
+
end
|
259
246
|
|
260
|
-
|
247
|
+
parse_request!(record)
|
261
248
|
|
262
|
-
|
263
|
-
rescue ArgumentError => e
|
264
|
-
@log.warn("#{e.message}: #{row}")
|
265
|
-
@log.warn('A record that has bad timestamp is not emitted.')
|
266
|
-
end
|
249
|
+
records << record
|
267
250
|
end
|
268
251
|
|
269
252
|
records
|
@@ -289,7 +272,7 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
289
272
|
parsed[13] = ssl_cipher
|
290
273
|
parsed[14] = ssl_protocol
|
291
274
|
rescue => e2
|
292
|
-
@log.warn("#{e.message}: #{line}")
|
275
|
+
@log.warn("#{e.message}: #{e2.message}: #{line}")
|
293
276
|
end
|
294
277
|
end
|
295
278
|
|
@@ -320,7 +303,7 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
320
303
|
parsed[18] = unquote(domain_name)
|
321
304
|
parsed[19] = unquote(chosen_cert_arn)
|
322
305
|
rescue => e2
|
323
|
-
@log.warn("#{e.message}: #{line}")
|
306
|
+
@log.warn("#{e.message}: #{e2.message}: #{line}")
|
324
307
|
end
|
325
308
|
end
|
326
309
|
|
@@ -443,4 +426,4 @@ class Fluent::ElbAccessLogInput < Fluent::Input
|
|
443
426
|
@log.error_backtrace(e.backtrace)
|
444
427
|
end
|
445
428
|
end # TimerWatcher
|
446
|
-
end # Fluent::ElbAccessLogInput
|
429
|
+
end # Fluent::Plugin::ElbAccessLogInput
|
@@ -1,9 +1,9 @@
|
|
1
|
-
describe Fluent::ElbAccessLogInput do
|
1
|
+
describe Fluent::Plugin::ElbAccessLogInput do
|
2
2
|
let(:account_id) { '123456789012' }
|
3
3
|
let(:s3_bucket) { 'my-bucket' }
|
4
4
|
let(:region) { 'us-west-1' }
|
5
5
|
let(:driver) { create_driver(fluentd_conf) }
|
6
|
-
let(:client){ Aws::S3::Client.new(stub_responses: true) }
|
6
|
+
let!(:client){ Aws::S3::Client.new(stub_responses: true) }
|
7
7
|
|
8
8
|
let(:fluentd_conf) do
|
9
9
|
{
|
@@ -29,9 +29,9 @@ describe Fluent::ElbAccessLogInput do
|
|
29
29
|
|
30
30
|
before do
|
31
31
|
Timecop.freeze(today)
|
32
|
-
|
33
|
-
allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:load_history) { [] }
|
34
|
-
allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:parse_tsfile) { nil }
|
32
|
+
allow(Aws::S3::Client).to receive(:new) { client }
|
33
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:load_history) { [] }
|
34
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:parse_tsfile) { nil }
|
35
35
|
allow(FileUtils).to receive(:touch)
|
36
36
|
expect(driver.instance.log).to_not receive(:error)
|
37
37
|
end
|
@@ -40,7 +40,7 @@ describe Fluent::ElbAccessLogInput do
|
|
40
40
|
Timecop.return
|
41
41
|
end
|
42
42
|
|
43
|
-
subject { driver.
|
43
|
+
subject { driver.events }
|
44
44
|
|
45
45
|
context 'when access log does not exist' do
|
46
46
|
before do
|
@@ -51,7 +51,7 @@ describe Fluent::ElbAccessLogInput do
|
|
51
51
|
expect(driver.instance).to receive(:save_history)
|
52
52
|
expect(driver.instance.log).to_not receive(:warn)
|
53
53
|
|
54
|
-
driver
|
54
|
+
driver_run(driver)
|
55
55
|
end
|
56
56
|
|
57
57
|
it { is_expected.to be_empty }
|
@@ -97,7 +97,7 @@ https 2015-05-25T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
97
97
|
expect(driver.instance).to receive(:save_history)
|
98
98
|
expect(driver.instance.log).to_not receive(:warn)
|
99
99
|
|
100
|
-
driver
|
100
|
+
driver_run(driver)
|
101
101
|
end
|
102
102
|
|
103
103
|
let(:expected_emits) do
|
@@ -302,7 +302,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
302
302
|
allow(Addressable::URI).to receive(:parse).and_raise('parse error')
|
303
303
|
expect(driver.instance.log).to receive(:warn).with('parse error: http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/')
|
304
304
|
|
305
|
-
driver
|
305
|
+
driver_run(driver)
|
306
306
|
end
|
307
307
|
|
308
308
|
let(:expected_emits) do
|
@@ -376,7 +376,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
376
376
|
expect(driver.instance).to receive(:save_history)
|
377
377
|
expect(driver.instance.log).to_not receive(:warn)
|
378
378
|
|
379
|
-
driver
|
379
|
+
driver_run(driver)
|
380
380
|
end
|
381
381
|
|
382
382
|
let(:expected_emits) do
|
@@ -449,7 +449,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
449
449
|
expect(driver.instance).to receive(:save_history)
|
450
450
|
expect(driver.instance.log).to_not receive(:warn)
|
451
451
|
|
452
|
-
driver
|
452
|
+
driver_run(driver)
|
453
453
|
end
|
454
454
|
|
455
455
|
let(:expected_emits) do
|
@@ -521,7 +521,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
521
521
|
expect(CSV).to receive(:parse_line).and_raise('parse error')
|
522
522
|
expect(driver.instance.log).to_not receive(:warn)
|
523
523
|
|
524
|
-
driver
|
524
|
+
driver_run(driver)
|
525
525
|
end
|
526
526
|
|
527
527
|
let(:expected_emits) do
|
@@ -610,7 +610,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
610
610
|
expect(driver.instance).to receive(:save_history)
|
611
611
|
expect(driver.instance.log).to_not receive(:warn)
|
612
612
|
|
613
|
-
driver
|
613
|
+
driver_run(driver)
|
614
614
|
end
|
615
615
|
|
616
616
|
it { is_expected.to be_empty }
|
@@ -639,7 +639,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
639
639
|
expect(driver.instance).to receive(:save_history)
|
640
640
|
expect(driver.instance.log).to_not receive(:warn)
|
641
641
|
|
642
|
-
driver
|
642
|
+
driver_run(driver)
|
643
643
|
end
|
644
644
|
|
645
645
|
it { is_expected.to be_empty }
|
@@ -675,7 +675,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
675
675
|
|
676
676
|
context 'when history.length <= 100' do
|
677
677
|
before do
|
678
|
-
driver
|
678
|
+
driver_run(driver)
|
679
679
|
end
|
680
680
|
|
681
681
|
it { is_expected.to eq 1 }
|
@@ -684,7 +684,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
684
684
|
context 'when history.length > 100' do
|
685
685
|
before do
|
686
686
|
history.concat (1..100).map(&:to_s)
|
687
|
-
driver
|
687
|
+
driver_run(driver)
|
688
688
|
end
|
689
689
|
|
690
690
|
it { is_expected.to eq 100 }
|
@@ -714,7 +714,7 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
714
714
|
expect(driver.instance).to receive(:save_history)
|
715
715
|
expect(driver.instance.log).to_not receive(:warn)
|
716
716
|
|
717
|
-
driver
|
717
|
+
driver_run(driver)
|
718
718
|
end
|
719
719
|
|
720
720
|
let(:expected_emits) do
|
@@ -760,4 +760,94 @@ https 2015-05-24T19:55:36.000000Z hoge 14.14.124.20:57673 10.0.199.184:80 0.0000
|
|
760
760
|
|
761
761
|
it { is_expected.to match_table expected_emits }
|
762
762
|
end
|
763
|
+
|
764
|
+
context 'when inflate fails' do
|
765
|
+
let(:today_access_log) do
|
766
|
+
<<-EOS
|
767
|
+
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"
|
768
|
+
EOS
|
769
|
+
end
|
770
|
+
|
771
|
+
before do
|
772
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
|
773
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
|
774
|
+
|
775
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
|
776
|
+
[double('today_objects', contents: [double('today_object', key: today_object_key)])]
|
777
|
+
end
|
778
|
+
|
779
|
+
expect(client).to receive(:get_object).with(bucket: s3_bucket, key: today_object_key) do
|
780
|
+
double('today_s3_object', body: StringIO.new(today_access_log))
|
781
|
+
end
|
782
|
+
|
783
|
+
expect(driver.instance).to receive(:save_history)
|
784
|
+
end
|
785
|
+
|
786
|
+
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.')
|
788
|
+
driver_run(driver)
|
789
|
+
end
|
790
|
+
end
|
791
|
+
|
792
|
+
context 'when bad timestamp' do
|
793
|
+
let(:today_access_log) do
|
794
|
+
Zlib::Deflate.deflate(<<-EOS)
|
795
|
+
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
|
+
EOS
|
797
|
+
end
|
798
|
+
|
799
|
+
before do
|
800
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
|
801
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
|
802
|
+
|
803
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
|
804
|
+
[double('today_objects', contents: [double('today_object', key: today_object_key)])]
|
805
|
+
end
|
806
|
+
|
807
|
+
expect(client).to receive(:get_object).with(bucket: s3_bucket, key: today_object_key) do
|
808
|
+
double('today_s3_object', body: StringIO.new(today_access_log))
|
809
|
+
end
|
810
|
+
|
811
|
+
expect(driver.instance).to receive(:save_timestamp).with(today)
|
812
|
+
expect(driver.instance).to receive(:save_history)
|
813
|
+
end
|
814
|
+
|
815
|
+
specify do
|
816
|
+
expect(driver.instance.log).to receive(:warn).with(/no time information in "xxx":/)
|
817
|
+
expect(driver.instance.log).to receive(:warn).with('A record that has bad timestamp is not emitted.')
|
818
|
+
driver_run(driver)
|
819
|
+
end
|
820
|
+
end
|
821
|
+
|
822
|
+
context 'when unquote fails' do
|
823
|
+
let(:today_access_log) do
|
824
|
+
Zlib::Deflate.deflate(<<-EOS)
|
825
|
+
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
|
+
EOS
|
827
|
+
end
|
828
|
+
|
829
|
+
before do
|
830
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
|
831
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
|
832
|
+
|
833
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
|
834
|
+
[double('today_objects', contents: [double('today_object', key: today_object_key)])]
|
835
|
+
end
|
836
|
+
|
837
|
+
expect(client).to receive(:get_object).with(bucket: s3_bucket, key: today_object_key) do
|
838
|
+
double('today_s3_object', body: StringIO.new(today_access_log))
|
839
|
+
end
|
840
|
+
|
841
|
+
expect(driver.instance).to receive(:save_timestamp).with(today)
|
842
|
+
expect(driver.instance).to receive(:save_history)
|
843
|
+
|
844
|
+
expect(CSV).to receive(:parse_line).and_raise('parse error')
|
845
|
+
expect(driver.instance).to receive(:unquote).and_raise('unquote error')
|
846
|
+
end
|
847
|
+
|
848
|
+
specify do
|
849
|
+
expect(driver.instance.log).to receive(:warn).with(/parse error: unquote error:/)
|
850
|
+
driver_run(driver)
|
851
|
+
end
|
852
|
+
end
|
763
853
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
describe Fluent::ElbAccessLogInput do
|
1
|
+
describe Fluent::Plugin::ElbAccessLogInput do
|
2
2
|
let(:account_id) { '123456789012' }
|
3
3
|
let(:s3_bucket) { 'my-bucket' }
|
4
4
|
let(:region) { 'us-west-1' }
|
5
5
|
let(:driver) { create_driver(fluentd_conf) }
|
6
|
-
let(:client){ Aws::S3::Client.new(stub_responses: true) }
|
6
|
+
let!(:client){ Aws::S3::Client.new(stub_responses: true) }
|
7
7
|
|
8
8
|
let(:fluentd_conf) do
|
9
9
|
{
|
@@ -28,18 +28,18 @@ describe Fluent::ElbAccessLogInput do
|
|
28
28
|
|
29
29
|
before do
|
30
30
|
Timecop.freeze(today)
|
31
|
-
|
32
|
-
allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:load_history) { [] }
|
33
|
-
allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:parse_tsfile) { nil }
|
31
|
+
allow(Aws::S3::Client).to receive(:new) { client }
|
32
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:load_history) { [] }
|
33
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:parse_tsfile) { nil }
|
34
34
|
allow(FileUtils).to receive(:touch)
|
35
35
|
expect(driver.instance.log).to_not receive(:error)
|
36
|
-
|
36
|
+
end
|
37
37
|
|
38
38
|
after do
|
39
39
|
Timecop.return
|
40
40
|
end
|
41
41
|
|
42
|
-
subject { driver.
|
42
|
+
subject { driver.events }
|
43
43
|
|
44
44
|
context 'when access log does not exist' do
|
45
45
|
before do
|
@@ -50,7 +50,7 @@ describe Fluent::ElbAccessLogInput do
|
|
50
50
|
expect(driver.instance).to receive(:save_history)
|
51
51
|
expect(driver.instance.log).to_not receive(:warn)
|
52
52
|
|
53
|
-
driver
|
53
|
+
driver_run(driver)
|
54
54
|
end
|
55
55
|
|
56
56
|
it { is_expected.to be_empty }
|
@@ -96,7 +96,7 @@ describe Fluent::ElbAccessLogInput do
|
|
96
96
|
expect(driver.instance).to receive(:save_history)
|
97
97
|
expect(driver.instance.log).to_not receive(:warn)
|
98
98
|
|
99
|
-
driver
|
99
|
+
driver_run(driver)
|
100
100
|
end
|
101
101
|
|
102
102
|
let(:expected_emits) do
|
@@ -272,7 +272,7 @@ describe Fluent::ElbAccessLogInput do
|
|
272
272
|
allow(Addressable::URI).to receive(:parse).and_raise('parse error')
|
273
273
|
expect(driver.instance.log).to receive(:warn).with('parse error: http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/')
|
274
274
|
|
275
|
-
driver
|
275
|
+
driver_run(driver)
|
276
276
|
end
|
277
277
|
|
278
278
|
let(:expected_emits) do
|
@@ -338,7 +338,7 @@ describe Fluent::ElbAccessLogInput do
|
|
338
338
|
expect(driver.instance).to receive(:save_history)
|
339
339
|
expect(driver.instance.log).to_not receive(:warn)
|
340
340
|
|
341
|
-
driver
|
341
|
+
driver_run(driver)
|
342
342
|
end
|
343
343
|
|
344
344
|
let(:expected_emits) do
|
@@ -403,7 +403,7 @@ describe Fluent::ElbAccessLogInput do
|
|
403
403
|
expect(driver.instance).to receive(:save_history)
|
404
404
|
expect(driver.instance.log).to_not receive(:warn)
|
405
405
|
|
406
|
-
driver
|
406
|
+
driver_run(driver)
|
407
407
|
end
|
408
408
|
|
409
409
|
let(:expected_emits) do
|
@@ -468,7 +468,7 @@ describe Fluent::ElbAccessLogInput do
|
|
468
468
|
expect(CSV).to receive(:parse_line).and_raise('parse error')
|
469
469
|
expect(driver.instance.log).to_not receive(:warn)
|
470
470
|
|
471
|
-
driver
|
471
|
+
driver_run(driver)
|
472
472
|
end
|
473
473
|
|
474
474
|
let(:expected_emits) do
|
@@ -546,7 +546,7 @@ describe Fluent::ElbAccessLogInput do
|
|
546
546
|
expect(driver.instance).to receive(:save_history)
|
547
547
|
expect(driver.instance.log).to_not receive(:warn)
|
548
548
|
|
549
|
-
driver
|
549
|
+
driver_run(driver)
|
550
550
|
end
|
551
551
|
|
552
552
|
it { is_expected.to be_empty }
|
@@ -575,7 +575,7 @@ describe Fluent::ElbAccessLogInput do
|
|
575
575
|
expect(driver.instance).to receive(:save_history)
|
576
576
|
expect(driver.instance.log).to_not receive(:warn)
|
577
577
|
|
578
|
-
driver
|
578
|
+
driver_run(driver)
|
579
579
|
end
|
580
580
|
|
581
581
|
it { is_expected.to be_empty }
|
@@ -611,7 +611,7 @@ describe Fluent::ElbAccessLogInput do
|
|
611
611
|
|
612
612
|
context 'when history.length <= 100' do
|
613
613
|
before do
|
614
|
-
driver
|
614
|
+
driver_run(driver)
|
615
615
|
end
|
616
616
|
|
617
617
|
it { is_expected.to eq 1 }
|
@@ -620,7 +620,7 @@ describe Fluent::ElbAccessLogInput do
|
|
620
620
|
context 'when history.length > 100' do
|
621
621
|
before do
|
622
622
|
history.concat (1..100).map(&:to_s)
|
623
|
-
driver
|
623
|
+
driver_run(driver)
|
624
624
|
end
|
625
625
|
|
626
626
|
it { is_expected.to eq 100 }
|
@@ -650,7 +650,7 @@ describe Fluent::ElbAccessLogInput do
|
|
650
650
|
expect(driver.instance).to receive(:save_history)
|
651
651
|
expect(driver.instance.log).to_not receive(:warn)
|
652
652
|
|
653
|
-
driver
|
653
|
+
driver_run(driver)
|
654
654
|
end
|
655
655
|
|
656
656
|
let(:expected_emits) do
|
@@ -689,4 +689,36 @@ describe Fluent::ElbAccessLogInput do
|
|
689
689
|
|
690
690
|
it { is_expected.to match_table expected_emits }
|
691
691
|
end
|
692
|
+
|
693
|
+
context 'when no user_agent' do
|
694
|
+
let(:today_access_log) do
|
695
|
+
<<-EOS
|
696
|
+
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
|
697
|
+
EOS
|
698
|
+
end
|
699
|
+
|
700
|
+
before do
|
701
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
|
702
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
|
703
|
+
|
704
|
+
expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
|
705
|
+
[double('today_objects', contents: [double('today_object', key: today_object_key)])]
|
706
|
+
end
|
707
|
+
|
708
|
+
expect(client).to receive(:get_object).with(bucket: s3_bucket, key: today_object_key) do
|
709
|
+
double('today_s3_object', body: StringIO.new(today_access_log))
|
710
|
+
end
|
711
|
+
|
712
|
+
expect(driver.instance).to receive(:save_timestamp).with(today)
|
713
|
+
expect(driver.instance).to receive(:save_history)
|
714
|
+
|
715
|
+
expect(CSV).to receive(:parse_line).and_raise('parse error')
|
716
|
+
expect(driver.instance).to receive(:unquote).and_raise('unquote error')
|
717
|
+
end
|
718
|
+
|
719
|
+
specify do
|
720
|
+
expect(driver.instance.log).to receive(:warn).with(/parse error: unquote error:/)
|
721
|
+
driver_run(driver)
|
722
|
+
end
|
723
|
+
end
|
692
724
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe 'Fluent::ElbAccessLogInput#configure' do
|
1
|
+
describe 'Fluent::Plugin::ElbAccessLogInput#configure' do
|
2
2
|
let(:account_id) { '123456789012' }
|
3
3
|
let(:s3_bucket) { 'my-bucket' }
|
4
4
|
let(:region) { 'us-west-1' }
|
@@ -11,8 +11,8 @@ 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) { [] }
|
15
|
-
allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:parse_tsfile) { nil }
|
14
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:load_history) { [] }
|
15
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:parse_tsfile) { nil }
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'when default' do
|
@@ -140,7 +140,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
before do
|
143
|
-
allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:parse_tsfile) { Time.parse(tsfile_datetime) }
|
143
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:parse_tsfile) { Time.parse(tsfile_datetime) }
|
144
144
|
end
|
145
145
|
|
146
146
|
it do
|
@@ -162,7 +162,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
|
|
162
162
|
end
|
163
163
|
|
164
164
|
before do
|
165
|
-
allow_any_instance_of(Fluent::ElbAccessLogInput).to receive(:parse_tsfile) { Time.parse(tsfile_datetime) }
|
165
|
+
allow_any_instance_of(Fluent::Plugin::ElbAccessLogInput).to receive(:parse_tsfile) { Time.parse(tsfile_datetime) }
|
166
166
|
allow_any_instance_of(Fluent::Test::TestLogger).to receive(:warn).with("start_datetime(#{start_datetime}) is set. but tsfile datetime(#{tsfile_datetime}) is used")
|
167
167
|
end
|
168
168
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
1
4
|
require 'fluent/test'
|
5
|
+
require 'fluent/test/driver/input'
|
2
6
|
require 'fluent/plugin/in_elb_access_log'
|
3
7
|
|
4
8
|
require 'aws-sdk-s3'
|
@@ -6,16 +10,6 @@ require 'time'
|
|
6
10
|
require 'timecop'
|
7
11
|
require 'rspec/match_table'
|
8
12
|
|
9
|
-
if ENV['TRAVIS']
|
10
|
-
require 'simplecov'
|
11
|
-
require 'coveralls'
|
12
|
-
|
13
|
-
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
14
|
-
SimpleCov.start do
|
15
|
-
add_filter "spec/"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
13
|
# Disable Test::Unit
|
20
14
|
module Test::Unit::RunCount; def run(*); end; end
|
21
15
|
|
@@ -46,8 +40,14 @@ region #{region}
|
|
46
40
|
#{additional_options}
|
47
41
|
EOS
|
48
42
|
|
49
|
-
|
50
|
-
|
43
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::ElbAccessLogInput).configure(fluentd_conf)
|
44
|
+
end
|
45
|
+
|
46
|
+
def driver_run(driver)
|
47
|
+
driver.run do
|
48
|
+
coolio_loop = driver.instance.instance_variable_get(:@loop)
|
49
|
+
sleep 0.1 until coolio_loop.instance_variable_get(:@running)
|
50
|
+
end
|
51
51
|
end
|
52
52
|
|
53
53
|
# prevent Test::Unit's AutoRunner from executing during RSpec's rake task
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.14'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.14'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: aws-sdk-s3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,8 +157,10 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- ".coveralls.yml"
|
160
161
|
- ".gitignore"
|
161
162
|
- ".rspec"
|
163
|
+
- ".simplecov"
|
162
164
|
- ".travis.yml"
|
163
165
|
- Gemfile
|
164
166
|
- LICENSE.txt
|