fluent-plugin-dynamodb-alt 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 313cdebb4acdd110160053ae3e62fae21df1f82e
4
- data.tar.gz: 42001e619859094c6e118e511310c71edb47b8ce
3
+ metadata.gz: def6475b444e76ca66d619f4fea1f814a4c64431
4
+ data.tar.gz: 3f83b0bd39fe53f813f2b8273b5e2e39392145da
5
5
  SHA512:
6
- metadata.gz: 9b5f25c37dd794f4f7500b55d4c6c3ad2b3f7e6712c90002129d84657381694924d7db4e8900aa9607fd0cf7a80ec2a0f21407cf893ed924a712b7702079e080
7
- data.tar.gz: 863bb9e03764a4cab2d66629881c701b10be1bd2a07a70e52e8a94af18a1a28fd4db4803a667dfb89856e5435cbb1fee1e48a98a67d36e406400d326caa5e795
6
+ metadata.gz: 552cd086584a6edcf30139cb6b6ea4b9081c2913592cd1381e3abe360a1f52958b4a0a4e2f62597d16ee4bc2a98c46536047a552403c792fbcf1f55e5fd04b07
7
+ data.tar.gz: 6eab1ab0f0540f685264fb2ec7190e2c177ebd7a41ea31dbb149b09aa63390fe17e3727fb2279dc00eb7310cebcb0da392b2c3796c3569407524fb47aa795cec
data/README.md CHANGED
@@ -29,6 +29,7 @@ bundle exec rake install
29
29
  region ap-northeast-1
30
30
  table_name my_table
31
31
  timestamp_key timestamp
32
+ #binary_keys data1,data2
32
33
  #endpoint http:://localhost:4567
33
34
  #concurrency 1
34
35
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'fluent-plugin-dynamodb-alt'
7
- spec.version = '0.1.1'
7
+ spec.version = '0.1.2'
8
8
  spec.authors = ['Genki Sugawara']
9
9
  spec.email = ['sgwr_dts@yahoo.co.jp']
10
10
  spec.summary = %q{Fluent plugin to output to DynamoDB.}
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rspec', '>= 3.0.0'
26
26
  spec.add_development_dependency 'hashie'
27
27
  spec.add_development_dependency 'ddbcli'
28
+ spec.add_development_dependency 'msgpack'
28
29
  end
@@ -16,6 +16,7 @@ class Fluent::DynamodbAltOutput < Fluent::BufferedOutput
16
16
  config_param :endpoint, :string, :default => nil
17
17
  config_param :table_name, :string
18
18
  config_param :timestamp_key, :string
19
+ config_param :binary_keys, :string, :default => nil
19
20
  config_param :concurrency, :integer, :default => 1
20
21
  config_param :expected, :string, :default => nil
21
22
  config_param :conditional_operator, :string, :default => 'AND'
@@ -27,6 +28,7 @@ class Fluent::DynamodbAltOutput < Fluent::BufferedOutput
27
28
  super
28
29
  require 'aws-sdk-core'
29
30
  require 'parallel'
31
+ require 'stringio'
30
32
  end
31
33
 
32
34
  def configure(conf)
@@ -66,6 +68,12 @@ class Fluent::DynamodbAltOutput < Fluent::BufferedOutput
66
68
  @expected = parse_expected(@expected)
67
69
  log.info("dynamodb_alt expected: #{@expected.inspect}")
68
70
  end
71
+
72
+ if @binary_keys
73
+ @binary_keys = @binary_keys.strip.split(/\s*,\s*/)
74
+ else
75
+ @binary_keys = []
76
+ end
69
77
  end
70
78
 
71
79
  def start
@@ -102,6 +110,8 @@ class Fluent::DynamodbAltOutput < Fluent::BufferedOutput
102
110
  end
103
111
 
104
112
  def put_record(record)
113
+ convert_binary!(record)
114
+
105
115
  item = {
106
116
  :table_name => @table_name,
107
117
  :item => record
@@ -201,4 +211,13 @@ class Fluent::DynamodbAltOutput < Fluent::BufferedOutput
201
211
  }.last
202
212
  }
203
213
  end
214
+
215
+ def convert_binary!(record)
216
+ @binary_keys.each do |key|
217
+ val = record[key]
218
+ record[key] = StringIO.new(val) if val
219
+ end
220
+
221
+ return record
222
+ end
204
223
  end
@@ -32,6 +32,7 @@ describe Fluent::DynamodbAltOutput do
32
32
  endpoint http:://localhost:4567
33
33
  table_name my_table
34
34
  timestamp_key timestamp
35
+ binary_keys aaa,bbb
35
36
  concurrency 2
36
37
  conditional_operator OR
37
38
  EOS
@@ -42,12 +43,37 @@ describe Fluent::DynamodbAltOutput do
42
43
  expect(driver.instance.endpoint ).to eq 'http:://localhost:4567'
43
44
  expect(driver.instance.table_name ).to eq 'my_table'
44
45
  expect(driver.instance.timestamp_key ).to eq 'timestamp'
46
+ expect(driver.instance.binary_keys ).to eq ['aaa', 'bbb']
45
47
  expect(driver.instance.concurrency ).to eq 2
46
48
  expect(driver.instance.conditional_operator).to eq 'OR'
47
49
  expect(driver.instance.instance_variable_get(:@hash_key) ).to eq 'hash_key'
48
50
  expect(driver.instance.instance_variable_get(:@range_key)).to eq 'range_key'
49
51
  end
50
52
 
53
+ it do
54
+ driver = create_driver
55
+ allow(driver.instance).to receive(:configure_aws)
56
+
57
+ allow(driver.instance).to receive(:create_client) {
58
+ client = double('client')
59
+ allow(client).to receive(:describe_table) {
60
+ Hashie::Mash.new(:table => {
61
+ :key_schema => [
62
+ {:key_type => 'HASH', :attribute_name => 'hash_key'},
63
+ ]})
64
+ }
65
+ client
66
+ }
67
+
68
+ driver.configure(<<-EOS)
69
+ type dynamodb_alt
70
+ table_name my_table
71
+ timestamp_key timestamp
72
+ EOS
73
+
74
+ expect(driver.instance.binary_keys).to eq []
75
+ end
76
+
51
77
  it do
52
78
  driver = create_driver
53
79
  allow(driver.instance).to receive(:configure_aws)
@@ -70,7 +96,7 @@ describe Fluent::DynamodbAltOutput do
70
96
  expected timestamp GE 0,key LT 100
71
97
  EOS
72
98
 
73
- expected = driver.instance.instance_variable_get(:@expected)
99
+ expected = driver.instance.expected
74
100
  expect(expected).to eq [["timestamp", "GE", 0],["key", "LT", 100]]
75
101
  end
76
102
 
@@ -96,7 +122,7 @@ describe Fluent::DynamodbAltOutput do
96
122
  expected id NULL,timestamp LT ${ts},key EQ ${k}
97
123
  EOS
98
124
 
99
- expected = driver.instance.instance_variable_get(:@expected)
125
+ expected = driver.instance.expected
100
126
 
101
127
  expect(expected[0]).to eq ["id", "NULL", nil]
102
128
 
@@ -158,7 +184,7 @@ describe Fluent::DynamodbAltOutput do
158
184
  expected key1 EQ "str",key2 EQ 1
159
185
  EOS
160
186
 
161
- expected = driver.instance.instance_variable_get(:@expected)
187
+ expected = driver.instance.expected
162
188
  expect(expected).to eq [["key1", "EQ", "str"], ["key2", "EQ", 1]]
163
189
  end
164
190
  }
@@ -430,5 +456,28 @@ describe Fluent::DynamodbAltOutput do
430
456
  end
431
457
  end
432
458
  }
459
+
460
+ context('binary') {
461
+ it do
462
+ run_driver(:binary_keys => 'data') do |d|
463
+ d.emit({'id' => '12345678-1234-1234-1234-123456789001', 'timestamp' => 1409534625001, 'data' => MessagePack.pack({'foo' => 100, 'bar' => 'Zzz...'})}, time)
464
+ d.emit({'id' => '12345678-1234-1234-1234-123456789002', 'timestamp' => 1409534625002, 'data' => MessagePack.pack({'foo' => 200, 'bar' => 'Zzz..'})}, time)
465
+ d.emit({'id' => '12345678-1234-1234-1234-123456789003', 'timestamp' => 1409534625003, 'data' => MessagePack.pack({'foo' => 300, 'bar' => 'Zzz.'})}, time)
466
+ end
467
+
468
+ rows = select_all.map do |row|
469
+ data = row['data']
470
+ data = Base64.strict_decode64(data)
471
+ row['data'] = MessagePack.unpack(data)
472
+ row
473
+ end
474
+
475
+ expect(rows).to match_array [
476
+ {"id"=>"12345678-1234-1234-1234-123456789001", "timestamp"=>1409534625001, "data" => {'foo' => 100, 'bar' => 'Zzz...'}},
477
+ {"id"=>"12345678-1234-1234-1234-123456789002", "timestamp"=>1409534625002, "data" => {'foo' => 200, 'bar' => 'Zzz..'}},
478
+ {"id"=>"12345678-1234-1234-1234-123456789003", "timestamp"=>1409534625003, "data" => {'foo' => 300, 'bar' => 'Zzz.'}},
479
+ ]
480
+ end
481
+ }
433
482
  }
434
483
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'fluent/test'
2
2
  require 'fluent/plugin/out_dynamodb_alt'
3
+ require 'base64'
3
4
  require 'hashie'
5
+ require 'msgpack'
4
6
  require 'securerandom'
7
+ require 'stringio'
5
8
 
6
9
  DRIVER_DEFAULT_TAG = 'test.default'
7
10
  TEST_TABLE_NAME = 'my_table-' + SecureRandom.uuid
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-dynamodb-alt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: msgpack
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Fluent plugin to output to DynamoDB.
126
140
  email:
127
141
  - sgwr_dts@yahoo.co.jp