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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23af18097699523eb79eacdfff39c155e14a074e
4
- data.tar.gz: 9132f72caaa0e09e2bbbad4fefef5bb6654642ee
3
+ metadata.gz: 96510ed8b34e1025ead147d989eefc4459404ae8
4
+ data.tar.gz: f44e0a4c33aa20267fa604fe181f1861c24b1ed5
5
5
  SHA512:
6
- metadata.gz: f3273e599277bb2ee5367e8934a4c8cb32d6337145c5eee60114558d2d111f4fde60149b3ef2ed811144ab35cdf5fb6e20a2cdbe2f8a8e3b6b8ccd5d4ad49c6d
7
- data.tar.gz: 4c44fdc553b5afddb444cdead9a2c6bf00304059a4eea0f9abe2d6550588679536122afe2ffe36e5e52c9e0640841a3d287815c43d2096d01fec33d9f82fc842
6
+ metadata.gz: a0375b94759d747d2f3bbdf0cec1b048cb1ec81149f1db9f111edc66726563b4cb75316ecb45a3c87b248ae8215076f0b32b00457779aacb3c04e6b635d2d495
7
+ data.tar.gz: 573db4ec038fb669d091e4125a7f09d0c485d619f28db67aea3e120f2439d9d9386d1f065790ebd085bd0f1e90c286fde90b224c95f56182474abc5ed8453a4f
data/README.md CHANGED
@@ -43,6 +43,7 @@ Or install it yourself as:
43
43
  #start_datetime 2015/05/24 17:00
44
44
  #buffer_sec 600
45
45
  #history_length 100
46
+ #sampling_interval 1
46
47
  #debug false
47
48
  </source>
48
49
  ```
@@ -29,22 +29,23 @@ class Fluent::ElbAccessLogInput < Fluent::Input
29
29
  define_method('router') { Fluent::Engine }
30
30
  end
31
31
 
32
- config_param :aws_key_id, :string, :default => nil
33
- config_param :aws_sec_key, :string, :default => nil
34
- config_param :profile, :string, :default => nil
35
- config_param :credentials_path, :string, :default => nil
36
- config_param :http_proxy, :string, :default => nil
37
- config_param :account_id, :string
38
- config_param :region, :string
39
- config_param :s3_bucket, :string
40
- config_param :s3_prefix, :string, :default => nil
41
- config_param :tag, :string, :default => 'elb.access_log'
42
- config_param :tsfile_path, :string, :default => '/var/tmp/fluent-plugin-elb-access-log.ts'
43
- config_param :interval, :time, :default => 300
44
- config_param :start_datetime, :string, :default => nil
45
- config_param :buffer_sec, :time, :default => 600
46
- config_param :history_length, :integer, :default => 100
47
- config_param :debug, :bool, :default => false
32
+ config_param :aws_key_id, :string, :default => nil
33
+ config_param :aws_sec_key, :string, :default => nil
34
+ config_param :profile, :string, :default => nil
35
+ config_param :credentials_path, :string, :default => nil
36
+ config_param :http_proxy, :string, :default => nil
37
+ config_param :account_id, :string
38
+ config_param :region, :string
39
+ config_param :s3_bucket, :string
40
+ config_param :s3_prefix, :string, :default => nil
41
+ config_param :tag, :string, :default => 'elb.access_log'
42
+ config_param :tsfile_path, :string, :default => '/var/tmp/fluent-plugin-elb-access-log.ts'
43
+ config_param :interval, :time, :default => 300
44
+ config_param :start_datetime, :string, :default => nil
45
+ config_param :buffer_sec, :time, :default => 600
46
+ config_param :history_length, :integer, :default => 100
47
+ config_param :sampling_interval, :integer, :default => 1
48
+ config_param :debug, :bool, :default => false
48
49
 
49
50
  def initialize
50
51
  super
@@ -146,6 +147,10 @@ class Fluent::ElbAccessLogInput < Fluent::Input
146
147
  end
147
148
 
148
149
  def emit_access_log(access_log)
150
+ if @sampling_interval > 1
151
+ access_log = sampling(access_log)
152
+ end
153
+
149
154
  access_log = CSV.parse(access_log, :col_sep => ' ')
150
155
 
151
156
  access_log.each do |row|
@@ -165,6 +170,10 @@ class Fluent::ElbAccessLogInput < Fluent::Input
165
170
  end
166
171
  end
167
172
 
173
+ def sampling(access_log)
174
+ access_log.split("\n").each_with_index.select {|row, i| (i % @sampling_interval).zero? }.map {|row, i| row }.join("\n")
175
+ end
176
+
168
177
  def split_address_port!(record, prefix)
169
178
  address, port = record["#{prefix}_port"].split(':', 2)
170
179
  record[prefix] = address
@@ -1,3 +1,3 @@
1
1
  module FluentPluginElbAccessLog
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
@@ -38,6 +38,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
38
38
  expect(driver.instance.start_datetime).to eq today
39
39
  expect(driver.instance.buffer_sec).to eq 600
40
40
  expect(driver.instance.history_length).to eq 100
41
+ expect(driver.instance.sampling_interval).to eq 1
41
42
  expect(driver.instance.debug).to be_falsey
42
43
  end
43
44
  end
@@ -55,6 +56,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
55
56
  let(:start_datetime) { today - 3600 }
56
57
  let(:buffer_sec) { 1200 }
57
58
  let(:history_length) { 200 }
59
+ let(:sampling_interval) { 100 }
58
60
 
59
61
  let(:fluentd_conf) do
60
62
  {
@@ -73,6 +75,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
73
75
  start_datetime: start_datetime,
74
76
  buffer_sec: buffer_sec,
75
77
  history_length: history_length,
78
+ sampling_interval: sampling_interval,
76
79
  debug: true,
77
80
  }
78
81
  end
@@ -92,6 +95,7 @@ describe 'Fluent::ElbAccessLogInput#configure' do
92
95
  expect(driver.instance.start_datetime).to eq start_datetime
93
96
  expect(driver.instance.buffer_sec).to eq buffer_sec
94
97
  expect(driver.instance.history_length).to eq history_length
98
+ expect(driver.instance.sampling_interval).to eq sampling_interval
95
99
  expect(driver.instance.debug).to be_truthy
96
100
  end
97
101
  end
@@ -217,6 +217,24 @@ describe Fluent::ElbAccessLogInput do
217
217
 
218
218
  it { is_expected.to eq expected_emits }
219
219
 
220
+ context 'when sampling' do
221
+ let(:fluentd_conf) do
222
+ {
223
+ account_id: account_id,
224
+ s3_bucket: s3_bucket,
225
+ region: region,
226
+ start_datetime: (today - 1).to_s,
227
+ sampling_interval: 2,
228
+ }
229
+ end
230
+
231
+ it do
232
+ expected_emits.delete_at(3)
233
+ expected_emits.delete_at(1)
234
+ is_expected.to eq expected_emits
235
+ end
236
+ end
237
+
220
238
  context 'when include bad URI' do
221
239
  let(:today_access_log) do
222
240
  <<-EOS
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara