fluent-plugin-elb-access-log 0.2.3 → 0.2.4

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: d199a2443e0155561cf75236566e4a2e6cb1e528
4
- data.tar.gz: 97fd5bb09c4f6b5d653c15fcef661fd886e14b81
3
+ metadata.gz: 20da40ca2f682d7cd5e2da5680a59a3d1d19ffcb
4
+ data.tar.gz: 493f3437ffc8614d3a7d4b144a5dbd34c2400beb
5
5
  SHA512:
6
- metadata.gz: 74953f1b6b2d0be08589596a255f6774bd9df447ebb9f52ea0c1902e78fb40769ec0cfc9a190abb0cb0a894d08aeccb5fcaa61170cc8ed8b768992878fead595
7
- data.tar.gz: 7e5477cf26c6e07217b78b02b7ed198c9b0a072e9c4dcb058cebcd53191f7c8dbf8f722c3a9db149ba47953dbd7ddea1d88ac006f3643bbb71fe8c42685e3d1f
6
+ metadata.gz: dc79f4a01261b1e125f9e9b699328723673edeb075d69aef266db31384d94254e3d49ba4adda7aa3c2eb96697300abd952aa18397b70ba7cce3f49e8ef267c06
7
+ data.tar.gz: 09760b23d4c257d7f6ef6f2604c50369ed3c68eab9a7fb0e4f0e8c9852ec076fc38fcec0b8f06c45c250978a5d1f88e5b2f3e7b4bb0f81be34a7ee84e9903b17
@@ -158,11 +158,8 @@ class Fluent::ElbAccessLogInput < Fluent::Input
158
158
  parsed_access_log = []
159
159
 
160
160
  access_log.split("\n").each do |line|
161
- begin
162
- parsed_access_log << CSV.parse_line(line, :col_sep => ' ')
163
- rescue => e
164
- @log.warn("#{e.message}: #{line}")
165
- end
161
+ line = parse_line(line)
162
+ parsed_access_log << line if line
166
163
  end
167
164
 
168
165
  parsed_access_log.each do |row|
@@ -182,6 +179,27 @@ class Fluent::ElbAccessLogInput < Fluent::Input
182
179
  end
183
180
  end
184
181
 
182
+ def parse_line(line)
183
+ parsed = nil
184
+
185
+ begin
186
+ parsed = CSV.parse_line(line, :col_sep => ' ')
187
+ rescue => e
188
+ begin
189
+ parsed = line.split(' ', 12)
190
+
191
+ # request
192
+ parsed[11] ||= ''
193
+ parsed[11].gsub!(/\A"/, '')
194
+ parsed[11].gsub!(/".*\z/, '')
195
+ rescue => e2
196
+ @log.warn("#{e.message}: #{line}")
197
+ end
198
+ end
199
+
200
+ parsed
201
+ end
202
+
185
203
  def sampling(access_log)
186
204
  access_log.split("\n").each_with_index.select {|row, i| (i % @sampling_interval).zero? }.map {|row, i| row }.join("\n")
187
205
  end
@@ -1,3 +1,3 @@
1
1
  module FluentPluginElbAccessLog
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -415,6 +415,67 @@ describe Fluent::ElbAccessLogInput do
415
415
  it { is_expected.to eq expected_emits }
416
416
  end
417
417
 
418
+ context 'when parse error' do
419
+ let(:today_access_log) do
420
+ <<-EOS
421
+ 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" - -
422
+ EOS
423
+ end
424
+
425
+ before do
426
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: yesterday_prefix) { [] }
427
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: tomorrow_prefix) { [] }
428
+
429
+ expect(client).to receive(:list_objects).with(bucket: s3_bucket, prefix: today_prefix) do
430
+ [double('today_objects', contents: [double('today_object', key: today_object_key)])]
431
+ end
432
+
433
+ expect(client).to receive(:get_object).with(bucket: s3_bucket, key: today_object_key) do
434
+ [double('today_s3_object', body: StringIO.new(today_access_log))]
435
+ end
436
+
437
+ expect(driver.instance).to receive(:save_timestamp).with(today)
438
+ expect(driver.instance).to receive(:save_history)
439
+
440
+ expect(CSV).to receive(:parse_line).and_raise('parse error')
441
+
442
+ driver.run
443
+ end
444
+
445
+ let(:expected_emits) do
446
+ [["elb.access_log",
447
+ Time.parse('2015-05-24 19:55:36 UTC').to_i,
448
+ {"timestamp"=>"2015-05-24T19:55:36.000000Z",
449
+ "elb"=>"hoge",
450
+ "client"=>"14.14.124.20",
451
+ "client_port"=>57673,
452
+ "backend"=>"10.0.199.184",
453
+ "backend_port"=>80,
454
+ "request_processing_time"=>5.3e-05,
455
+ "backend_processing_time"=>0.000913,
456
+ "response_processing_time"=>3.6e-05,
457
+ "elb_status_code"=>200,
458
+ "backend_status_code"=>200,
459
+ "received_bytes"=>0,
460
+ "sent_bytes"=>3,
461
+ "request"=>
462
+ "GET http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/ HTTP/1.1",
463
+ "request.method"=>"GET",
464
+ "request.uri"=>
465
+ "http://hoge-1876938939.ap-northeast-1.elb.amazonaws.com:80/",
466
+ "request.http_version"=>"HTTP/1.1",
467
+ "request.uri.scheme"=>"http",
468
+ "request.uri.user"=>nil,
469
+ "request.uri.host"=>"hoge-1876938939.ap-northeast-1.elb.amazonaws.com",
470
+ "request.uri.port"=>80,
471
+ "request.uri.path"=>"/",
472
+ "request.uri.query"=>nil,
473
+ "request.uri.fragment"=>nil}]]
474
+ end
475
+
476
+ it { is_expected.to eq expected_emits }
477
+ end
478
+
418
479
  context 'when access old log exists (timeout)' do
419
480
  let(:today_access_log) do
420
481
  <<-EOS
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.2.3
4
+ version: 0.2.4
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-26 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd