fluent-plugin-kinesis-alt 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfc7866ce0006f1ffdcfb0f0ecdc30558a5df997
4
+ data.tar.gz: e45f0d00255c99bc6cd786fc54f322e081c43f36
5
+ SHA512:
6
+ metadata.gz: 98706b5fe436280c1ab66fa3191137b9936ea9db6dcacc1d6033761438d3f2fd4ef906b8b6174639542b9e63520c8199bb338bdb94ed2da6af2c2fa99bd3b3c3
7
+ data.tar.gz: 744f4540579994a7ec5448215cdcd2bc57fa767c5ffabdb569c0bb7d87f1c20e7b157c20940d50fa9a58eef10a07d9e01c0f009f01af12821c66efbfd93d2cc1
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-kinesis-alt.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Genki Sugawara
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ # fluent-plugin-kinesis-alt
2
+
3
+ Output filter plugin for Amazon Kinesis
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-kinesis-alt'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-kinesis-alt
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ ```
24
+ <match kinesis.**>
25
+ type kinesis_alt
26
+ aws_key_id ...
27
+ aws_sec_key ...
28
+ region us-east-1
29
+
30
+ stream_name your_stream_name
31
+
32
+ #partition_key any_json_key
33
+
34
+ # partition_key:
35
+ # JSON Object Hash Key for PartitionKey
36
+ # e.g.)
37
+ # JSON Object: {'foo': 100, 'bar': 200}
38
+ # fluent config: partition_key=foo
39
+ # -> PutRecord Action: PartitionKey=100
40
+
41
+ partition_key_proc proc {|i| Time.now.to_i.to_s }
42
+
43
+ # partition_key_proc:
44
+ # Ruby Code to create PartitionKey
45
+ # e.g.)
46
+ # fluent config: partition_key_proc=proc {|i| 100 + 200 }
47
+ # -> PutRecord Action: PartitionKey=300
48
+
49
+ #explicit_hash_key ...
50
+ #explicit_hash_key_proc ...
51
+
52
+ #debug false
53
+ #include_tag true
54
+ #include_time true
55
+
56
+ flush_interval 3
57
+ </match>
58
+ ```
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'fluent-plugin-kinesis-alt'
7
+ spec.version = '0.0.1'
8
+ spec.authors = ['Genki Sugawara']
9
+ spec.email = ['sgwr_dts@yahoo.co.jp']
10
+ spec.description = 'Output filter plugin for Amazon Kinesis'
11
+ spec.summary = 'Output filter plugin for Amazon Kinesis'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'fluentd'
20
+ spec.add_dependency 'aws-sdk', '>= 1.31.3'
21
+ spec.add_dependency 'json'
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,142 @@
1
+ module Fluent
2
+ class KinesisAltOutput < Fluent::BufferedOutput
3
+ Fluent::Plugin.register_output('kinesis_alt', self)
4
+
5
+ def initialize
6
+ super
7
+ require 'aws-sdk'
8
+ require 'base64'
9
+ require 'json'
10
+ require 'logger'
11
+ end
12
+
13
+ config_param :aws_key_id, :string, :default => nil
14
+ config_param :aws_sec_key, :string, :default => nil
15
+ config_param :region, :string, :default => nil
16
+
17
+ config_param :stream_name, :string, :default => nil
18
+ config_param :partition_key, :string, :default => nil
19
+ config_param :partition_key_proc, :string, :default => nil
20
+ config_param :explicit_hash_key, :string, :default => nil
21
+ config_param :explicit_hash_key_proc, :string, :default => nil
22
+
23
+ config_param :sequence_number_for_ordering, :string, :default => nil
24
+
25
+ config_param :include_tag, :bool, :default => true
26
+ config_param :include_time, :bool, :default => true
27
+ config_param :debug, :bool, :default => false
28
+
29
+ def configure(conf)
30
+ super
31
+
32
+ [:aws_key_id, :aws_sec_key, :region, :stream_name].each do |name|
33
+ unless self.instance_variable_get("@#{name}")
34
+ raise ConfigError, "'#{name}' is required"
35
+ end
36
+ end
37
+
38
+ unless @partition_key or @partition_key_proc
39
+ raise ConfigError, "'partition_key' or 'partition_key_proc' is required"
40
+ end
41
+
42
+ if @partition_key_proc
43
+ @partition_key_proc = eval(@partition_key_proc)
44
+ end
45
+
46
+ if @explicit_hash_key_proc
47
+ @explicit_hash_key_proc = eval(@explicit_hash_key_proc)
48
+ end
49
+ end
50
+
51
+ def start
52
+ super
53
+ configure_aws
54
+ @client = AWS.kinesis.client
55
+ @client.describe_stream(:stream_name => @stream_name)
56
+ end
57
+
58
+ def shutdown
59
+ super
60
+ end
61
+
62
+ def format(tag, time, record)
63
+ record['__tag'] = tag if @include_tag
64
+ record['__time'] = time if @include_time
65
+
66
+ # XXX: The maximum size of the data blob is 50 kilobytes
67
+ # http://docs.aws.amazon.com/kinesis/latest/APIReference/API_PutRecord.html
68
+ data = {
69
+ :stream_name => @stream_name,
70
+ :data => encode64(record.to_json),
71
+ :partition_key => get_key(:partition_key, record)
72
+ }
73
+
74
+ if @explicit_hash_key or @explicit_hash_key_proc
75
+ data[:explicit_hash_key] = get_key(:explicit_hash_key, record)
76
+ end
77
+
78
+ if @sequence_number_for_ordering
79
+ data[:sequence_number_for_ordering] = @sequence_number_for_ordering
80
+ end
81
+
82
+ pack_data(data)
83
+ end
84
+
85
+ def write(chunk)
86
+ buf = chunk.read
87
+
88
+ while (data = unpack_data(buf))
89
+ AWS.kinesis.client.put_record(data)
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def configure_aws
96
+ options = {
97
+ :access_key_id => @aws_key_id ,
98
+ :secret_access_key => @aws_sec_key,
99
+ :region => @region
100
+ }
101
+
102
+ if @debug
103
+ options.update(
104
+ :logger => Logger.new($log.out),
105
+ :log_level => :debug,
106
+ #:http_wire_trace => true
107
+ )
108
+ end
109
+
110
+ AWS.config(options)
111
+ end
112
+
113
+ def get_key(name, record)
114
+ key = self.instance_variable_get("@#{name}")
115
+ key_proc = self.instance_variable_get("@#{name}_proc")
116
+
117
+ value = key ? record[key] : record
118
+ value = key_proc.call(value) if key_proc
119
+
120
+ value.to_s
121
+ end
122
+
123
+ def pack_data(data)
124
+ data = data.to_msgpack(data)
125
+ data.force_encoding('ascii-8bit')
126
+ [data.length].pack('L') + data
127
+ end
128
+
129
+ def unpack_data(buf)
130
+ return nil if buf.empty?
131
+
132
+ buf.force_encoding('ascii-8bit')
133
+ length = buf.slice!(0, 4).unpack('L').first
134
+ data = buf.slice!(0, length)
135
+ MessagePack.unpack(data)
136
+ end
137
+
138
+ def encode64(str)
139
+ Base64.encode64(str).delete("\n")
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'test/unit'
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+
17
+ require 'fluent/test'
18
+
19
+ unless ENV.has_key?('VERBOSE')
20
+ nulllogger = Object.new
21
+
22
+ nulllogger.instance_eval do |obj|
23
+ def method_missing(method, *args); end
24
+ end
25
+
26
+ $log = nulllogger
27
+ end
28
+
29
+ require 'fluent/plugin/out_kinesis_alt'
30
+
31
+ class Test::Unit::TestCase
32
+ end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+
3
+ class KinesisAltOutputTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ ]
10
+ # CONFIG = %[
11
+ # path #{TMP_DIR}/out_file_test
12
+ # compress gz
13
+ # utc
14
+ # ]
15
+
16
+ def create_driver(conf = CONFIG, tag='test')
17
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::KinesisAltOutput, tag).configure(conf)
18
+ end
19
+
20
+ def test_configure
21
+ #### set configurations
22
+ # d = create_driver %[
23
+ # path test_path
24
+ # compress gz
25
+ # ]
26
+ #### check configurations
27
+ # assert_equal 'test_path', d.instance.path
28
+ # assert_equal :gz, d.instance.compress
29
+ end
30
+
31
+ def test_format
32
+ #d = create_driver
33
+
34
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
35
+ # d.emit({"a"=>1}, time)
36
+ # d.emit({"a"=>2}, time)
37
+
38
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
39
+ # d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]
40
+
41
+ # d.run
42
+ end
43
+
44
+ def test_write
45
+ #d = create_driver
46
+
47
+ # time = Time.parse("2011-01-02 13:14:15 UTC").to_i
48
+ # d.emit({"a"=>1}, time)
49
+ # d.emit({"a"=>2}, time)
50
+
51
+ # ### FileOutput#write returns path
52
+ # path = d.run
53
+ # expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
54
+ # assert_equal expect_path, path
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-kinesis-alt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.31.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.31.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Output filter plugin for Amazon Kinesis
84
+ email:
85
+ - sgwr_dts@yahoo.co.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - fluent-plugin-kinesis-alt.gemspec
96
+ - lib/fluent/plugin/out_kinesis_alt.rb
97
+ - test/helper.rb
98
+ - test/plugin/test_out_kinesis_alt.rb
99
+ homepage: ''
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.0.14
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Output filter plugin for Amazon Kinesis
123
+ test_files:
124
+ - test/helper.rb
125
+ - test/plugin/test_out_kinesis_alt.rb