fluent-plugin-firehose 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1832232fd08b3cf765a87159f2348131214d9961
4
- data.tar.gz: 179946e340284b3d2be5523fa971fa73d2d45c23
3
+ metadata.gz: 67653d5f46420f2c391caa4f8b50bcdefc618646
4
+ data.tar.gz: a09fa7105153c273f3eb780b588710eab8b6331d
5
5
  SHA512:
6
- metadata.gz: 027c739ac55cc5be2810bbbbfcacf9782dcb5d747f4410f06242cb1449938fb0981b93f1ff62e999528e6376e2e682c74661d8a84c542134be0b80570a6e118c
7
- data.tar.gz: 92645124927c2e12e934a2a7438992b51a31843a63be4fef1423a8e2139d6353f5df12582a43044a9459a49a5e42f207dffafe285a8fb56cd8a737bfe07d3845
6
+ metadata.gz: 5eafd1d3e552b28305b75bf6784d70bff87c2636287b2bf232609d8eabe387e07163826926db6feb3ed59b6129181f1fe718b50ceeb938fbf9a4287028d42d47
7
+ data.tar.gz: 86f679869790d209afdd087b590fe2878e8564bd0e6ba45d1cc5f973ad95d428810cb40ef3d12a652aea18fb1aada093e42027abd82dc75b85cccad06d464eef
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.0.1 Forked from https://github.com/awslabs/aws-fluent-plugin-kinesis
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # Copyright 2015 Ji Oh Yoo
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # may not use this file except in compliance with the License. A copy of
6
+ # the License is located at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # or in the "license" file accompanying this file. This file is
11
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # ANY KIND, either express or implied. See the License for the specific
13
+ # language governing permissions and limitations under the License.
14
+
15
+ source 'https://rubygems.org'
16
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-firehose (0.0.2)
5
+ aws-sdk-core (>= 2.0.12, < 3.0)
6
+ fluentd (>= 0.10.53, < 0.13)
7
+ msgpack (>= 0.5.8)
8
+ multi_json (~> 1.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ aws-sdk-core (2.2.4)
14
+ jmespath (~> 1.0)
15
+ cool.io (1.4.2)
16
+ fluentd (0.12.17)
17
+ cool.io (>= 1.2.2, < 2.0.0)
18
+ http_parser.rb (>= 0.5.1, < 0.7.0)
19
+ json (>= 1.4.3)
20
+ msgpack (>= 0.5.11, < 0.6.0)
21
+ sigdump (~> 0.2.2)
22
+ string-scrub (>= 0.0.3)
23
+ tzinfo (>= 1.0.0)
24
+ tzinfo-data (>= 1.0.0)
25
+ yajl-ruby (~> 1.0)
26
+ http_parser.rb (0.6.0)
27
+ jmespath (1.1.3)
28
+ json (1.8.3)
29
+ msgpack (0.5.12)
30
+ multi_json (1.11.2)
31
+ power_assert (0.2.6)
32
+ rake (10.4.2)
33
+ rr (1.1.2)
34
+ sigdump (0.2.3)
35
+ string-scrub (0.0.5)
36
+ test-unit (3.1.5)
37
+ power_assert
38
+ test-unit-rr (1.0.3)
39
+ rr (>= 1.1.1)
40
+ test-unit (>= 2.5.2)
41
+ thread_safe (0.3.5)
42
+ tzinfo (1.2.2)
43
+ thread_safe (~> 0.1)
44
+ tzinfo-data (1.2015.7)
45
+ tzinfo (>= 1.0.0)
46
+ yajl-ruby (1.2.1)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 1.3)
53
+ fluent-plugin-firehose!
54
+ rake (~> 10.0)
55
+ test-unit-rr (~> 1.0)
56
+
57
+ BUNDLED WITH
58
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,203 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
191
+ Copyright 2015 Ji Oh Yoo
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # Fluent Plugin for Amazon Kinesis Firehose
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # Copyright 2015 Ji Oh Yoo
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # may not use this file except in compliance with the License. A copy of
6
+ # the License is located at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # or in the "license" file accompanying this file. This file is
11
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # ANY KIND, either express or implied. See the License for the specific
13
+ # language governing permissions and limitations under the License.
14
+
15
+ require "bundler/gem_tasks"
16
+
17
+ require 'rake/testtask'
18
+ Rake::TestTask.new(:test) do |test|
19
+ test.libs << 'lib' << 'test'
20
+ test.pattern = 'test/**/test_*.rb'
21
+ test.verbose = true
22
+ end
23
+
24
+ task :default => :test
@@ -0,0 +1,42 @@
1
+ # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # Copyright 2015 Ji Oh Yoo
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # may not use this file except in compliance with the License. A copy of
6
+ # the License is located at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # or in the "license" file accompanying this file. This file is
11
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # ANY KIND, either express or implied. See the License for the specific
13
+ # language governing permissions and limitations under the License.
14
+
15
+ # coding: utf-8
16
+ lib = File.expand_path('../lib', __FILE__)
17
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
18
+
19
+ require "fluent/plugin/version"
20
+
21
+ Gem::Specification.new do |spec|
22
+ spec.name = "fluent-plugin-firehose"
23
+ spec.version = FluentPluginFirehose::VERSION
24
+ spec.author = ['Ji Oh Yoo', 'Amazon Web Services']
25
+ spec.summary = %q{Fluentd output plugin that sends events to Amazon Kinesis Firehose.}
26
+ spec.license = "Apache License, Version 2.0"
27
+
28
+ spec.files = `git ls-files`.split($/)
29
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
30
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
31
+ spec.require_paths = ["lib"]
32
+ spec.required_ruby_version = '>= 1.9.3'
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.3"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "test-unit-rr", "~> 1.0"
37
+
38
+ spec.add_dependency "fluentd", ">= 0.10.53", "< 0.13"
39
+ spec.add_dependency "aws-sdk-core", ">= 2.0.12", "< 3.0"
40
+ spec.add_dependency "multi_json", "~> 1.0"
41
+ spec.add_dependency "msgpack", ">= 0.5.8"
42
+ end
@@ -0,0 +1,265 @@
1
+ # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # Copyright 2015 Ji Oh Yoo
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # may not use this file except in compliance with the License. A copy of
6
+ # the License is located at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # or in the "license" file accompanying this file. This file is
11
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # ANY KIND, either express or implied. See the License for the specific
13
+ # language governing permissions and limitations under the License.
14
+
15
+ require 'aws-sdk-core'
16
+ require 'multi_json'
17
+ require 'yajl'
18
+ require 'logger'
19
+ require 'securerandom'
20
+ require 'fluent/plugin/version'
21
+ require 'zlib'
22
+
23
+ module FluentPluginFirehose
24
+ class FirehoseBufferedOutput < Fluent::BufferedOutput
25
+
26
+ include Fluent::DetachMultiProcessMixin
27
+ include Fluent::SetTimeKeyMixin
28
+ include Fluent::SetTagKeyMixin
29
+
30
+ USER_AGENT_NAME = 'fluent-plugin-kinesis-output-filter'
31
+ PUT_RECORD_MAX_DATA_SIZE = 1000 * 1024 # 1000 KB
32
+ PUT_RECORD_BATCH_MAX_COUNT = 500
33
+ PUT_RECORD_BATCH_MAX_DATA_SIZE = 4 * 1024 * 1024 # 4 MB
34
+
35
+ Fluent::Plugin.register_output('firehose', self)
36
+
37
+ config_set_default :include_time_key, true
38
+ config_set_default :include_tag_key, true
39
+
40
+ config_param :aws_key_id, :string, default: nil, :secret => true
41
+ config_param :aws_sec_key, :string, default: nil, :secret => true
42
+ # The 'region' parameter is optional because
43
+ # it may be set as an environment variable.
44
+ config_param :region, :string, default: nil
45
+ config_param :ensure_stream_connection, :bool, default: true
46
+
47
+ config_param :profile, :string, :default => nil
48
+ config_param :credentials_path, :string, :default => nil
49
+ config_param :role_arn, :string, :default => nil
50
+ config_param :external_id, :string, :default => nil
51
+
52
+ config_param :delivery_stream_name, :string
53
+ config_param :order_events, :bool, default: false
54
+ config_param :retries_on_putrecordbatch, :integer, default: 3
55
+ config_param :use_yajl, :bool, default: false
56
+ config_param :zlib_compression, :bool, default: false
57
+
58
+ config_param :debug, :bool, default: false
59
+
60
+ config_param :http_proxy, :string, default: nil
61
+
62
+ def configure(conf)
63
+ super
64
+
65
+ if @detach_process or (@num_threads > 1)
66
+ @parallel_mode = true
67
+ if @detach_process
68
+ @use_detach_multi_process_mixin = true
69
+ end
70
+ else
71
+ @parallel_mode = false
72
+ end
73
+
74
+ if @parallel_mode
75
+ if @order_events
76
+ log.warn 'You have set "order_events" to true, however this configuration will be ignored due to "detach_process" and/or "num_threads".'
77
+ end
78
+ @order_events = false
79
+ end
80
+
81
+ @dump_class = @use_yajl ? Yajl : JSON
82
+ end
83
+
84
+ def start
85
+ detach_multi_process do
86
+ super
87
+ load_client
88
+ if @ensure_stream_connection
89
+ check_connection_to_stream
90
+ end
91
+ end
92
+ end
93
+
94
+ def format(tag, time, record)
95
+ data = {
96
+ data: @dump_class.dump(record)
97
+ }
98
+
99
+ data.to_msgpack
100
+ end
101
+
102
+ def write(chunk)
103
+ data_list = chunk.to_enum(:msgpack_each).map{|record|
104
+ build_data_to_put(record)
105
+ }.find_all{|record|
106
+ unless record_exceeds_max_size?(record[:data])
107
+ true
108
+ else
109
+ log.error sprintf('Record exceeds the %.3f KB(s) per-record size limit and will not be delivered: %s', PUT_RECORD_MAX_DATA_SIZE / 1024.0, record[:data])
110
+ false
111
+ end
112
+ }
113
+
114
+ if @order_events
115
+ put_record_for_order_events(data_list)
116
+ else
117
+ records_array = build_records_array_to_put(data_list)
118
+ records_array.each{|records|
119
+ put_records_with_retry(records)
120
+ }
121
+ end
122
+ end
123
+
124
+ def load_client
125
+ user_agent_suffix = "#{USER_AGENT_NAME}/#{FluentPluginFirehose::VERSION}"
126
+
127
+ options = {
128
+ user_agent_suffix: user_agent_suffix
129
+ }
130
+
131
+ if @region
132
+ options[:region] = @region
133
+ end
134
+
135
+ if @aws_key_id && @aws_sec_key
136
+ options.update(
137
+ access_key_id: @aws_key_id,
138
+ secret_access_key: @aws_sec_key,
139
+ )
140
+ elsif @profile
141
+ credentials_opts = {:profile_name => @profile}
142
+ credentials_opts[:path] = @credentials_path if @credentials_path
143
+ credentials = Aws::SharedCredentials.new(credentials_opts)
144
+ options[:credentials] = credentials
145
+ elsif @role_arn
146
+ credentials = Aws::AssumeRoleCredentials.new(
147
+ client: Aws::STS::Client.new(options),
148
+ role_arn: @role_arn,
149
+ role_session_name: "aws-fluent-plugin-kinesis",
150
+ external_id: @external_id,
151
+ duration_seconds: 60 * 60
152
+ )
153
+ options[:credentials] = credentials
154
+ end
155
+
156
+ if @debug
157
+ options.update(
158
+ logger: Logger.new(log.out),
159
+ log_level: :debug
160
+ )
161
+ # XXX: Add the following options, if necessary
162
+ # :http_wire_trace => true
163
+ end
164
+
165
+ if @http_proxy
166
+ options[:http_proxy] = @http_proxy
167
+ end
168
+
169
+ @client = Aws::Firehose::Client.new(options)
170
+
171
+ end
172
+
173
+ def check_connection_to_stream
174
+ @client.describe_stream(delivery_stream_name: @delivery_stream_name)
175
+ end
176
+
177
+ def build_data_to_put(data)
178
+ if @zlib_compression
179
+ Hash[data.map{|k, v| [k.to_sym, k=="data" ? Zlib::Deflate.deflate(v) : v] }]
180
+ else
181
+ Hash[data.map{|k, v| [k.to_sym, v] }]
182
+ end
183
+ end
184
+
185
+ def put_record_for_order_events(data_list)
186
+ sequence_number_for_ordering = nil
187
+ data_list.each do |data_to_put|
188
+ if sequence_number_for_ordering
189
+ data_to_put.update(
190
+ sequence_number_for_ordering: sequence_number_for_ordering
191
+ )
192
+ end
193
+ data_to_put.update(
194
+ delivery_stream_name: @delivery_stream_name
195
+ )
196
+ result = @client.put_record(data_to_put)
197
+ sequence_number_for_ordering = result[:sequence_number]
198
+ end
199
+ end
200
+
201
+ def build_records_array_to_put(data_list)
202
+ records_array = []
203
+ records = []
204
+ records_payload_length = 0
205
+ data_list.each{|data_to_put|
206
+ payload = data_to_put[:data]
207
+ if records.length >= PUT_RECORD_BATCH_MAX_COUNT or (records_payload_length + payload.length) >= PUT_RECORD_BATCH_MAX_DATA_SIZE
208
+ records_array.push(records)
209
+ records = []
210
+ records_payload_length = 0
211
+ end
212
+ records.push(data_to_put)
213
+ records_payload_length += payload.length
214
+ }
215
+ records_array.push(records) unless records.empty?
216
+ records_array
217
+ end
218
+
219
+ def put_records_with_retry(records,retry_count=0)
220
+ response = @client.put_records(
221
+ records: records,
222
+ delivery_stream_name: @delivery_stream_name
223
+ )
224
+
225
+ if response[:failed_put_count] && response[:failed_put_count] > 0
226
+ failed_records = []
227
+ response[:request_responses].each_with_index{|record,index|
228
+ if record[:error_code]
229
+ failed_records.push({body: records[index], error_code: record[:error_code]})
230
+ end
231
+ }
232
+
233
+ if(retry_count < @retries_on_putrecordbatch)
234
+ sleep(calculate_sleep_duration(retry_count))
235
+ retry_count += 1
236
+ log.warn sprintf('Retrying to put records. Retry count: %d', retry_count)
237
+ put_records_with_retry(
238
+ failed_records.map{|record| record[:body]},
239
+ retry_count
240
+ )
241
+ else
242
+ failed_records.each{|record|
243
+ log.error sprintf(
244
+ 'Could not put record, Error: %s, Record: %s',
245
+ record[:error_code],
246
+ @dump_class.dump(record[:body])
247
+ )
248
+ }
249
+ end
250
+ end
251
+ end
252
+
253
+ def calculate_sleep_duration(current_retry)
254
+ Array.new(@retries_on_putrecords){|n| ((2 ** n) * scaling_factor)}[current_retry]
255
+ end
256
+
257
+ def scaling_factor
258
+ 0.5 + Kernel.rand * 0.1
259
+ end
260
+
261
+ def record_exceeds_max_size?(record_string)
262
+ return record_string.length > PUT_RECORD_MAX_DATA_SIZE
263
+ end
264
+ end
265
+ end
@@ -0,0 +1,17 @@
1
+ # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ # Copyright 2015 Ji Oh Yoo
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # may not use this file except in compliance with the License. A copy of
6
+ # the License is located at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # or in the "license" file accompanying this file. This file is
11
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # ANY KIND, either express or implied. See the License for the specific
13
+ # language governing permissions and limitations under the License.
14
+
15
+ module FluentPluginFirehose
16
+ VERSION = '0.0.2'
17
+ end