Skip to content

Commit 39323cd

Browse files
committed
initial commit
0 parents  commit 39323cd

File tree

9 files changed

+176
-0
lines changed

9 files changed

+176
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/
10+
*.bundle
11+
*.so
12+
*.o
13+
*.a
14+
mkmf.log

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Release 0.1.0 - 2014/10/22
2+
3+
* First commit

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 Masayuki DOI
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Fluent::Plugin::Dynamodb::Add
2+
3+
TODO: Write a gem description
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'fluent-plugin-dynamodb-add'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle
16+
17+
Or install it yourself as:
18+
19+
$ gem install fluent-plugin-dynamodb-add
20+
21+
## Usage
22+
23+
TODO: Write usage instructions here
24+
25+
## Contributing
26+
27+
1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-dynamodb-add/fork )
28+
2. Create your feature branch (`git checkout -b my-new-feature`)
29+
3. Commit your changes (`git commit -am 'Add some feature'`)
30+
4. Push to the branch (`git push origin my-new-feature`)
31+
5. Create a new Pull Request

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "bundler/gem_tasks"
2+

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

fluent-plugin-dynamodb-add.gemspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
5+
Gem::Specification.new do |spec|
6+
spec.name = "fluent-plugin-dynamodb-add"
7+
spec.authors = ["Masayuki DOI"]
8+
spec.email = ["[email protected]"]
9+
spec.description = "Amazon DynamoDB atomic add plugin"
10+
spec.summary = spec.description
11+
spec.homepage = "https://github.com/mdoi/fluent-plugin-dynamodb-add"
12+
13+
spec.files = `git ls-files -z`.split("\x0")
14+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16+
spec.require_paths = ["lib"]
17+
18+
spec.add_development_dependency "bundler", "~> 1.7"
19+
spec.add_development_dependency "rake", "~> 10.0"
20+
spec.add_dependency "fluentd", "~> 0.10.0"
21+
spec.add_dependency "aws-sdk", ">= 1.56.0"
22+
end

lib/fluent/plugin/out_dynamodb_add.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
module Fluent
2+
class DynamodbAdd < Fluent::Output
3+
Fluent::Plugin.register_output('dynamodb_add', self)
4+
5+
unless method_defined?(:log)
6+
define_method(:log) { $log }
7+
end
8+
9+
config_param :count_key, :string
10+
config_param :dynamo_count_key, :string
11+
config_param :table_name, :string
12+
config_param :use_iam_role, :bool, :default => false
13+
config_param :aws_key_id, :string, :default => nil
14+
config_param :aws_sec_key, :string, :default => nil
15+
config_param :endpoint, :string, :default => nil
16+
config_param :hash_key, :string, :default => nil
17+
config_param :hash_key_delimiter, :string, :default => ":"
18+
config_param :range_key, :string, :default => nil
19+
20+
def initialize
21+
super
22+
require 'aws-sdk'
23+
end
24+
25+
def configure(conf)
26+
super
27+
28+
unless use_iam_role
29+
[:aws_key_id, :aws_sec_key].each do |name|
30+
unless self.instance_variable_get("@#{name}")
31+
raise ConfigError, "'#{name}' is required"
32+
end
33+
end
34+
end
35+
@hash_key = hash_key.split(/\s*,\s*/)
36+
end
37+
38+
def start
39+
super
40+
if use_iam_role
41+
AWS.config(:credential_provider => AWS::Core::CredentialProviders::EC2Provider.new)
42+
else
43+
AWS.config(:access_key_id => @aws_key_id, :secret_access_key => @aws_sec_key)
44+
end
45+
46+
AWS.config(:dynamo_db_endpoint => @endpoint) if @endpoint
47+
48+
@dynamo_db = AWS::DynamoDB.new
49+
@table = @dynamo_db.tables[table_name]
50+
@table.load_schema
51+
end
52+
53+
def emit(tag, es, chain)
54+
es.each do |time, record|
55+
hash_key = create_key(record)
56+
next unless hash_key || record[@count_key]
57+
58+
if @range_key
59+
next unless record[@range_key]
60+
item = @table.items[hash_key, record[@range_key]]
61+
else
62+
item = @table.items[hash_key]
63+
end
64+
item.attributes.update {|u| u.add @dynamo_count_key => record[@count_key] }
65+
end
66+
end
67+
68+
private
69+
def create_key(record)
70+
key_array = []
71+
@hash_key.each do |h|
72+
return nil unless record[h]
73+
key_array << record[h]
74+
end
75+
key_array.join(@hash_key_delimiter)
76+
end
77+
end
78+
end

0 commit comments

Comments
 (0)