fluent-plugin-dd 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODQ1NTNjMTEyZjZhOTAyNTAzOGFlN2VlMDQ2MGFjMzYxZmM4ZmI5ZQ==
5
- data.tar.gz: !binary |-
6
- OWQxOTE3ZmQzM2Y2NmZkODZhYjlhNjkxMDhkNWJiN2ZjYTYxYTI2Nw==
2
+ SHA1:
3
+ metadata.gz: 8abcfb0fc04ae21036b74510e140eb471c583ec1
4
+ data.tar.gz: bb1cd7f2340cb5d14a5fcafed9ab58d13923afd0
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YTIyMmE0YmMwNWU4NDNlZGM0YTRlNjM1NWY4OGQ5YzZlMGI5MGExNjRjODdj
10
- M2Q2OWFmMGYwMGJhNjAxZTBlMDg2NzkwZmNiOTBjMzc1NWVmNTgyOWYyMThl
11
- YWQ2YjA1ODUwNDYxZDdlYTMyMWY0Y2I3ZTczYTljNDE1MDM2NDY=
12
- data.tar.gz: !binary |-
13
- ZmEzNjMwMTQ5NDFkODI3ZTM5ODgyMzNmZjI1M2Y5YTc2NTJkYmIwN2JlM2Ix
14
- M2I3NGU3ZGFiZWJlNmE2YjRhZDY0Y2Y2MjM0ZTA0NTgzNmEyYzc5YjY3ZjM0
15
- NzU5YzdkYTYwNDdkZGVmZWE3MGEwZTU0MjVjMzJlNjg5NTJlOGU=
6
+ metadata.gz: 0be3eeb5ba3ee78de16a52c597031d4ee943771bed50743f6ccf60a8058f1e0077a40742ea9efa09e4fd693326a71afbae55a7d250920eca807ada8fb6db49a3
7
+ data.tar.gz: 0235abf277ff35648cfdcbff3a05219a78cfa1c147a0bc1eb144c57aae27ad5a5938cd9711f7fbd9bd14599d9c8a5ecd205ea7e809ff07a8673ee985fd0944a1
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = 'fluent-plugin-dd'
4
- spec.version = '0.1.4'
4
+ spec.version = '0.1.5'
5
5
  spec.authors = ['Genki Sugawara']
6
6
  spec.email = ['sugawara@cookpad.com']
7
7
  spec.description = %q{Output plugin for Datadog}
@@ -9,6 +9,7 @@ class Fluent::DdOutput < Fluent::BufferedOutput
9
9
  config_param :host, :string, :default => nil
10
10
  config_param :use_fluentd_tag_for_datadog_tag, :bool, :default => false
11
11
  config_param :emit_in_background, :bool, :default => false
12
+ config_param :concurrency, :integer, :default => nil
12
13
 
13
14
  def initialize
14
15
  super
@@ -23,10 +24,12 @@ class Fluent::DdOutput < Fluent::BufferedOutput
23
24
  if @emit_in_background
24
25
  @queue = Queue.new
25
26
 
26
- @thread = Thread.start do
27
- while(chunk = @queue.pop)
28
- emit_points(chunk)
29
- Thread.pass
27
+ @threads = @concurrency.times.map do
28
+ Thread.start do
29
+ while (job = @queue.pop)
30
+ emit_points(*job)
31
+ Thread.pass
32
+ end
30
33
  end
31
34
  end
32
35
  end
@@ -36,8 +39,12 @@ class Fluent::DdOutput < Fluent::BufferedOutput
36
39
  super
37
40
 
38
41
  if @emit_in_background
39
- @queue.push(false)
40
- @thread.join
42
+ @threads.size.times do
43
+ @queue.push(false)
44
+ end
45
+ @threads.each do |thread|
46
+ thread.join
47
+ end
41
48
  end
42
49
  end
43
50
 
@@ -48,6 +55,11 @@ class Fluent::DdOutput < Fluent::BufferedOutput
48
55
  raise Fluent::ConfigError, '`dd_api_key` is required'
49
56
  end
50
57
 
58
+ if !@emit_in_background && @concurrency
59
+ raise Fluent::ConfigError, '`concurrency` should be used with `emit_in_background`'
60
+ end
61
+ @concurrency ||= 1
62
+
51
63
  unless @host
52
64
  @host = %x[hostname -f 2> /dev/null].strip
53
65
  @host = Socket.gethostname if @host.empty?
@@ -61,16 +73,24 @@ class Fluent::DdOutput < Fluent::BufferedOutput
61
73
  end
62
74
 
63
75
  def write(chunk)
64
- if @emit_in_background
65
- @queue.push(chunk)
66
- else
67
- emit_points(chunk)
76
+ jobs = chunk_to_jobs(chunk)
77
+
78
+ jobs.each do |job|
79
+ if @emit_in_background
80
+ @queue.push(job)
81
+ else
82
+ emit_points(*job)
83
+ end
68
84
  end
69
85
  end
70
86
 
71
87
  private
72
88
 
73
- def emit_points(chunk)
89
+ def emit_points(metric, points, options)
90
+ @dog.emit_points(metric, points, options)
91
+ end
92
+
93
+ def chunk_to_jobs(chunk)
74
94
  enum = chunk.to_enum(:msgpack_each)
75
95
 
76
96
  enum.select {|tag, time, record|
@@ -87,7 +107,7 @@ class Fluent::DdOutput < Fluent::BufferedOutput
87
107
  end
88
108
 
89
109
  [dd_tag] + record.values_at('metric', 'host', 'type')
90
- }.each {|i, records|
110
+ }.map {|i, records|
91
111
  tag, metric, host, type = i
92
112
 
93
113
  points = records.map do |tag, time, record|
@@ -101,7 +121,7 @@ class Fluent::DdOutput < Fluent::BufferedOutput
101
121
  options[:host] = host if host
102
122
  options[:type] = type if type
103
123
 
104
- @dog.emit_points(metric, points, options)
124
+ [metric, points, options]
105
125
  }
106
126
  end
107
127
  end
@@ -22,17 +22,51 @@ describe Fluent::DdOutput do
22
22
  end
23
23
  end
24
24
 
25
- it 'should be called emit_points in the background' do
26
- run_driver(:emit_in_background => true) do |d, dog|
27
- dog.should_receive(:emit_points).with(
28
- "some.metric.name",
29
- [[Time.parse("2014-02-08 04:14:15 UTC"), 50.0],
30
- [Time.parse("2014-02-08 04:14:15 UTC"), 100.0]],
31
- {}
32
- )
25
+ context 'with emit_in_background' do
26
+ before do
27
+ $threads_array_for_test = []
28
+ end
33
29
 
34
- d.emit({"metric" => "some.metric.name", "value" => 50.0}, time)
35
- d.emit({"metric" => "some.metric.name", "value" => 100.0}, time)
30
+ after do
31
+ $threads_array_for_test = nil
32
+ end
33
+
34
+ it 'should be called emit_points in the background' do
35
+ run_driver(:emit_in_background => true) do |d, dog|
36
+ dog.should_receive(:emit_points).with(
37
+ "some.metric.name",
38
+ [[Time.parse("2014-02-08 04:14:15 UTC"), 50.0],
39
+ [Time.parse("2014-02-08 04:14:15 UTC"), 100.0]],
40
+ {}
41
+ )
42
+
43
+ d.emit({"metric" => "some.metric.name", "value" => 50.0}, time)
44
+ d.emit({"metric" => "some.metric.name", "value" => 100.0}, time)
45
+ end
46
+ end
47
+
48
+ it 'should be called emit_points in the background and in the different thread' do
49
+ run_driver(
50
+ :emit_in_background => true,
51
+ :concurrency => 2,
52
+ ) do |d, dog|
53
+ dog.should_receive(:emit_points).with(
54
+ "some.metric.name.1",
55
+ [[Time.parse("2014-02-08 04:14:15 UTC"), 50.0]],
56
+ {}
57
+ )
58
+ dog.should_receive(:emit_points).with(
59
+ "some.metric.name.2",
60
+ [[Time.parse("2014-02-08 04:14:15 UTC"), 100.0]],
61
+ {}
62
+ )
63
+
64
+ d.emit({"metric" => "some.metric.name.1", "value" => 50.0}, time)
65
+ d.emit({"metric" => "some.metric.name.2", "value" => 100.0}, time)
66
+ end
67
+
68
+ expect($threads_array_for_test.size).to eq(2)
69
+ expect($threads_array_for_test[0]).not_to eq($threads_array_for_test[1])
36
70
  end
37
71
  end
38
72
 
@@ -6,6 +6,18 @@ require 'time'
6
6
  # Disable Test::Unit
7
7
  module Test::Unit::RunCount; def run(*); end; end
8
8
 
9
+ class Fluent::DdOutput < Fluent::BufferedOutput
10
+ private
11
+ alias_method :orig_emit_points, :emit_points
12
+
13
+ def emit_points(*args)
14
+ if $threads_array_for_test
15
+ $threads_array_for_test << Thread.current
16
+ end
17
+ orig_emit_points(*args)
18
+ end
19
+ end
20
+
9
21
  RSpec.configure do |config|
10
22
  config.before(:all) do
11
23
  Fluent::Test.setup
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-dd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dogapi
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
@@ -56,28 +56,28 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.11.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.11.0
83
83
  description: Output plugin for Datadog
@@ -107,20 +107,21 @@ require_paths:
107
107
  - lib
108
108
  required_ruby_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ! '>='
110
+ - - '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.1.11
120
+ rubygems_version: 2.0.14
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Output plugin for Datadog
124
124
  test_files:
125
125
  - spec/out_dd_spec.rb
126
126
  - spec/spec_helper.rb
127
+ has_rdoc: