fluent-plugin-sqs 2.0.0 → 2.1.0

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: c7d738c77ff00141662a60dbe4db65109c7c873b
4
- data.tar.gz: f399c2e1ee216a6f84cc7c172e22950a4a3e8b0c
3
+ metadata.gz: ac806e59bc8e71ad1eecb7cc1f3a6fc0c7107d8c
4
+ data.tar.gz: 01ee1714e4709cadbe7965453abac2d74f664384
5
5
  SHA512:
6
- metadata.gz: 6d55dc8fe951b822e8b047fcf29f8dbf1ab07775292afa0b1d9dc621e82e2c8b489a8397488a894a22ef90c78210d1de9506483e9a92b2878616ac7da50a2717
7
- data.tar.gz: af34dacba968a84f73422c7fd0c94bf1eb924466cfdba99d1f3c06030cae047ce8739424c1470b94045f157d8053facc701ad3f17700163896ea5d4d4d1ac318
6
+ metadata.gz: 591e14bd3934e022a5eca41cbf9dd588de7d1976625c2d4eb9a8ae8d32da32eddfa52548a2968d63354473169989d7cc3eb9613713cd960db623e743ed7dd2a8
7
+ data.tar.gz: 82b30c47720e3daabe83efcba3dbb91ac24f53dc87439926b0afb36c93387d7646f94806267a2a84dfd86b57aab38119c77d9ac0adcdd76955388570dfc265df
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.1.0
@@ -1,11 +1,11 @@
1
- require 'fluent/input'
1
+ require 'fluent/plugin/input'
2
2
  require 'aws-sdk'
3
3
 
4
- module Fluent
4
+ module Fluent::Plugin
5
5
  class SQSInput < Input
6
- Plugin.register_input('sqs', self)
6
+ Fluent::Plugin.register_input('sqs', self)
7
7
 
8
- define_method('router') { Fluent::Engine } unless method_defined?(:router)
8
+ helpers :timer
9
9
 
10
10
  config_param :aws_key_id, :string, default: nil, secret: true
11
11
  config_param :aws_sec_key, :string, default: nil, secret: true
@@ -32,8 +32,7 @@ module Fluent
32
32
  def start
33
33
  super
34
34
 
35
- @finished = false
36
- @thread = Thread.new(&method(:run_periodic))
35
+ timer_execute(:in_sqs_run_periodic_timer, @receive_interval, &method(:run))
37
36
  end
38
37
 
39
38
  def client
@@ -46,16 +45,6 @@ module Fluent
46
45
 
47
46
  def shutdown
48
47
  super
49
-
50
- @finished = true
51
- @thread.join
52
- end
53
-
54
- def run_periodic
55
- until @finished
56
- sleep @receive_interval
57
- run
58
- end
59
48
  end
60
49
 
61
50
  def run
@@ -68,11 +57,11 @@ module Fluent
68
57
 
69
58
  message.delete if @delete_message
70
59
 
71
- router.emit(@tag, Time.now.to_i, record)
60
+ router.emit(@tag, Fluent::Engine.now, record)
72
61
  end
73
62
  rescue
74
- $log.error 'failed to emit or receive', error: $ERROR_INFO.to_s, error_class: $ERROR_INFO.class.to_s
75
- $log.warn_backtrace $ERROR_INFO.backtrace
63
+ log.error 'failed to emit or receive', error: $ERROR_INFO.to_s, error_class: $ERROR_INFO.class.to_s
64
+ log.warn_backtrace $ERROR_INFO.backtrace
76
65
  end
77
66
 
78
67
  private
@@ -1,17 +1,18 @@
1
- require 'fluent/output'
1
+ require 'fluent/plugin/output'
2
2
  require 'aws-sdk'
3
3
 
4
- module Fluent
4
+ module Fluent::Plugin
5
5
  SQS_BATCH_SEND_MAX_MSGS = 10
6
6
  SQS_BATCH_SEND_MAX_SIZE = 262_144
7
7
 
8
- class SQSOutput < BufferedOutput
8
+ class SQSOutput < Output
9
9
  Fluent::Plugin.register_output('sqs', self)
10
10
 
11
- include SetTagKeyMixin
12
- config_set_default :include_tag_key, false
11
+ helpers :compat_parameters, :inject
12
+
13
+ DEFAULT_BUFFER_TYPE = "memory"
13
14
 
14
- include SetTimeKeyMixin
15
+ config_set_default :include_tag_key, false
15
16
  config_set_default :include_time_key, true
16
17
 
17
18
  config_param :aws_key_id, :string, default: nil, secret: true
@@ -24,7 +25,12 @@ module Fluent
24
25
  config_param :include_tag, :bool, default: true
25
26
  config_param :tag_property_name, :string, default: '__tag'
26
27
 
28
+ config_section :buffer do
29
+ config_set_default :@type, DEFAULT_BUFFER_TYPE
30
+ end
31
+
27
32
  def configure(conf)
33
+ compat_parameters_convert(conf, :buffer, :inject)
28
34
  super
29
35
 
30
36
  Aws.config = {
@@ -58,12 +64,21 @@ module Fluent
58
64
  @queue
59
65
  end
60
66
 
61
- def format(tag, _time, record)
67
+ def format(tag, time, record)
62
68
  record[@tag_property_name] = tag if @include_tag
69
+ record = inject_values_to_record(tag, time, record)
63
70
 
64
71
  record.to_msgpack
65
72
  end
66
73
 
74
+ def formatted_to_msgpack_binary
75
+ true
76
+ end
77
+
78
+ def multi_workers_ready?
79
+ true
80
+ end
81
+
67
82
  def write(chunk)
68
83
  batch_records = []
69
84
  batch_size = 0
@@ -98,7 +113,8 @@ module Fluent
98
113
  end
99
114
 
100
115
  def generate_id
101
- @tag_property_name + Time.now.to_i.to_s
116
+ unique_val = ((('a'..'z').to_a + (0..9).to_a)*3).shuffle[0,(rand(10).to_i)].join
117
+ @tag_property_name + Time.now.to_i.to_s + unique_val
102
118
  end
103
119
  end
104
120
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
  require 'fluent/plugin/in_sqs'
3
3
 
4
- describe Fluent::SQSInput do
4
+ describe Fluent::Plugin::SQSInput do
5
5
  let(:driver) do
6
6
  Fluent::Test.setup
7
- Fluent::Test::InputTestDriver.new(Fluent::SQSInput).configure(config)
7
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::SQSInput).configure(config)
8
8
  end
9
9
  subject { driver.instance }
10
10
 
@@ -85,7 +85,7 @@ describe Fluent::SQSInput do
85
85
  .with(max_number_of_messages: 10, wait_time_seconds: 10, visibility_timeout: 1) { messages }
86
86
  expect(subject).to receive(:parse_message).with(message) { message_attributes }
87
87
  expect(message).not_to receive(:delete)
88
- expect(subject.router).to receive(:emit).with('TAG', kind_of(Integer), message_attributes)
88
+ expect(subject.router).to receive(:emit).with('TAG', kind_of(Fluent::EventTime), message_attributes)
89
89
 
90
90
  subject.run
91
91
  end
@@ -111,7 +111,7 @@ describe Fluent::SQSInput do
111
111
  .with(max_number_of_messages: 10, wait_time_seconds: 10, visibility_timeout: 1) { messages }
112
112
  expect(subject).to receive(:parse_message).with(message) { message_attributes }
113
113
  expect(message).to receive(:delete)
114
- expect(subject.router).to receive(:emit).with('TAG', kind_of(Integer), message_attributes)
114
+ expect(subject.router).to receive(:emit).with('TAG', kind_of(Fluent::EventTime), message_attributes)
115
115
 
116
116
  subject.run
117
117
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'fluent/plugin/out_sqs'
3
3
 
4
- describe Fluent::SQSOutput do
5
- let(:driver) { Fluent::Test::BufferedOutputTestDriver.new(Fluent::SQSOutput) }
4
+ describe Fluent::Plugin::SQSOutput do
5
+ let(:driver) { Fluent::Test::Driver::Output.new(Fluent::Plugin::SQSOutput) }
6
6
  subject { driver.instance }
7
7
 
8
8
  before do
@@ -121,9 +121,12 @@ describe Fluent::SQSOutput do
121
121
  it 'send_messages to queue' do
122
122
  allow(Yajl).to receive(:dump).with(record) { body }
123
123
 
124
+ expect(driver.instance).to receive(:queue).twice.and_return("QUEUE_NAME")
124
125
  expect(subject.queue).to receive(:send_messages).with(entries: [{ id: kind_of(String), message_body: body, delay_seconds: 0 }])
125
126
 
126
- driver.emit(record).run
127
+ driver.run(default_tag: "test") do
128
+ driver.feed(record)
129
+ end
127
130
  end
128
131
  end
129
132
  end
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,9 @@ RSpec.configure do |config|
16
16
 
17
17
  require 'fluent/load'
18
18
  require 'fluent/test'
19
+ require 'fluent/test/helpers'
20
+ require 'fluent/test/driver/output'
21
+ require 'fluent/test/driver/input'
19
22
 
20
23
  require 'ostruct'
21
24
  require 'pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-sqs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Odagiri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2017-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  version: '0'
193
193
  requirements: []
194
194
  rubyforge_project:
195
- rubygems_version: 2.4.1
195
+ rubygems_version: 2.5.2
196
196
  signing_key:
197
197
  specification_version: 3
198
198
  summary: Amazon SQS input/output plugin for Fluent event collector