fluent-plugin-kinesis 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -23
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile +9 -9
  5. data/LICENSE.txt +201 -40
  6. data/Makefile +24 -31
  7. data/README.md +179 -308
  8. data/Rakefile +9 -13
  9. data/benchmark/task.rake +96 -58
  10. data/fluent-plugin-kinesis.gemspec +15 -19
  11. data/gemfiles/Gemfile.fluentd-0.12 +10 -10
  12. data/lib/fluent/plugin/kinesis.rb +166 -0
  13. data/lib/fluent/plugin/kinesis_helper/aggregator.rb +99 -0
  14. data/lib/fluent/plugin/kinesis_helper/api.rb +152 -121
  15. data/lib/fluent/plugin/kinesis_helper/client.rb +125 -12
  16. data/lib/fluent/plugin/out_kinesis_firehose.rb +40 -27
  17. data/lib/fluent/plugin/out_kinesis_streams.rb +51 -30
  18. data/lib/fluent/plugin/out_kinesis_streams_aggregated.rb +76 -0
  19. data/lib/fluent_plugin_kinesis/version.rb +10 -10
  20. metadata +18 -70
  21. data/README-v0.4.md +0 -348
  22. data/benchmark/dummy.conf +0 -0
  23. data/gemfiles/Gemfile.aws-sdk-2.4 +0 -20
  24. data/gemfiles/Gemfile.fluentd-0.10.58 +0 -20
  25. data/gemfiles/Gemfile.fluentd-0.14.11 +0 -20
  26. data/gemfiles/Gemfile.ruby-2.0 +0 -21
  27. data/gemfiles/Gemfile.ruby-2.1 +0 -21
  28. data/lib/fluent/plugin/kinesis_helper.rb +0 -36
  29. data/lib/fluent/plugin/kinesis_helper/class_methods.rb +0 -123
  30. data/lib/fluent/plugin/kinesis_helper/credentials.rb +0 -51
  31. data/lib/fluent/plugin/kinesis_helper/error.rb +0 -43
  32. data/lib/fluent/plugin/kinesis_helper/format.rb +0 -85
  33. data/lib/fluent/plugin/kinesis_helper/initialize.rb +0 -59
  34. data/lib/fluent/plugin/kinesis_helper/kpl.rb +0 -82
  35. data/lib/fluent/plugin/out_kinesis.rb +0 -323
  36. data/lib/fluent/plugin/out_kinesis_producer.rb +0 -48
  37. data/lib/fluent/plugin/patched_detach_process_impl.rb +0 -103
  38. data/lib/kinesis_producer.rb +0 -24
  39. data/lib/kinesis_producer/binary.rb +0 -10
  40. data/lib/kinesis_producer/daemon.rb +0 -270
  41. data/lib/kinesis_producer/library.rb +0 -122
  42. data/lib/kinesis_producer/protobuf/config.pb.rb +0 -66
  43. data/lib/kinesis_producer/protobuf/messages.pb.rb +0 -151
  44. data/lib/kinesis_producer/tasks/binary.rake +0 -73
@@ -1,24 +0,0 @@
1
- #
2
- # Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- #
4
- # Licensed under the Amazon Software License (the "License").
5
- # You may not use this file except in compliance with the License.
6
- # A copy of the License is located at
7
- #
8
- # http://aws.amazon.com/asl/
9
- #
10
- # or in the "license" file accompanying this file. This file is distributed
11
- # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
- # express or implied. See the License for the specific language governing
13
- # permissions and limitations under the License.
14
-
15
- require 'protobuf'
16
- require 'kinesis_producer/binary'
17
- require 'kinesis_producer/library'
18
- require 'kinesis_producer/daemon'
19
- require 'kinesis_producer/protobuf/config.pb'
20
- require 'kinesis_producer/protobuf/messages.pb'
21
-
22
- module KinesisProducer
23
- ConfigurationFields = Protobuf::Configuration.all_fields.reject(&:repeated?)
24
- end
@@ -1,10 +0,0 @@
1
- module KinesisProducer
2
- class Binary
3
- Dir = 'amazon-kinesis-producer-native-binaries'
4
- Files = {
5
- 'linux' => File.join(Dir, 'linux', 'kinesis_producer'),
6
- 'osx' => File.join(Dir, 'osx', 'kinesis_producer'),
7
- 'windows' => File.join(Dir, 'windows', 'kinesis_producer.exe'),
8
- }
9
- end
10
- end
@@ -1,270 +0,0 @@
1
- #
2
- # Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- #
4
- # Licensed under the Amazon Software License (the "License").
5
- # You may not use this file except in compliance with the License.
6
- # A copy of the License is located at
7
- #
8
- # http://aws.amazon.com/asl/
9
- #
10
- # or in the "license" file accompanying this file. This file is distributed
11
- # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
- # express or implied. See the License for the specific language governing
13
- # permissions and limitations under the License.
14
-
15
- require 'tempfile'
16
- require 'concurrent'
17
-
18
- module KinesisProducer
19
- class Daemon
20
- FixnumMax = (2 ** (64 - 2)) - 1
21
-
22
- def initialize(binary, handler, options)
23
- @binary = binary
24
- @handler = handler
25
-
26
- @configuration = options[:configuration] || {}
27
- @credentials = options[:credentials]
28
- @metrics_credentials = options[:metrics_credentials]
29
- @credentials_refresh_delay = options[:credentials_refresh_delay] || 5000
30
- @logger = options[:logger]
31
- @debug = options[:debug]
32
- @enable_kpl_logging = options[:enable_kpl_logging]
33
-
34
- @executor = Concurrent::CachedThreadPool.new
35
- @shutdown = Concurrent::AtomicBoolean.new(false)
36
- @outgoing_messages = Queue.new
37
- @incoming_messages = Queue.new
38
-
39
- if debug?
40
- @meters = {
41
- add_message: Meter.new,
42
- send_message: Meter.new,
43
- receive_message: Meter.new,
44
- return_message: Meter.new,
45
- }
46
- end
47
- end
48
-
49
- def start
50
- @executor.post do
51
- create_pipes
52
- start_child
53
- end
54
- end
55
-
56
- def destroy
57
- @shutdown.make_true
58
- if @pid
59
- Process.kill("TERM", @pid)
60
- Process.waitpid(@pid)
61
- sleep 1 # TODO
62
- end
63
- delete_pipes
64
- end
65
-
66
- def add(message)
67
- @outgoing_messages.push(message)
68
- @meters[:add_message].mark if debug?
69
- end
70
-
71
- private
72
-
73
- def create_pipes
74
- @in_pipe = temp_pathname('amz-aws-kpl-in-pipe-')
75
- @out_pipe = temp_pathname('amz-aws-kpl-out-pipe-')
76
- system("mkfifo", @in_pipe.to_path, @out_pipe.to_path)
77
- sleep 1 # TODO
78
- end
79
-
80
- def delete_pipes
81
- @in_channel.close unless @in_channel.nil?
82
- @out_channel.close unless @out_channel.nil?
83
- @in_pipe.unlink
84
- @out_pipe.unlink
85
- rescue Errno::ENOENT
86
- end
87
-
88
- def temp_pathname(basename)
89
- tempfile = Tempfile.new(basename)
90
- ObjectSpace.undefine_finalizer(tempfile)
91
- file = tempfile.path
92
- File.delete(file)
93
- Pathname.new(file)
94
- end
95
-
96
- def start_child
97
- start_child_daemon
98
- connect_to_child
99
- start_loops
100
- end
101
-
102
- def start_child_daemon
103
- @child_stdout, stdout = IO.pipe
104
- @child_stderr, stderr = IO.pipe
105
- @pid = Process.fork do
106
- Process.setsid
107
- STDOUT.sync = true
108
- $stdout.reopen stdout
109
- $stderr.reopen stderr
110
- @child_stdout.close
111
- @child_stderr.close
112
- configuration = make_configuration_message
113
- credentials = make_set_credentials_message
114
- command = [@binary, @out_pipe.to_path, @in_pipe.to_path, to_hex(configuration), to_hex(credentials)]
115
- if @metrics_credentials
116
- metrics_credentials = make_set_metrics_credentials_message
117
- command.push(to_hex(metrics_credentials))
118
- end
119
- exec(*command)
120
- end
121
- stdout.close
122
- stderr.close
123
- sleep 1 # TODO
124
- end
125
-
126
- def connect_to_child
127
- @in_channel = @in_pipe.open('r')
128
- @out_channel = @out_pipe.open('w')
129
- end
130
-
131
- def enable_kpl_logging?
132
- @enable_kpl_logging
133
- end
134
-
135
- def start_loops
136
- start_loop_for(:log_stdout) if enable_kpl_logging?
137
- start_loop_for(:log_stderr) if enable_kpl_logging?
138
- start_loop_for(:send_message)
139
- start_loop_for(:receive_message)
140
- start_loop_for(:return_message)
141
- start_loop_for(:update_credentials)
142
- start_loop_for(:tick) if debug?
143
- end
144
-
145
- def start_loop_for(method)
146
- @executor.post do
147
- while @shutdown.false?
148
- send(method)
149
- @meters[method].mark if debug? and @meters.include?(method)
150
- end
151
- end
152
- end
153
-
154
- def log_stdout
155
- line = @child_stdout.readline.chomp
156
- @logger.info(line)
157
- end
158
-
159
- def log_stderr
160
- line = @child_stderr.readline.chomp
161
- if line.include? ' [info] '
162
- @logger.info(line)
163
- elsif line.include? ' [warn] '
164
- @logger.warn(line)
165
- else
166
- @logger.error(line)
167
- end
168
- end
169
-
170
- def send_message
171
- message = @outgoing_messages.pop
172
- size = [message.size].pack('N*')
173
- @out_channel.write(size)
174
- @out_channel.write(message)
175
- @out_channel.flush
176
- end
177
-
178
- def receive_message
179
- size = @in_channel.read(4)
180
- data = @in_channel.read(size.unpack('N*').first)
181
- @incoming_messages.push(data)
182
- end
183
-
184
- def return_message
185
- data = @incoming_messages.pop
186
- message = KinesisProducer::Protobuf::Message.decode(data)
187
- @handler.on_message(message)
188
- end
189
-
190
- def update_credentials
191
- add(make_set_credentials_message)
192
- add(make_set_metrics_credentials_message) if @metrics_credentials
193
- sleep(@credentials_refresh_delay.to_f/1000)
194
- end
195
-
196
- def make_configuration_message
197
- configuration = @configuration
198
- KinesisProducer::ConfigurationFields.each do |field|
199
- if configuration[field.name].nil?
200
- configuration[field.name] = field.default_value
201
- end
202
- end
203
- config = KinesisProducer::Protobuf::Configuration.new(configuration)
204
- make_message(0, :configuration, config)
205
- end
206
-
207
- def make_set_credentials_message
208
- make_set_credential_message(@credentials)
209
- end
210
-
211
- def make_set_metrics_credentials_message
212
- make_set_credential_message(@metrics_credentials, true)
213
- end
214
-
215
- def make_set_credential_message(credentials, for_metrics = false)
216
- return nil if credentials.nil?
217
- cred = KinesisProducer::Protobuf::Credentials.new(
218
- akid: credentials.credentials.access_key_id,
219
- secret_key: credentials.credentials.secret_access_key,
220
- token: credentials.credentials.session_token
221
- )
222
- set_credentials = KinesisProducer::Protobuf::SetCredentials.new(credentials: cred, for_metrics: for_metrics)
223
- make_message(FixnumMax, :set_credentials, set_credentials)
224
- end
225
-
226
- def make_message(id, target, value)
227
- KinesisProducer::Protobuf::Message.new(id: id, target => value).encode
228
- end
229
-
230
- def to_hex(message)
231
- message.unpack('H*').first
232
- end
233
-
234
- def tick
235
- out = @meters.each_value.map do |meter|
236
- sprintf("%5d", meter.tick)
237
- end
238
- @logger.debug("[#{Thread.current.object_id}] "+out.join(" ")) if debug?
239
- sleep 1
240
- end
241
-
242
- def debug?
243
- @debug
244
- end
245
-
246
- class Meter
247
- def initialize
248
- @count = Concurrent::AtomicFixnum.new(0)
249
- @previous_tick_time = Time.now.to_f
250
- @current_rate = 0.0
251
- tick
252
- end
253
-
254
- def mark(count = 1)
255
- @count.increment(count)
256
- end
257
-
258
- def tick
259
- @current_rate = @count.value.to_f / (Time.now.to_f - @previous_tick_time)
260
- @count.value = 0
261
- @previous_tick_time = Time.now.to_f
262
- current_rate
263
- end
264
-
265
- def current_rate
266
- @current_rate
267
- end
268
- end
269
- end
270
- end
@@ -1,122 +0,0 @@
1
- #
2
- # Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- #
4
- # Licensed under the Amazon Software License (the "License").
5
- # You may not use this file except in compliance with the License.
6
- # A copy of the License is located at
7
- #
8
- # http://aws.amazon.com/asl/
9
- #
10
- # or in the "license" file accompanying this file. This file is distributed
11
- # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
- # express or implied. See the License for the specific language governing
13
- # permissions and limitations under the License.
14
-
15
- require 'concurrent'
16
- require 'os'
17
-
18
- module KinesisProducer
19
- class Library
20
- class Handler
21
- def initialize(futures)
22
- @futures = futures
23
- end
24
-
25
- def on_message(message)
26
- if !message.put_record_result.nil?
27
- on_put_record_result(message)
28
- elsif !message.metrics_response.nil?
29
- on_metrics_response(message)
30
- end
31
- end
32
-
33
- def on_put_record_result(message)
34
- source_id = message.source_id
35
- result = message.put_record_result
36
- f = @futures.fetch(source_id)
37
- @futures.delete(source_id)
38
- if result.success
39
- f.set(result)
40
- else
41
- f.fail(StandardError.new(result.to_hash))
42
- end
43
- end
44
-
45
- def on_metrics_response(message)
46
- source_id = message.source_id
47
- response = message.metrics_response
48
- f = @futures.fetch(source_id)
49
- @futures.delete(source_id)
50
- f.set(response.metrics)
51
- end
52
- end
53
-
54
- class << self
55
- def binary
56
- case
57
- when OS.linux?; Binary::Files['linux']
58
- when OS.osx?; Binary::Files['osx']
59
- when OS.windows?; Binary::Files['windows']
60
- else; raise
61
- end
62
- end
63
-
64
- def default_binary_path
65
- root_dir = File.expand_path('../../..', __FILE__)
66
- File.join(root_dir, binary)
67
- end
68
- end
69
-
70
- def initialize(options)
71
- @binary_path = options.delete(:binary_path) || self.class.default_binary_path
72
- @message_id = Concurrent::AtomicFixnum.new(1)
73
- @futures = Concurrent::Map.new
74
- @child = Daemon.new(@binary_path, Handler.new(@futures), options)
75
- @child.start
76
- end
77
-
78
- def destroy
79
- flush_sync
80
- @child.destroy
81
- end
82
-
83
- def put_record(options)
84
- f = Concurrent::IVar.new
85
- id = add_message(:put_record, KinesisProducer::Protobuf::PutRecord.new(options))
86
- @futures[id] = f
87
- f
88
- end
89
-
90
- def get_metrics(options = {})
91
- f = Concurrent::IVar.new
92
- id = add_message(:metrics_request, KinesisProducer::Protobuf::MetricsRequest.new(options))
93
- @futures[id] = f
94
- f.wait
95
- f.value
96
- end
97
-
98
- def flush(options = {})
99
- add_message(:flush, KinesisProducer::Protobuf::Flush.new(options))
100
- end
101
-
102
- def flush_sync
103
- while @futures.size > 0
104
- flush()
105
- sleep 0.5
106
- end
107
- end
108
-
109
- private
110
-
111
- def add_message(target, value)
112
- id = get_and_inc_message_id
113
- message = KinesisProducer::Protobuf::Message.new(id: id, target => value)
114
- @child.add(message.encode)
115
- id
116
- end
117
-
118
- def get_and_inc_message_id
119
- @message_id.increment
120
- end
121
- end
122
- end
@@ -1,66 +0,0 @@
1
- #
2
- # Copyright 2014-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- #
4
- # Licensed under the Amazon Software License (the "License").
5
- # You may not use this file except in compliance with the License.
6
- # A copy of the License is located at
7
- #
8
- # http://aws.amazon.com/asl/
9
- #
10
- # or in the "license" file accompanying this file. This file is distributed
11
- # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
- # express or implied. See the License for the specific language governing
13
- # permissions and limitations under the License.
14
-
15
- ##
16
- # This file is auto-generated. DO NOT EDIT!
17
- #
18
- require 'protobuf/message'
19
-
20
- module KinesisProducer
21
- module Protobuf
22
- ##
23
- # Message Classes
24
- #
25
- class AdditionalDimension < ::Protobuf::Message; end
26
- class Configuration < ::Protobuf::Message; end
27
-
28
-
29
- ##
30
- # Message Fields
31
- #
32
- class AdditionalDimension
33
- required :string, :key, 1
34
- required :string, :value, 2
35
- required :string, :granularity, 3
36
- end
37
-
38
- class Configuration
39
- repeated ::KinesisProducer::Protobuf::AdditionalDimension, :additional_metric_dims, 128
40
- optional :bool, :aggregation_enabled, 1, :default => true
41
- optional :uint64, :aggregation_max_count, 2, :default => 4294967295
42
- optional :uint64, :aggregation_max_size, 3, :default => 51200
43
- optional :uint64, :collection_max_count, 4, :default => 500
44
- optional :uint64, :collection_max_size, 5, :default => 5242880
45
- optional :uint64, :connect_timeout, 6, :default => 6000
46
- optional :string, :custom_endpoint, 7
47
- optional :bool, :fail_if_throttled, 8, :default => false
48
- optional :string, :log_level, 9, :default => "info"
49
- optional :uint64, :max_connections, 10, :default => 24
50
- optional :string, :metrics_granularity, 11, :default => "shard"
51
- optional :string, :metrics_level, 12, :default => "detailed"
52
- optional :string, :metrics_namespace, 13, :default => "KinesisProducerLibrary"
53
- optional :uint64, :metrics_upload_delay, 14, :default => 60000
54
- optional :uint64, :min_connections, 15, :default => 1
55
- optional :uint64, :port, 16, :default => 443
56
- optional :uint64, :rate_limit, 17, :default => 150
57
- optional :uint64, :record_max_buffered_time, 18, :default => 100
58
- optional :uint64, :record_ttl, 19, :default => 30000
59
- optional :string, :region, 20
60
- optional :uint64, :request_timeout, 21, :default => 6000
61
- optional :bool, :verify_certificate, 22, :default => true
62
- end
63
-
64
- end
65
- end
66
-