fluent-plugin-ec2-metadata 0.0.15 → 0.1.0
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 +0 -7
- data/README.md +7 -0
- data/Rakefile +1 -1
- data/fluent-plugin-ec2-metadata.gemspec +2 -2
- data/lib/fluent/plugin/ec2_metadata.rb +9 -9
- data/lib/fluent/plugin/filter_ec2_metadata.rb +5 -9
- data/lib/fluent/plugin/out_ec2_metadata.rb +8 -15
- data/test/plugin/test_filter_ec2_metadata.rb +25 -2
- data/test/plugin/test_out_ec2_metadata.rb +9 -8
- metadata +7 -9
- data/Gemfile.fluentd.0.10 +0 -9
- data/Gemfile.fluentd.0.12 +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce91cbea4bad7e31c32de08af7f6769d986be51c
|
4
|
+
data.tar.gz: 5c9ba0747b12f50bdb65c2d9386fa1afb18a655d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8f5b0090c3120c9cedfa29269461901e9106d57a58cb926d7bcf529b51f5c72b22af9680b9cc08d25f960631aa45354cfd334733f6ee28af5a179b50275ad4a
|
7
|
+
data.tar.gz: 96fc722e796512024285c29c5708241d92c97768c4b42a4e0651c04b899d8e11cece1febcf83a7626953c28afea764eada9c19715e2e8f030538b07316eea849
|
data/.travis.yml
CHANGED
@@ -1,15 +1,8 @@
|
|
1
1
|
rvm:
|
2
|
-
- 2.0.*
|
3
2
|
- 2.1.*
|
4
3
|
- 2.2.*
|
5
4
|
- 2.3.0
|
6
5
|
gemfile:
|
7
6
|
- Gemfile
|
8
|
-
- Gemfile.fluentd.0.12
|
9
|
-
- Gemfile.fluentd.0.10
|
10
|
-
matrix:
|
11
|
-
exclude:
|
12
|
-
- rvm: 2.0.*
|
13
|
-
gemfile: Gemfile
|
14
7
|
before_install: gem update bundler
|
15
8
|
after_script: codeclimate-test-reporter
|
data/README.md
CHANGED
@@ -9,6 +9,13 @@
|
|
9
9
|
|
10
10
|
[Fluentd](http://fluentd.org) plugin to add ec2 metadata fields to a event record
|
11
11
|
|
12
|
+
## Requirements
|
13
|
+
|
14
|
+
| fluent-plugin-ec2-metadata | fluentd | ruby |
|
15
|
+
|--------------------|------------|--------|
|
16
|
+
| >= 0.0.16 | v0.14.x | >= 2.1 |
|
17
|
+
| 0.0.15 <= | v0.12.x | >= 1.9 |
|
18
|
+
|
12
19
|
## Installation
|
13
20
|
Use RubyGems:
|
14
21
|
|
data/Rakefile
CHANGED
@@ -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-ec2-metadata"
|
7
|
-
spec.version = "0.0
|
7
|
+
spec.version = "0.1.0"
|
8
8
|
spec.authors = ["SAKAMOTO Takumi"]
|
9
9
|
spec.email = ["takumi.saka@gmail.com"]
|
10
10
|
spec.description = %q{Fluentd output plugin to add ec2 metadata fields to a event record}
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_runtime_dependency "fluentd"
|
20
|
+
spec.add_runtime_dependency "fluentd", "> 0.14.0"
|
21
21
|
spec.add_runtime_dependency "oj"
|
22
22
|
spec.add_runtime_dependency "aws-sdk"
|
23
23
|
|
@@ -104,19 +104,19 @@ module Fluent
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def modify_record(record, tag, tag_parts)
|
107
|
-
@placeholder_expander.prepare_placeholders(record, tag, tag_parts, @ec2_metadata)
|
107
|
+
placeholders = @placeholder_expander.prepare_placeholders(record, tag, tag_parts, @ec2_metadata)
|
108
108
|
new_record = record.dup
|
109
|
-
@map.each_pair { |k, v| new_record[k] = @placeholder_expander.expand(v) }
|
109
|
+
@map.each_pair { |k, v| new_record[k] = @placeholder_expander.expand(v, placeholders) }
|
110
110
|
new_record
|
111
111
|
end
|
112
112
|
|
113
113
|
def modify(output_tag, record, tag, tag_parts)
|
114
|
-
@placeholder_expander.prepare_placeholders(record, tag, tag_parts, @ec2_metadata)
|
114
|
+
placeholders = @placeholder_expander.prepare_placeholders(record, tag, tag_parts, @ec2_metadata)
|
115
115
|
|
116
|
-
new_tag = @placeholder_expander.expand(output_tag)
|
116
|
+
new_tag = @placeholder_expander.expand(output_tag, placeholders)
|
117
117
|
|
118
118
|
new_record = record.dup
|
119
|
-
@map.each_pair { |k, v| new_record[k] = @placeholder_expander.expand(v) }
|
119
|
+
@map.each_pair { |k, v| new_record[k] = @placeholder_expander.expand(v, placeholders) }
|
120
120
|
|
121
121
|
[new_tag, new_record]
|
122
122
|
end
|
@@ -145,13 +145,13 @@ module Fluent
|
|
145
145
|
placeholders.store("${#{k}}", v)
|
146
146
|
}
|
147
147
|
|
148
|
-
|
148
|
+
placeholders
|
149
149
|
end
|
150
150
|
|
151
|
-
def expand(str)
|
151
|
+
def expand(str, placeholders)
|
152
152
|
str.gsub(/(\${[a-z_:\-]+(\[-?[0-9]+\])?}|__[A-Z_]+__)/) {
|
153
|
-
@log.warn "ec2-metadata: unknown placeholder `#{$1}` found in a tag `#{
|
154
|
-
|
153
|
+
@log.warn "ec2-metadata: unknown placeholder `#{$1}` found in a tag `#{placeholders['${tag}']}`" unless placeholders.include?($1)
|
154
|
+
placeholders[$1]
|
155
155
|
}
|
156
156
|
end
|
157
157
|
end
|
@@ -1,19 +1,15 @@
|
|
1
|
+
require 'fluent/plugin/filter'
|
1
2
|
require_relative 'ec2_metadata'
|
2
3
|
|
3
|
-
module Fluent
|
4
|
+
module Fluent::Plugin
|
4
5
|
class EC2MetadataFilter < Filter
|
5
6
|
include Fluent::EC2Metadata
|
6
7
|
|
7
8
|
Fluent::Plugin.register_filter('ec2_metadata', self)
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
config_param :aws_key_id, :string, :default => ENV['AWS_ACCESS_KEY_ID'], :secret => true
|
15
|
-
config_param :aws_sec_key, :string, :default => ENV['AWS_SECRET_ACCESS_KEY'], :secret => true
|
16
|
-
config_param :metadata_refresh_seconds, :integer, :default => 300
|
10
|
+
config_param :aws_key_id, :string, default: ENV['AWS_ACCESS_KEY_ID'], secret: true
|
11
|
+
config_param :aws_sec_key, :string, default: ENV['AWS_SECRET_ACCESS_KEY'], secret: true
|
12
|
+
config_param :metadata_refresh_seconds, :integer, default: 300
|
17
13
|
|
18
14
|
attr_reader :ec2_metadata
|
19
15
|
|
@@ -1,34 +1,27 @@
|
|
1
|
+
require 'fluent/plugin/output'
|
1
2
|
require_relative 'ec2_metadata'
|
2
3
|
|
3
|
-
module Fluent
|
4
|
+
module Fluent::Plugin
|
4
5
|
class EC2MetadataOutput < Output
|
5
|
-
include EC2Metadata
|
6
|
+
include Fluent::EC2Metadata
|
6
7
|
|
7
8
|
Fluent::Plugin.register_output('ec2_metadata', self)
|
8
9
|
|
9
|
-
|
10
|
-
unless method_defined?(:router)
|
11
|
-
define_method("router") { Fluent::Engine }
|
12
|
-
end
|
13
|
-
|
14
|
-
unless method_defined?(:log)
|
15
|
-
define_method(:log) { $log }
|
16
|
-
end
|
10
|
+
helpers :event_emitter
|
17
11
|
|
18
12
|
config_param :output_tag, :string
|
19
|
-
config_param :aws_key_id, :string, :
|
20
|
-
config_param :aws_sec_key, :string, :
|
21
|
-
config_param :metadata_refresh_seconds, :integer, :
|
13
|
+
config_param :aws_key_id, :string, default: ENV['AWS_ACCESS_KEY_ID'], secret: true
|
14
|
+
config_param :aws_sec_key, :string, default: ENV['AWS_SECRET_ACCESS_KEY'], secret: true
|
15
|
+
config_param :metadata_refresh_seconds, :integer, default: 300
|
22
16
|
|
23
17
|
attr_reader :ec2_metadata
|
24
18
|
|
25
|
-
def
|
19
|
+
def process(tag, es)
|
26
20
|
tag_parts = tag.split('.')
|
27
21
|
es.each { |time, record|
|
28
22
|
new_tag, new_record = modify(@output_tag, record, tag, tag_parts)
|
29
23
|
router.emit(new_tag, time, new_record)
|
30
24
|
}
|
31
|
-
chain.next
|
32
25
|
rescue => e
|
33
26
|
log.warn "ec2-metadata: #{e.class} #{e.message} #{e.backtrace.join(', ')}"
|
34
27
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fluent/test/driver/filter'
|
2
3
|
require 'fluent/plugin/filter_ec2_metadata'
|
3
4
|
|
4
5
|
require 'webmock/test_unit'
|
@@ -21,8 +22,8 @@ class EC2MetadataFilterTest < Test::Unit::TestCase
|
|
21
22
|
@time = Fluent::Engine.now
|
22
23
|
end
|
23
24
|
|
24
|
-
def create_driver(conf=CONFIG
|
25
|
-
Fluent::Test::
|
25
|
+
def create_driver(conf=CONFIG)
|
26
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::EC2MetadataFilter).configure(conf)
|
26
27
|
end
|
27
28
|
|
28
29
|
test 'configure-vpc' do
|
@@ -71,4 +72,26 @@ class EC2MetadataFilterTest < Test::Unit::TestCase
|
|
71
72
|
assert_equal(nil, d.instance.ec2_metadata['subnet_id'])
|
72
73
|
end
|
73
74
|
end
|
75
|
+
|
76
|
+
test 'emit' do
|
77
|
+
VCR.use_cassette('ec2-vpc') do
|
78
|
+
d = create_driver
|
79
|
+
|
80
|
+
d.run(default_tag: 'test') do
|
81
|
+
d.feed("a" => 1)
|
82
|
+
d.feed("a" => 2)
|
83
|
+
end
|
84
|
+
|
85
|
+
# record
|
86
|
+
mapped = {
|
87
|
+
'instance_id' => 'i-0c0c0000',
|
88
|
+
'az' => 'ap-northeast-1b',
|
89
|
+
'name' => 'instance-name',
|
90
|
+
}
|
91
|
+
assert_equal [
|
92
|
+
{"a" => 1}.merge(mapped),
|
93
|
+
{"a" => 2}.merge(mapped),
|
94
|
+
], d.filtered.map{|e| e.last}
|
95
|
+
end
|
96
|
+
end
|
74
97
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fluent/test/driver/output'
|
2
3
|
require 'fluent/plugin/out_ec2_metadata'
|
3
4
|
|
4
5
|
require 'webmock/test_unit'
|
@@ -23,8 +24,8 @@ class EC2MetadataOutputTest < Test::Unit::TestCase
|
|
23
24
|
@time = Fluent::Engine.now
|
24
25
|
end
|
25
26
|
|
26
|
-
def create_driver(conf=CONFIG
|
27
|
-
Fluent::Test::
|
27
|
+
def create_driver(conf=CONFIG)
|
28
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::EC2MetadataOutput).configure(conf)
|
28
29
|
end
|
29
30
|
|
30
31
|
test 'configure-vpc' do
|
@@ -85,14 +86,14 @@ class EC2MetadataOutputTest < Test::Unit::TestCase
|
|
85
86
|
VCR.use_cassette('ec2-vpc') do
|
86
87
|
d = create_driver
|
87
88
|
|
88
|
-
d.run do
|
89
|
-
d.
|
90
|
-
d.
|
89
|
+
d.run(default_tag: 'test') do
|
90
|
+
d.feed("a" => 1)
|
91
|
+
d.feed("a" => 2)
|
91
92
|
end
|
92
93
|
|
93
94
|
# tag
|
94
|
-
assert_equal "i-0c0c0000.test", d.
|
95
|
-
assert_equal "i-0c0c0000.test", d.
|
95
|
+
assert_equal "i-0c0c0000.test", d.events[0][0]
|
96
|
+
assert_equal "i-0c0c0000.test", d.events[1][0]
|
96
97
|
|
97
98
|
# record
|
98
99
|
mapped = {
|
@@ -104,7 +105,7 @@ class EC2MetadataOutputTest < Test::Unit::TestCase
|
|
104
105
|
assert_equal [
|
105
106
|
{"a" => 1}.merge(mapped),
|
106
107
|
{"a" => 2}.merge(mapped),
|
107
|
-
], d.
|
108
|
+
], d.events.map{|e| e.last}
|
108
109
|
end
|
109
110
|
end
|
110
111
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-ec2-metadata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SAKAMOTO Takumi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.14.0
|
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:
|
26
|
+
version: 0.14.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: oj
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,8 +118,6 @@ files:
|
|
118
118
|
- ".gitignore"
|
119
119
|
- ".travis.yml"
|
120
120
|
- Gemfile
|
121
|
-
- Gemfile.fluentd.0.10
|
122
|
-
- Gemfile.fluentd.0.12
|
123
121
|
- LICENSE.txt
|
124
122
|
- README.md
|
125
123
|
- Rakefile
|
@@ -152,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
150
|
version: '0'
|
153
151
|
requirements: []
|
154
152
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.5.1
|
156
154
|
signing_key:
|
157
155
|
specification_version: 4
|
158
156
|
summary: Fluentd output plugin to add ec2 metadata fields to a event record
|
data/Gemfile.fluentd.0.10
DELETED