fluent-plugin-kinesis 0.4.1 → 1.0.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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +13 -18
  3. data/.travis.yml +9 -9
  4. data/CHANGELOG.md +9 -0
  5. data/CONTRIBUTORS.txt +1 -1
  6. data/Gemfile +12 -9
  7. data/LICENSE.txt +39 -201
  8. data/Makefile +40 -0
  9. data/NOTICE.txt +1 -1
  10. data/README-v0.4.md +348 -0
  11. data/README.md +398 -183
  12. data/Rakefile +20 -14
  13. data/benchmark/dummer.conf +13 -0
  14. data/benchmark/firehose.conf +24 -0
  15. data/benchmark/producer.conf +28 -0
  16. data/benchmark/streams.conf +24 -0
  17. data/fluent-plugin-kinesis.gemspec +34 -23
  18. data/gemfiles/Gemfile.fluentd-0.10.58 +20 -0
  19. data/lib/fluent/plugin/kinesis_helper.rb +30 -0
  20. data/lib/fluent/plugin/kinesis_helper/api.rb +164 -0
  21. data/lib/fluent/plugin/kinesis_helper/class_methods.rb +120 -0
  22. data/lib/fluent/plugin/kinesis_helper/client.rb +36 -0
  23. data/lib/fluent/plugin/kinesis_helper/credentials.rb +51 -0
  24. data/lib/fluent/plugin/kinesis_helper/error.rb +38 -0
  25. data/lib/fluent/plugin/kinesis_helper/format.rb +85 -0
  26. data/lib/fluent/plugin/kinesis_helper/initialize.rb +58 -0
  27. data/lib/fluent/plugin/kinesis_helper/kpl.rb +81 -0
  28. data/lib/fluent/plugin/out_kinesis.rb +13 -11
  29. data/lib/fluent/plugin/out_kinesis_firehose.rb +44 -0
  30. data/lib/fluent/plugin/out_kinesis_producer.rb +38 -0
  31. data/lib/fluent/plugin/out_kinesis_streams.rb +47 -0
  32. data/lib/fluent/plugin/patched_detach_process_impl.rb +103 -0
  33. data/lib/fluent_plugin_kinesis/version.rb +17 -0
  34. data/lib/kinesis_producer.rb +24 -0
  35. data/lib/kinesis_producer/binary.rb +10 -0
  36. data/lib/kinesis_producer/daemon.rb +238 -0
  37. data/lib/kinesis_producer/library.rb +122 -0
  38. data/lib/kinesis_producer/protobuf/config.pb.rb +66 -0
  39. data/lib/kinesis_producer/protobuf/messages.pb.rb +151 -0
  40. data/lib/kinesis_producer/tasks/binary.rake +73 -0
  41. metadata +196 -36
  42. data/lib/fluent/plugin/version.rb +0 -16
  43. data/test/helper.rb +0 -32
  44. data/test/plugin/test_out_kinesis.rb +0 -641
@@ -0,0 +1,36 @@
1
+ #
2
+ # Copyright 2014-2016 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
+ module Fluent
16
+ module KinesisHelper
17
+ module Client
18
+ def client
19
+ @client ||= client_class.new(client_options)
20
+ end
21
+
22
+ private
23
+
24
+ def client_class
25
+ case request_type
26
+ when :streams
27
+ Aws::Kinesis::Client
28
+ when :firehose
29
+ Aws::Firehose::Client
30
+ when :producer
31
+ KinesisProducer::Library
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Copyright 2014-2016 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
+ module Fluent
16
+ module KinesisHelper
17
+ module Credentials
18
+ def credentials
19
+ case
20
+ when @assume_role_credentials
21
+ Aws::AssumeRoleCredentials.new(
22
+ client: Aws::STS::Client.new(region: @region),
23
+ role_arn: @assume_role_credentials.role_arn,
24
+ external_id: @assume_role_credentials.external_id,
25
+ role_session_name: 'aws-fluent-plugin-kinesis',
26
+ duration_seconds: 60 * 60,
27
+ )
28
+ when @shared_credentials
29
+ Aws::SharedCredentials.new(
30
+ profile_name: @shared_credentials.profile_name,
31
+ path: @shared_credentials.path,
32
+ )
33
+ else
34
+ default_credentials_provider
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def default_credentials_provider
41
+ config_class = Struct.new(:access_key_id, :secret_access_key, :session_token, :profile)
42
+ config = config_class.new(@aws_key_id, @aws_sec_key)
43
+ provider = Aws::CredentialProviderChain.new(config).resolve
44
+ if provider.nil?
45
+ raise Fluent::ConfigError, "You must specify credentials on ~/.aws/credentials, environment variables or IAM role for default credentials"
46
+ end
47
+ provider.credentials
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Copyright 2014-2016 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
+ module Fluent
16
+ module KinesisHelper
17
+ class BaseError < ::StandardError; end
18
+ class SkipRecordError < BaseError; end
19
+
20
+ class KeyNotFoundError < SkipRecordError
21
+ def initialize(key, record)
22
+ super "Key '#{key}' doesn't exist on #{record}"
23
+ end
24
+ end
25
+
26
+ class ExceedMaxRecordSizeError < SkipRecordError
27
+ def initialize(record)
28
+ super "Record size limit exceeded for #{record}"
29
+ end
30
+ end
31
+
32
+ class InvalidRecordError < SkipRecordError
33
+ def initialize(record)
34
+ super "Invalid type of record: #{record}"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Copyright 2014-2016 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 'fluent/plugin/kinesis_helper/error'
16
+
17
+ module Fluent
18
+ module KinesisHelper
19
+ module Format
20
+ MaxRecordSize = 1024 * 1024 # 1 MB
21
+
22
+ def configure(conf)
23
+ super
24
+ @formatter = Fluent::Plugin.new_formatter(@formatter)
25
+ @formatter.configure(conf)
26
+ end
27
+
28
+ def format(tag, time, record)
29
+ [tag, time, record].to_msgpack
30
+ end
31
+
32
+ private
33
+
34
+ def data_format(tag, time, record)
35
+ if @data_key and record[@data_key].nil?
36
+ raise KeyNotFoundError.new(@data_key, record)
37
+ elsif @data_key
38
+ record[@data_key].to_s
39
+ else
40
+ @formatter.format(tag, time, record).chomp
41
+ end
42
+ end
43
+
44
+ def key(record)
45
+ if @partition_key.nil?
46
+ SecureRandom.hex(16)
47
+ elsif !record.key?(@partition_key)
48
+ raise KeyNotFoundError.new(@partition_key, record)
49
+ else
50
+ record[@partition_key]
51
+ end
52
+ end
53
+
54
+ def convert_to_records(chunk)
55
+ chunk.to_enum(:msgpack_each).map{|tag, time, record|
56
+ convert_record(tag, time, record)
57
+ }.compact
58
+ end
59
+
60
+ def convert_record(tag, time, record)
61
+ unless record.is_a? Hash
62
+ raise InvalidRecordError, record
63
+ end
64
+ converted = convert_format(tag, time, record)
65
+ converted[:data] += "\n" if @append_new_line
66
+ if converted[:data].size > MaxRecordSize
67
+ raise ExceedMaxRecordSizeError, converted[:data]
68
+ else
69
+ converted
70
+ end
71
+ rescue SkipRecordError => e
72
+ log.error(truncate e)
73
+ nil
74
+ end
75
+
76
+ def truncate(msg)
77
+ if @log_truncate_max_size == 0 or (msg.to_s.size <= @log_truncate_max_size)
78
+ msg.to_s
79
+ else
80
+ msg.to_s[0...@log_truncate_max_size]
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Copyright 2014-2016 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
+ module Fluent
16
+ module KinesisHelper
17
+ module Initialize
18
+ def initialize
19
+ super
20
+ class << self
21
+ define_method('log') { $log } unless method_defined?(:log)
22
+
23
+ require 'aws-sdk'
24
+ require 'fluent/plugin/kinesis_helper/format'
25
+ require 'fluent/plugin/kinesis_helper/client'
26
+ require 'fluent/plugin/kinesis_helper/credentials'
27
+ include Format, Client, Credentials
28
+
29
+ case
30
+ when api?
31
+ require 'fluent/plugin/kinesis_helper/api'
32
+ include API
33
+ when kpl?
34
+ require 'fluent/plugin/kinesis_helper/kpl'
35
+ if Gem::Version.new(Fluent::VERSION) < Gem::Version.new('0.12.20')
36
+ # Backport from https://github.com/fluent/fluentd/pull/757
37
+ require 'fluent/plugin/patched_detach_process_impl'
38
+ include PatchedDetachProcessImpl
39
+ end
40
+ include KPL
41
+ end
42
+
43
+ def request_type
44
+ self.class.request_type
45
+ end
46
+
47
+ def api?
48
+ self.class.api?
49
+ end
50
+
51
+ def kpl?
52
+ self.class.kpl?
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,81 @@
1
+ #
2
+ # Copyright 2014-2016 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
+ module Fluent
16
+ module KinesisHelper
17
+ module KPL
18
+ def configure(conf)
19
+ # To workaround when the kinesis_producer section is not specified
20
+ if conf.elements.none?{|e|e.name == "kinesis_producer"}
21
+ conf.add_element("kinesis_producer")
22
+ end
23
+ super(conf)
24
+ if @region.nil?
25
+ keys = %w(AWS_REGION AMAZON_REGION AWS_DEFAULT_REGION)
26
+ @region = ENV.values_at(*keys).compact.first
27
+ end
28
+ end
29
+
30
+ def start
31
+ detach_multi_process do
32
+ super
33
+ client
34
+ end
35
+ end
36
+
37
+ def shutdown
38
+ super
39
+ client.destroy
40
+ end
41
+
42
+ private
43
+
44
+ def client_options
45
+ {
46
+ credentials: credentials,
47
+ configuration: build_kpl_configuration,
48
+ credentials_refresh_delay: @kinesis_producer.credentials_refresh_delay,
49
+ debug: @debug,
50
+ logger: log,
51
+ }
52
+ end
53
+
54
+ def build_kpl_configuration
55
+ configuration = @kinesis_producer.to_h
56
+ configuration.update(region: @region) unless @region.nil?
57
+ end
58
+
59
+ def write_chunk_to_kpl(records)
60
+ records.map do |record|
61
+ client.put_record(record)
62
+ end
63
+ end
64
+
65
+ def wait_futures(futures)
66
+ futures.each do |f|
67
+ f.wait
68
+ result = f.value!
69
+ end
70
+ end
71
+
72
+ def on_detach_process(i)
73
+ Process.setsid
74
+ end
75
+
76
+ def on_exit_process(i)
77
+ shutdown
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,22 +1,23 @@
1
- # Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
1
  #
3
- # Licensed under the Apache License, Version 2.0 (the "License"). You
4
- # may not use this file except in compliance with the License. A copy of
5
- # the License is located at
2
+ # Copyright 2014-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
3
  #
7
- # http://www.apache.org/licenses/LICENSE-2.0
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
8
7
  #
9
- # or in the "license" file accompanying this file. This file is
10
- # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
- # ANY KIND, either express or implied. See the License for the specific
12
- # language governing permissions and limitations under the License.
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.
13
14
 
14
- require 'aws-sdk-core'
15
+ require 'aws-sdk'
15
16
  require 'yajl'
16
17
  require 'logger'
17
18
  require 'securerandom'
18
- require 'fluent/plugin/version'
19
19
  require 'zlib'
20
+ require 'fluent_plugin_kinesis/version'
20
21
 
21
22
  module FluentPluginKinesis
22
23
  class OutputFilter < Fluent::BufferedOutput
@@ -64,6 +65,7 @@ module FluentPluginKinesis
64
65
  config_param :http_proxy, :string, default: nil
65
66
 
66
67
  def configure(conf)
68
+ log.warn("Deprecated warning: out_kinesis is no longer supported after v1.0.0. Please check out_kinesis_streams out.")
67
69
  super
68
70
  validate_params
69
71
 
@@ -0,0 +1,44 @@
1
+ #
2
+ # Copyright 2014-2016 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 'fluent/plugin/kinesis_helper'
16
+
17
+ module Fluent
18
+ class KinesisFirehoseOutput < BufferedOutput
19
+ include KinesisHelper
20
+ Fluent::Plugin.register_output('kinesis_firehose', self)
21
+ config_param_for_firehose
22
+
23
+ def write(chunk)
24
+ records = convert_to_records(chunk)
25
+ split_to_batches(records).each do |batch|
26
+ batch_request_with_retry(batch)
27
+ end
28
+ log.debug("Written #{records.size} records")
29
+ end
30
+
31
+ private
32
+
33
+ def convert_format(tag, time, record)
34
+ { data: data_format(tag, time, record) }
35
+ end
36
+
37
+ def batch_request(batch)
38
+ client.put_record_batch(
39
+ delivery_stream_name: @delivery_stream_name,
40
+ records: batch
41
+ )
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Copyright 2014-2016 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 'fluent/plugin/kinesis_helper'
16
+
17
+ module Fluent
18
+ class KinesisProducerOutput < BufferedOutput
19
+ include KinesisHelper
20
+ Fluent::Plugin.register_output('kinesis_producer', self)
21
+ config_param_for_producer
22
+
23
+ def write(chunk)
24
+ records = convert_to_records(chunk)
25
+ wait_futures(write_chunk_to_kpl(records))
26
+ end
27
+
28
+ private
29
+
30
+ def convert_format(tag, time, record)
31
+ {
32
+ data: data_format(tag, time, record),
33
+ partition_key: key(record),
34
+ stream_name: @stream_name,
35
+ }
36
+ end
37
+ end
38
+ end