fluent-plugin-kinesis-firehose 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b2471dffd3f9f27c10aca52f31cb38d7064e8d6
4
+ data.tar.gz: e7deee8fcf20ab6716addb4b777450c83a548913
5
+ SHA512:
6
+ metadata.gz: 4ea4ccbad15ea093a96e0e826688a72e51b27ebc2893d52b1fe5f2bd5ee2dc856a3eaecb00ed3b60ff948edd4c29a3d5df907ceea7e7f62587e5a12a1047ab80
7
+ data.tar.gz: 27ef882a71dc233c32b493c72ba6a8aa8f2f4e934adcc82b6a10f4ce36c1285fcddf21ed235dfe4650ab38d13263c60e3fb9dde06f5d668b2ab68967769a175f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ fluent.conf
11
+ test.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-kinesis-firehose.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Genki Sugawara
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # fluent-plugin-kinesis-firehose
2
+
3
+ Fluentd output plugin for Amazon Kinesis Firehose.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fluent-plugin-kinesis-firehose'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fluent-plugin-kinesis-firehose
20
+
21
+ ## Configuration
22
+
23
+ ```apache
24
+ <match kinesis.data>
25
+ @type kinesis_firehose
26
+
27
+ delivery_stream_name DeliveryStreamName
28
+
29
+ #profile ...
30
+ #credentials_path ...
31
+ #aws_key_id ...
32
+ #aws_sec_key ...
33
+ region us-east-1
34
+ #endpoint ...
35
+
36
+ #data_key data (default: nil)
37
+
38
+ # Put a data_key value if data_key is set
39
+ # {... "data":"xxx" ...}
40
+ # Put a record as JSON if data_key is not set
41
+
42
+ #append_new_line true
43
+
44
+ #include_time_key false
45
+ #include_tag_key false
46
+
47
+ flush_interval 1s
48
+ </match>
49
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/kinesis/firehose"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent_plugin_kinesis_firehose/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fluent-plugin-kinesis-firehose'
8
+ spec.version = FluentPluginKinesisFirehose::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sugawara@cookpad.com']
11
+
12
+ spec.summary = %q{Fluentd output plugin for Amazon Kinesis Firehose.}
13
+ spec.description = %q{Fluentd output plugin for Amazon Kinesis Firehose.}
14
+ spec.homepage = 'https://github.com/winebarrel/fluent-plugin-kinesis-firehose'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'fluentd'
23
+ spec.add_dependency 'aws-sdk', '~> 2.1.28'
24
+ spec.add_dependency 'multi_json'
25
+
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'test-unit', '>= 3.1.0'
30
+ end
@@ -0,0 +1,126 @@
1
+ require "fluent_plugin_kinesis_firehose/version"
2
+
3
+ class Fluent::KinesisFirehoseOutput < Fluent::BufferedOutput
4
+ Fluent::Plugin.register_output('kinesis_firehose', self)
5
+
6
+ include Fluent::SetTimeKeyMixin
7
+ include Fluent::SetTagKeyMixin
8
+
9
+ USER_AGENT_SUFFIX = "fluent-plugin-kinesis-firehose/#{FluentPluginKinesisFirehose::VERSION}"
10
+ PUT_RECORDS_MAX_COUNT = 500
11
+ PUT_RECORDS_MAX_DATA_SIZE = 1024 * 1024 * 4
12
+
13
+ unless method_defined?(:log)
14
+ define_method('log') { $log }
15
+ end
16
+
17
+ config_param :profile, :string, :default => nil
18
+ config_param :credentials_path, :string, :default => nil
19
+ config_param :aws_key_id, :string, :default => nil
20
+ config_param :aws_sec_key, :string, :default => nil
21
+ config_param :region, :string, :default => nil
22
+ config_param :endpoint, :string, :default => nil
23
+ config_param :http_proxy, :string, :default => nil
24
+ config_param :delivery_stream_name, :string
25
+ config_param :data_key, :string, :default => nil
26
+ config_param :append_new_line, :bool, :default => true
27
+
28
+ def initialize
29
+ super
30
+ require 'aws-sdk'
31
+ require 'multi_json'
32
+ end
33
+
34
+ def configure(conf)
35
+ super
36
+ end
37
+
38
+ def format(tag, time, record)
39
+ [tag, time, record].to_msgpack
40
+ end
41
+
42
+ def write(chunk)
43
+ chunk = chunk.to_enum(:msgpack_each)
44
+
45
+ chunk.select {|tag, time, record|
46
+ if not @data_key or record[@data_key]
47
+ true
48
+ else
49
+ log.warn("'#{@data_key}' key does not exist: #{[tag, time, record].inspect}")
50
+ false
51
+ end
52
+ }.map {|tag, time, record|
53
+ convert_record_to_data(record)
54
+ }.each_slice(PUT_RECORDS_MAX_COUNT, &method(:put_records))
55
+ end
56
+
57
+ private
58
+
59
+ def convert_record_to_data(record)
60
+ if @data_key
61
+ data = record[@data_key].to_s
62
+ else
63
+ data = MultiJson.dump(record)
64
+ end
65
+
66
+ if @append_new_line
67
+ data + "\n"
68
+ else
69
+ data
70
+ end
71
+ end
72
+
73
+ def put_records(data_list)
74
+ state = 0
75
+
76
+ data_list.slice_before {|data|
77
+ data_size = data.size
78
+ state += data_size
79
+
80
+ if PUT_RECORDS_MAX_DATA_SIZE < state
81
+ state = data_size
82
+ true
83
+ else
84
+ false
85
+ end
86
+ }.each(&method(:put_record_batch))
87
+ end
88
+
89
+ def put_record_batch(data_list)
90
+ records = data_list.map do |data|
91
+ {:data => data}
92
+ end
93
+
94
+ client.put_record_batch(
95
+ :delivery_stream_name => @delivery_stream_name,
96
+ :records => records
97
+ )
98
+ end
99
+
100
+ def client
101
+ return @client if @client
102
+
103
+ options = {:user_agent_suffix => USER_AGENT_SUFFIX}
104
+ options[:region] = @region if @region
105
+ options[:endpoint] = @endpoint if @endpoint
106
+ options[:http_proxy] = @http_proxy if @http_proxy
107
+
108
+ if @aws_key_id and @aws_sec_key
109
+ options[:access_key_id] = @aws_key_id
110
+ options[:secret_access_key] = @aws_sec_key
111
+ elsif @profile
112
+ credentials_opts = {:profile_name => @profile}
113
+ credentials_opts[:path] = @credentials_path if @credentials_path
114
+ credentials = Aws::SharedCredentials.new(credentials_opts)
115
+ options[:credentials] = credentials
116
+ end
117
+
118
+ if @debug
119
+ options[:logger] = Logger.new(log.out)
120
+ options[:log_level] = :debug
121
+ #options[:http_wire_trace] = true
122
+ end
123
+
124
+ @client = Aws::Firehose::Client.new(options)
125
+ end
126
+ end
@@ -0,0 +1,3 @@
1
+ module FluentPluginKinesisFirehose
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-kinesis-firehose
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-11 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: 2.1.28
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.28
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
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
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-unit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.1.0
111
+ description: Fluentd output plugin for Amazon Kinesis Firehose.
112
+ email:
113
+ - sugawara@cookpad.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - fluent-plugin-kinesis-firehose.gemspec
128
+ - lib/fluent/plugin/out_kinesis_firehose.rb
129
+ - lib/fluent_plugin_kinesis_firehose/version.rb
130
+ homepage: https://github.com/winebarrel/fluent-plugin-kinesis-firehose
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.5
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Fluentd output plugin for Amazon Kinesis Firehose.
154
+ test_files: []