fluent-plugin-dynamodb-drc 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 +7 -0
- data/AUTHORS +3 -0
- data/ChangeLog +20 -0
- data/Gemfile +3 -0
- data/README.md +6 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/fluent-plugin-dynamodb-drc.gemspec +22 -0
- data/lib/fluent/plugin/out_dynamodb.rb +129 -0
- data/test/out_dynamodb.rb +59 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 569ec51668adffaf4ba084880612169126332238
|
4
|
+
data.tar.gz: 57d212b6852bb4761304745b274a9d8dd74878a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 814a7c301ef4da1deeb0de0fcc57dba047a40b7f2d85ed7397e4d75fddc0b1752de606d3d64d192798879423febf040a21a11231bfef5099eccf125e3781510e
|
7
|
+
data.tar.gz: b936f092a2b12191e391ca5d81fb44b8a94c605063e3ece357f48a807995e324a7c5c770ee1fdad9bbadd676c1bac937cdba40550c5164716f707ee2944f9784
|
data/AUTHORS
ADDED
data/ChangeLog
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Release 0.1.8 - 2012/07/10
|
2
|
+
|
3
|
+
* Fix gem.homepage url
|
4
|
+
|
5
|
+
Release 0.1.7 - 2012/06/17
|
6
|
+
|
7
|
+
* Inherits DetachMultiProcessMixin
|
8
|
+
|
9
|
+
Release 0.1.6 - 2012/06/12
|
10
|
+
|
11
|
+
* Optimized write(chunk) method not to collect all records in memory
|
12
|
+
|
13
|
+
Release 0.1.5 - 2012/06/10
|
14
|
+
|
15
|
+
* First release
|
16
|
+
|
17
|
+
Release 0.1.0 - 2012/06/09
|
18
|
+
|
19
|
+
* First commit
|
20
|
+
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.test_files = FileList['test/*.rb']
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:build]
|
14
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-dynamodb-drc"
|
6
|
+
gem.description = "Amazon DynamoDB output plugin for Fluent event collector"
|
7
|
+
gem.homepage = "https://github.com/kumapon/fluent-plugin-dynamodb-drc"
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = File.read("VERSION").strip
|
10
|
+
gem.authors = ["Takashi Matsuno", "Sadayuki Furuhashi", "CaDs"]
|
11
|
+
gem.has_rdoc = false
|
12
|
+
#gem.platform = Gem::Platform::RUBY
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_dependency "fluentd", "~> 0.10.0"
|
19
|
+
gem.add_dependency "aws-sdk", ">= 1.5.2"
|
20
|
+
gem.add_dependency "uuidtools", "~> 2.1.0"
|
21
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
22
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Fluent
|
3
|
+
|
4
|
+
|
5
|
+
class DynamoDBOutput < Fluent::BufferedOutput
|
6
|
+
Fluent::Plugin.register_output('dynamodb_drc', self)
|
7
|
+
|
8
|
+
include DetachMultiProcessMixin
|
9
|
+
|
10
|
+
BATCHWRITE_ITEM_LIMIT = 25
|
11
|
+
BATCHWRITE_CONTENT_SIZE_LIMIT = 1024*1024
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
require 'aws-sdk'
|
16
|
+
require 'msgpack'
|
17
|
+
require 'time'
|
18
|
+
require 'uuidtools'
|
19
|
+
end
|
20
|
+
|
21
|
+
config_param :aws_key_id, :string, :default => nil
|
22
|
+
config_param :aws_sec_key, :string, :default => nil
|
23
|
+
config_param :proxy_uri, :string, :default => nil
|
24
|
+
config_param :dynamo_db_table, :string
|
25
|
+
config_param :dynamo_db_endpoint, :string, :default => nil
|
26
|
+
config_param :time_format, :string, :default => nil
|
27
|
+
config_param :detach_process, :integer, :default => 2
|
28
|
+
|
29
|
+
def configure(conf)
|
30
|
+
super
|
31
|
+
|
32
|
+
@timef = TimeFormatter.new(@time_format, @localtime)
|
33
|
+
end
|
34
|
+
|
35
|
+
def start
|
36
|
+
options = {}
|
37
|
+
if @aws_key_id && @aws_sec_key
|
38
|
+
options[:access_key_id] = @aws_key_id
|
39
|
+
options[:secret_access_key] = @aws_sec_key
|
40
|
+
end
|
41
|
+
options[:dynamo_db_endpoint] = @dynamo_db_endpoint
|
42
|
+
options[:proxy_uri] = @proxy_uri if @proxy_uri
|
43
|
+
|
44
|
+
detach_multi_process do
|
45
|
+
super
|
46
|
+
|
47
|
+
begin
|
48
|
+
restart_session(options)
|
49
|
+
valid_table(@dynamo_db_table)
|
50
|
+
rescue ConfigError => e
|
51
|
+
$log.fatal "ConfigError: Please check your configuration, then restart fluentd. '#{e}'"
|
52
|
+
exit!
|
53
|
+
rescue Exception => e
|
54
|
+
$log.fatal "UnknownError: '#{e}'"
|
55
|
+
exit!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def restart_session(options)
|
61
|
+
config = AWS.config(options)
|
62
|
+
@batch = AWS::DynamoDB::BatchWrite.new(config)
|
63
|
+
@dynamo_db = AWS::DynamoDB.new(options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def valid_table(table_name)
|
67
|
+
table = @dynamo_db.tables[table_name]
|
68
|
+
table.load_schema
|
69
|
+
@hash_key = table.hash_key
|
70
|
+
@range_key = table.range_key unless table.simple_key?
|
71
|
+
end
|
72
|
+
|
73
|
+
def match_type!(key, record)
|
74
|
+
if key.type == :number
|
75
|
+
potential_value = record[key.name].to_i
|
76
|
+
if potential_value == 0
|
77
|
+
$log.fatal "Failed attempt to cast hash_key to Integer."
|
78
|
+
end
|
79
|
+
record[key.name] = potential_value
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def format(tag, time, record)
|
84
|
+
if !record.key?(@hash_key.name)
|
85
|
+
record[@hash_key.name] = UUIDTools::UUID.timestamp_create.to_s
|
86
|
+
end
|
87
|
+
match_type!(@hash_key, record)
|
88
|
+
|
89
|
+
formatted_time = @timef.format(time)
|
90
|
+
if @range_key
|
91
|
+
if !record.key?(@range_key.name)
|
92
|
+
record[@range_key.name] = formatted_time
|
93
|
+
end
|
94
|
+
match_type!(@range_key, record)
|
95
|
+
end
|
96
|
+
record['time'] = formatted_time
|
97
|
+
|
98
|
+
record.to_msgpack
|
99
|
+
end
|
100
|
+
|
101
|
+
def write(chunk)
|
102
|
+
batch_size = 0
|
103
|
+
batch_records = []
|
104
|
+
chunk.msgpack_each {|record|
|
105
|
+
fixed_timestamp = "#{Time.zone.parse(record["time"]).to_i}#{rand(1000000000..9999999999)}"
|
106
|
+
record["timestamp"] = fixed_timestamp
|
107
|
+
batch_records << record
|
108
|
+
batch_size += record.to_json.length # FIXME: heuristic
|
109
|
+
if batch_records.size >= BATCHWRITE_ITEM_LIMIT || batch_size >= BATCHWRITE_CONTENT_SIZE_LIMIT
|
110
|
+
batch_put_records(batch_records)
|
111
|
+
batch_records.clear
|
112
|
+
batch_size = 0
|
113
|
+
end
|
114
|
+
}
|
115
|
+
unless batch_records.empty?
|
116
|
+
batch_put_records(batch_records)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def batch_put_records(records)
|
121
|
+
@batch.put(@dynamo_db_table, records)
|
122
|
+
@batch.process!
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
end
|
129
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
require 'fluent/plugin/out_dynamodb'
|
3
|
+
|
4
|
+
class DynamoDBOutputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG = %[
|
10
|
+
aws_key_id test_key_id
|
11
|
+
aws_sec_key test_sec_key
|
12
|
+
dynamo_db_table test_table
|
13
|
+
dynamo_db_endpoint test.endpoint
|
14
|
+
utc
|
15
|
+
buffer_type memory
|
16
|
+
]
|
17
|
+
|
18
|
+
def create_driver(conf = CONFIG)
|
19
|
+
Fluent::Test::BufferedOutputTestDriver.new(Fluent::DynamoDBOutput) do
|
20
|
+
def write(chunk)
|
21
|
+
chunk.read
|
22
|
+
end
|
23
|
+
end.configure(conf)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_configure
|
27
|
+
d = create_driver
|
28
|
+
assert_equal 'test_key_id', d.instance.aws_key_id
|
29
|
+
assert_equal 'test_sec_key', d.instance.aws_sec_key
|
30
|
+
assert_equal 'test_table', d.instance.dynamo_db_table
|
31
|
+
assert_equal 'test.endpoint', d.instance.dynamo_db_endpoint
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_format
|
35
|
+
d = create_driver
|
36
|
+
|
37
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
38
|
+
d.emit({"a"=>1}, time)
|
39
|
+
d.emit({"a"=>2}, time)
|
40
|
+
|
41
|
+
d.expect_format([time, {'a' => 1}].to_msgpack)
|
42
|
+
d.expect_format([time, {'a' => 2}].to_msgpack)
|
43
|
+
|
44
|
+
d.run
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_write
|
48
|
+
d = create_driver
|
49
|
+
|
50
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
51
|
+
d.emit({"a"=>1}, time)
|
52
|
+
d.emit({"a"=>2}, time)
|
53
|
+
|
54
|
+
data = d.run
|
55
|
+
|
56
|
+
assert_equal [time, {'a' => 1}].to_msgpack + [time, {'a' => 2}].to_msgpack, data
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-dynamodb-drc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi Matsuno
|
8
|
+
- Sadayuki Furuhashi
|
9
|
+
- CaDs
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fluentd
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 0.10.0
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: aws-sdk
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.5.2
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.5.2
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: uuidtools
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 2.1.0
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.1.0
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rake
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.9.2
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.9.2
|
71
|
+
description: Amazon DynamoDB output plugin for Fluent event collector
|
72
|
+
email:
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- AUTHORS
|
78
|
+
- ChangeLog
|
79
|
+
- Gemfile
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- VERSION
|
83
|
+
- fluent-plugin-dynamodb-drc.gemspec
|
84
|
+
- lib/fluent/plugin/out_dynamodb.rb
|
85
|
+
- test/out_dynamodb.rb
|
86
|
+
homepage: https://github.com/kumapon/fluent-plugin-dynamodb-drc
|
87
|
+
licenses: []
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Amazon DynamoDB output plugin for Fluent event collector
|
109
|
+
test_files:
|
110
|
+
- test/out_dynamodb.rb
|