Skip to content

Commit

Permalink
Merge pull request #15 from winebarrel/add_request_separator_option
Browse files Browse the repository at this point in the history
Add request separator option
  • Loading branch information
winebarrel committed Apr 5, 2018
2 parents 28adc7e + 3e3f44e commit d06631b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Or install it yourself as:
#parse_request true
#split_addr_port true
#file_filter REGEXP
#request_separator .
</source>
```

Expand Down
9 changes: 5 additions & 4 deletions lib/fluent/plugin/in_elb_access_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class FluentPluginElbAccessLogInput < Fluent::Input
config_param :parse_request, :bool, default: true
config_param :split_addr_port, :bool, default: true
config_param :file_filter, :string, default: nil
config_param :request_separator, :string, default: '.'

def configure(conf)
super
Expand Down Expand Up @@ -377,9 +378,9 @@ def parse_request!(record)
return unless request
method, uri, http_version = request.split(' ', 3)

record['request.method'] = method
record['request.uri'] = uri
record['request.http_version'] = http_version
record["request#{@request_separator}method"] = method
record["request#{@request_separator}uri"] = uri
record["request#{@request_separator}http_version"] = http_version

begin
uri = Addressable::URI.parse(uri)
Expand All @@ -392,7 +393,7 @@ def parse_request!(record)
value = value.to_s
end

record["request.uri.#{key}"] = value
record["request#{@request_separator}uri#{@request_separator}#{key}"] = value
end
end
rescue => e
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent_plugin_elb_access_log/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FluentPluginElbAccessLog
VERSION = '0.6.0'
VERSION = '0.6.1'
end
23 changes: 23 additions & 0 deletions spec/in_elb_access_log_alb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,29 @@
is_expected.to match_table expected_emits_without_request_parsing
end
end

context 'with request_separator' do
let(:fluentd_conf) do
{
interval: 0,
account_id: account_id,
s3_bucket: s3_bucket,
region: region,
start_datetime: (today - 1).to_s,
elb_type: 'alb',
request_separator: '_'
}
end

it do
expected_emits_with_underscore = expected_emits.map do |tag, ts, h|
h = Hash[h.map {|k, v| [k.gsub('.', '_'), v] }]
[tag, ts, h]
end

is_expected.to match_table expected_emits_with_underscore
end
end
end

context 'with file_filter' do
Expand Down
22 changes: 22 additions & 0 deletions spec/in_elb_access_log_clb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,28 @@
is_expected.to match_table expected_emits_without_request_parsing
end
end

context 'with request_separator' do
let(:fluentd_conf) do
{
interval: 0,
account_id: account_id,
s3_bucket: s3_bucket,
region: region,
start_datetime: (today - 1).to_s,
request_separator: '_'
}
end

it do
expected_emits_with_underscore = expected_emits.map do |tag, ts, h|
h = Hash[h.map {|k, v| [k.gsub('.', '_'), v] }]
[tag, ts, h]
end

is_expected.to match_table expected_emits_with_underscore
end
end
end

context 'with file_filter' do
Expand Down
5 changes: 5 additions & 0 deletions spec/in_elb_access_log_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
expect(driver.instance.parse_request).to be_truthy
expect(driver.instance.split_addr_port).to be_truthy
expect(driver.instance.filter).to be_nil
expect(driver.instance.file_filter).to be_nil
expect(driver.instance.request_separator).to eq '.'
end
end

Expand All @@ -72,6 +74,7 @@
let(:filter) { 'elb_status_code:^2' }
let(:filter_operator) { 'or' }
let(:file_filter) { '.*my-elb.*' }
let(:request_separator) { '_' }

let(:fluentd_conf) do
{
Expand Down Expand Up @@ -100,6 +103,7 @@
parse_request: 'false',
split_addr_port: 'false',
file_filter: file_filter,
request_separator: request_separator,
}
end

Expand Down Expand Up @@ -128,6 +132,7 @@
expect(driver.instance.parse_request).to be_falsey
expect(driver.instance.split_addr_port).to be_falsey
expect(driver.instance.file_filter).to eq Regexp.new(file_filter)
expect(driver.instance.request_separator).to eq request_separator
end
end

Expand Down

0 comments on commit d06631b

Please sign in to comment.