fluent-plugin-elb-log 0.4.0 → 0.4.1
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 +4 -4
- data/.travis.yml +11 -1
- data/README.md +5 -0
- data/fluent-plugin-elb-log.gemspec +5 -4
- data/lib/fluent/plugin/in_elb_log.rb +45 -43
- data/test/helper.rb +3 -0
- data/test/plugin/in_elb_log.rb +27 -4
- metadata +26 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f565fbbe387bad73d53cee18557d89ae0acd9f4f
|
4
|
+
data.tar.gz: 6a37e1c172a8d1c5b20394dbaa38923b9b82b0e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58c8fd4c5ba84514c783afb2867438c4646a171f41d3d8fcb052db6624f807578b7bec83061f357b04791662b5a42d96cf973e0426aa5d091a5690b62625a5ba
|
7
|
+
data.tar.gz: 85870e3681ddc11eb40ad22feed503aacfddd970dfc108917af87f86fd06fadba084f1f09ff4bd0d3d38a2c88d436e463bfef1403fde1c690735ddb4b8accb04
|
data/.travis.yml
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
env:
|
2
|
+
global:
|
3
|
+
- CC_TEST_REPORTER_ID=bca5d9771c392e374d213de82dde44181a12b4c8b5d5bd37b249c81ca5bf32f1
|
4
|
+
- GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
|
5
|
+
language: ruby
|
2
6
|
|
3
7
|
rvm:
|
4
8
|
- 2.1
|
@@ -8,3 +12,9 @@ rvm:
|
|
8
12
|
branches:
|
9
13
|
only:
|
10
14
|
- master
|
15
|
+
|
16
|
+
before_script:
|
17
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
18
|
+
- chmod +x ./cc-test-reporter
|
19
|
+
after_script:
|
20
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Amazon ELB log input plugin for fluentd
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/fluent-plugin-elb-log)
|
4
|
+
[](https://travis-ci.org/shinsaka/fluent-plugin-elb-log)
|
5
|
+
[](https://codeclimate.com/github/shinsaka/fluent-plugin-elb-log)
|
6
|
+
[](https://codeclimate.com/github/shinsaka/fluent-plugin-elb-log/coverage)
|
7
|
+
|
3
8
|
## Overview
|
4
9
|
- Amazon Web Services ELB log input plubin for fluentd
|
5
10
|
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-elb-log"
|
7
|
-
spec.version = "0.4.
|
7
|
+
spec.version = "0.4.1"
|
8
8
|
spec.authors = ["shinsaka"]
|
9
9
|
spec.email = ["shinx1265@gmail.com"]
|
10
10
|
spec.summary = "Amazon ELB log input plugin"
|
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "aws-sdk", "~> 2"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
-
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "test-unit", "
|
26
|
-
spec.add_development_dependency "webmock"
|
24
|
+
spec.add_development_dependency "rake", "~> 12"
|
25
|
+
spec.add_development_dependency "test-unit", "~> 3.2"
|
26
|
+
spec.add_development_dependency "webmock", "~>3"
|
27
|
+
spec.add_development_dependency "simplecov", "~>0"
|
27
28
|
end
|
@@ -33,6 +33,7 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
33
33
|
end
|
34
34
|
raise Fluent::ConfigError.new("s3_bucketname is required") unless @s3_bucketname
|
35
35
|
raise Fluent::ConfigError.new("timestamp_file is required") unless @timestamp_file
|
36
|
+
raise Fluent::ConfigError.new("s3 bucket not found #{@s3_bucketname}") unless s3bucket_is_ok?
|
36
37
|
end
|
37
38
|
|
38
39
|
def start
|
@@ -42,8 +43,6 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
42
43
|
File.open(@timestamp_file, File::RDWR|File::CREAT).close
|
43
44
|
File.open(@buf_file, File::RDWR|File::CREAT).close
|
44
45
|
|
45
|
-
raise StandardError.new("s3 bucket not found #{@s3_bucketname}") unless s3bucket_is_ok()
|
46
|
-
|
47
46
|
timer_execute(:in_elb_log, @refresh_interval, &method(:input))
|
48
47
|
end
|
49
48
|
|
@@ -104,15 +103,15 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
107
|
-
def s3bucket_is_ok
|
108
|
-
|
109
|
-
log.debug "search bucket #{@s3_bucketname}"
|
106
|
+
def s3bucket_is_ok?
|
107
|
+
log.debug "searching for bucket #{@s3_bucketname}"
|
110
108
|
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
begin
|
110
|
+
# try get one
|
111
|
+
!(get_object_list(1).nil?)
|
114
112
|
rescue => e
|
115
|
-
log.warn "
|
113
|
+
log.warn "error occurred: #{e.message}"
|
114
|
+
false
|
116
115
|
end
|
117
116
|
end
|
118
117
|
|
@@ -180,14 +179,8 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
180
179
|
|
181
180
|
def get_object_keys_from_s3
|
182
181
|
begin
|
183
|
-
objects = s3_client.list_objects(
|
184
|
-
bucket: @s3_bucketname,
|
185
|
-
max_keys: 100,
|
186
|
-
prefix: @s3_prefix,
|
187
|
-
)
|
188
|
-
|
189
182
|
object_keys = []
|
190
|
-
|
183
|
+
get_object_list(100).each do |object|
|
191
184
|
object.contents.each do |content|
|
192
185
|
object_keys << content.key
|
193
186
|
end
|
@@ -208,6 +201,14 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
208
201
|
end
|
209
202
|
end
|
210
203
|
|
204
|
+
def get_object_list(max_num)
|
205
|
+
s3_client.list_objects(
|
206
|
+
bucket: @s3_bucketname,
|
207
|
+
max_keys: max_num,
|
208
|
+
prefix: @s3_prefix
|
209
|
+
)
|
210
|
+
end
|
211
|
+
|
211
212
|
def get_file_from_s3(object_name)
|
212
213
|
begin
|
213
214
|
log.debug "getting object from s3 name is #{object_name}"
|
@@ -244,37 +245,38 @@ class Fluent::Plugin::Elb_LogInput < Fluent::Plugin::Input
|
|
244
245
|
next
|
245
246
|
end
|
246
247
|
|
247
|
-
|
248
|
-
"time" => line_match[:time].gsub(/Z/, "+0000"),
|
249
|
-
"elb" => line_match[:elb],
|
250
|
-
"client" => line_match[:client],
|
251
|
-
"client_port" => line_match[:client_port],
|
252
|
-
"backend" => line_match[:backend],
|
253
|
-
"backend_port" => line_match[:backend_port],
|
254
|
-
"request_processing_time" => line_match[:request_processing_time].to_f,
|
255
|
-
"backend_processing_time" => line_match[:backend_processing_time].to_f,
|
256
|
-
"response_processing_time" => line_match[:response_processing_time].to_f,
|
257
|
-
"elb_status_code" => line_match[:elb_status_code],
|
258
|
-
"backend_status_code" => line_match[:backend_status_code],
|
259
|
-
"received_bytes" => line_match[:received_bytes].to_i,
|
260
|
-
"sent_bytes" => line_match[:sent_bytes].to_i,
|
261
|
-
"request_method" => line_match[:request_method],
|
262
|
-
"request_uri" => line_match[:request_uri],
|
263
|
-
"request_protocol" => line_match[:request_protocol],
|
264
|
-
"user_agent" => line_match[:user_agent],
|
265
|
-
"ssl_cipher" => line_match[:ssl_cipher],
|
266
|
-
"ssl_protocol" => line_match[:ssl_protocol],
|
267
|
-
"type" => line_match[:type],
|
268
|
-
"target_group_arn" => line_match[:target_group_arn],
|
269
|
-
"trace_id" => line_match[:trace_id],
|
270
|
-
"option3" => line_match[:option3],
|
271
|
-
}
|
272
|
-
|
273
|
-
router.emit(@tag, Fluent::Engine.now, record_common.merge(record))
|
248
|
+
router.emit(@tag, Fluent::Engine.now, record_common.merge(format_record(line_match)))
|
274
249
|
end
|
275
250
|
end
|
276
251
|
rescue => e
|
277
252
|
log.warn "error occurred: #{e.message}"
|
278
253
|
end
|
279
254
|
end
|
255
|
+
|
256
|
+
def format_record(item)
|
257
|
+
{ "time" => item[:time].gsub(/Z/, '+0000'),
|
258
|
+
"elb" => item[:elb],
|
259
|
+
"client" => item[:client],
|
260
|
+
"client_port" => item[:client_port],
|
261
|
+
"backend" => item[:backend],
|
262
|
+
"backend_port" => item[:backend_port],
|
263
|
+
"request_processing_time" => item[:request_processing_time].to_f,
|
264
|
+
"backend_processing_time" => item[:backend_processing_time].to_f,
|
265
|
+
"response_processing_time" => item[:response_processing_time].to_f,
|
266
|
+
"elb_status_code" => item[:elb_status_code],
|
267
|
+
"backend_status_code" => item[:backend_status_code],
|
268
|
+
"received_bytes" => item[:received_bytes].to_i,
|
269
|
+
"sent_bytes" => item[:sent_bytes].to_i,
|
270
|
+
"request_method" => item[:request_method],
|
271
|
+
"request_uri" => item[:request_uri],
|
272
|
+
"request_protocol" => item[:request_protocol],
|
273
|
+
"user_agent" => item[:user_agent],
|
274
|
+
"ssl_cipher" => item[:ssl_cipher],
|
275
|
+
"ssl_protocol" => item[:ssl_protocol],
|
276
|
+
"type" => item[:type],
|
277
|
+
"target_group_arn" => item[:target_group_arn],
|
278
|
+
"trace_id" => item[:trace_id],
|
279
|
+
"option3" => item[:option3]
|
280
|
+
}
|
281
|
+
end
|
280
282
|
end
|
data/test/helper.rb
CHANGED
data/test/plugin/in_elb_log.rb
CHANGED
@@ -10,7 +10,7 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
10
10
|
access_key_id: 'dummy_access_key_id',
|
11
11
|
secret_access_key: 'dummy_secret_access_key',
|
12
12
|
s3_endpoint: 's3-ap-northeast-1.amazonaws.com',
|
13
|
-
s3_bucketname: '
|
13
|
+
s3_bucketname: 'dummy_bucket',
|
14
14
|
s3_prefix: 'test',
|
15
15
|
region: 'ap-northeast-1',
|
16
16
|
timestamp_file: 'elb_last_at.dat',
|
@@ -26,7 +26,7 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def iam_info_url
|
29
|
-
|
29
|
+
'http://169.254.169.254/latest/meta-data/iam/security-credentials/'
|
30
30
|
end
|
31
31
|
|
32
32
|
def use_iam_role
|
@@ -50,7 +50,18 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
50
50
|
.to_return(status: [404, 'Not Found'])
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
53
|
+
def s3bucket_ok
|
54
|
+
stub_request(:get, 'https://s3-ap-northeast-1.amazonaws.com/dummy_bucket?encoding-type=url&max-keys=1&prefix=test')
|
55
|
+
.to_return(status: 200, body: "", headers: {})
|
56
|
+
end
|
57
|
+
|
58
|
+
def s3bucket_not_found
|
59
|
+
stub_request(:get, 'https://s3-ap-northeast-1.amazonaws.com/dummy_bucket?encoding-type=url&max-keys=1&prefix=test')
|
60
|
+
.to_return(status: 404, body: "", headers: {})
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_configure_default
|
64
|
+
s3bucket_ok
|
54
65
|
use_iam_role
|
55
66
|
assert_nothing_raised { create_driver }
|
56
67
|
|
@@ -70,6 +81,7 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
70
81
|
end
|
71
82
|
|
72
83
|
def test_configure_in_EC2_with_IAM_role
|
84
|
+
s3bucket_ok
|
73
85
|
use_iam_role
|
74
86
|
conf = DEFAULT_CONFIG.clone
|
75
87
|
conf.delete(:access_key_id)
|
@@ -78,8 +90,9 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
78
90
|
end
|
79
91
|
|
80
92
|
def test_configure_in_EC2_without_IAM_role
|
81
|
-
not_use_iam_role
|
82
93
|
exception = assert_raise(Fluent::ConfigError) {
|
94
|
+
s3bucket_ok
|
95
|
+
not_use_iam_role
|
83
96
|
conf = DEFAULT_CONFIG.clone
|
84
97
|
conf.delete(:access_key_id)
|
85
98
|
create_driver(conf)
|
@@ -95,6 +108,7 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
95
108
|
end
|
96
109
|
|
97
110
|
def test_configure_outside_EC2
|
111
|
+
s3bucket_ok
|
98
112
|
iam_info_timeout
|
99
113
|
|
100
114
|
assert_nothing_raised { create_driver }
|
@@ -113,6 +127,15 @@ class Elb_LogInputTest < Test::Unit::TestCase
|
|
113
127
|
assert_equal('secret_access_key is required', exception.message)
|
114
128
|
end
|
115
129
|
|
130
|
+
def test_not_found_s3bucket
|
131
|
+
e = assert_raise(Fluent::ConfigError) {
|
132
|
+
use_iam_role
|
133
|
+
s3bucket_not_found
|
134
|
+
create_driver(DEFAULT_CONFIG.clone)
|
135
|
+
}
|
136
|
+
assert_equal('s3 bucket not found dummy_bucket', e.message)
|
137
|
+
end
|
138
|
+
|
116
139
|
def test_logfilename_classic_lb_parse
|
117
140
|
logfile_classic = 'classic/AWSLogs/123456789012/elasticloadbalancing/ap-northeast-1/2017/05/03/123456789012_elasticloadbalancing_ap-northeast-1_elbname_20170503T1250Z_10.0.0.1_43nzjpdj.log'
|
118
141
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-elb-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shinsaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -62,42 +62,56 @@ dependencies:
|
|
62
62
|
name: rake
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
65
|
+
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '12'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '12'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: test-unit
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 3.
|
81
|
+
version: '3.2'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- - "
|
86
|
+
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 3.
|
88
|
+
version: '3.2'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: webmock
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- - "
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
94
108
|
- !ruby/object:Gem::Version
|
95
109
|
version: '0'
|
96
110
|
type: :development
|
97
111
|
prerelease: false
|
98
112
|
version_requirements: !ruby/object:Gem::Requirement
|
99
113
|
requirements:
|
100
|
-
- - "
|
114
|
+
- - "~>"
|
101
115
|
- !ruby/object:Gem::Version
|
102
116
|
version: '0'
|
103
117
|
description: Amazon ELB log input plugin for fluentd
|