fluent-plugin-dogstatsd 0.0.1 → 0.0.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: 6ce5e12ea022b781f31f745f2a31ff3764860ab2
4
- data.tar.gz: 83e3d99b0b172ac3a4e678e88299b2aaeb31257c
3
+ metadata.gz: f188162ad60261d59a5dd838f6885ad22f793e57
4
+ data.tar.gz: 81fb1419996bf0ca51be6f212e69c752237b14b0
5
5
  SHA512:
6
- metadata.gz: 779b3b7fbc3b189d88478edd560ee7dd65c02c8e3d29c02597f68dd11f3cee1ccb0139cd60a4317b2751566f5e23eedfe5959bb3ddd780ae7de8430db3edaf0d
7
- data.tar.gz: 2f19c1bb877c1e22b581b39477221a4f0ff035e0b36fbccbd4cad556b6fb131053afd2177836e8358cbc464e84e6a8f3d3272fa3b4c4bf653cf5a0c1ae6bdc6b
6
+ metadata.gz: 748ec60e813ebff20e0c35dfc0d480806f0a8eec0ddc690073c13bece6c96d54a049164f080c625dbc06f823bb997996d011cc4ca499d3bf5d9d737d16352792
7
+ data.tar.gz: eb3d5f4ce5f50b456df495bce922e90169ceb6ce7d1913ec46288128f97b6b9471a3db2928ff9f9f216d8a489034cf40ca7a499f7e2c08646546ab692174ccbc
data/README.md CHANGED
@@ -30,6 +30,12 @@ Supported types are `increment`, `decrement`, `count`, `gauge`, `histogram`, `ti
30
30
 
31
31
  # Use tag of fluentd record as key sent to Dogstatsd
32
32
  use_tag_as_key false
33
+
34
+ # (Treat fields in a record as tags)
35
+ # flat_tag true
36
+
37
+ # (Metric type in Datadog.)
38
+ # metric_type increment
33
39
  </match>
34
40
  ```
35
41
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "fluentd"
21
- spec.add_dependency "dogstatsd-ruby"
21
+ spec.add_dependency "dogstatsd-ruby", "~> 1.4.1"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.6"
24
24
  spec.add_development_dependency "rake"
@@ -1,7 +1,7 @@
1
1
  module Fluent
2
2
  module Plugin
3
3
  module Dogstatsd
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -5,6 +5,8 @@ module Fluent
5
5
  config_param :host, :string, :default => nil
6
6
  config_param :port, :integer, :default => nil
7
7
  config_param :use_tag_as_key, :bool, :default => false
8
+ config_param :flat_tag, :bool, :default => false
9
+ config_param :metric_type, :string, :default => nil
8
10
 
9
11
  unless method_defined?(:log)
10
12
  define_method(:log) { $log }
@@ -16,7 +18,6 @@ module Fluent
16
18
  super
17
19
 
18
20
  require 'statsd' # dogstatsd-ruby
19
- require 'fluent/plugin/dogstatsd/statsd_patch'
20
21
  end
21
22
 
22
23
  def start
@@ -38,20 +39,35 @@ module Fluent
38
39
  key = if @use_tag_as_key
39
40
  tag
40
41
  else
41
- record['key']
42
+ record.delete('key')
42
43
  end
43
44
 
44
- value = record['value']
45
+ unless key
46
+ log.warn "'key' is not specified. skip this record:", tag: tag
47
+ next
48
+ end
49
+
50
+ value = record.delete('value')
45
51
 
46
52
  options = {}
47
53
 
48
- if record['tags']
49
- options[:tags] = record['tags'].map do |k, v|
54
+ tags = if @flat_tag
55
+ record
56
+ else
57
+ record['tags']
58
+ end
59
+
60
+ title = record.delete('title')
61
+ text = record.delete('text')
62
+ type = @metric_type || record.delete('type')
63
+
64
+ if tags
65
+ options[:tags] = tags.map do |k, v|
50
66
  "#{k}:#{v}"
51
67
  end
52
68
  end
53
69
 
54
- case record['type']
70
+ case type
55
71
  when 'increment'
56
72
  s.increment(key, options)
57
73
  when 'decrement'
@@ -67,7 +83,11 @@ module Fluent
67
83
  when 'set'
68
84
  s.set(key, value, options)
69
85
  when 'event'
70
- s.event(record['title'], record['text'], options)
86
+ s.event(title, text, options)
87
+ when nil
88
+ log.warn "type is not provided (You can provide type via `metric_type` in config or `type` field in a record."
89
+ else
90
+ log.warn "Type '#{type}' is unknown."
71
91
  end
72
92
  end
73
93
  end
@@ -41,8 +41,6 @@ class DogstatsdOutputTest < Test::Unit::TestCase
41
41
  def test_write
42
42
  d = create_driver
43
43
 
44
- d.instance.statsd = DummyStatsd.new
45
-
46
44
  d.emit({'type' => 'increment', 'key' => 'hello.world1'}, Time.now.to_i)
47
45
  d.emit({'type' => 'increment', 'key' => 'hello.world2'}, Time.now.to_i)
48
46
  d.emit({'type' => 'decrement', 'key' => 'hello.world'}, Time.now.to_i)
@@ -67,14 +65,40 @@ class DogstatsdOutputTest < Test::Unit::TestCase
67
65
  ])
68
66
  end
69
67
 
68
+ def test_flat_tag
69
+ d = create_driver(<<-EOC)
70
+ #{default_config}
71
+ flat_tag true
72
+ EOC
73
+
74
+ d.emit({'type' => 'increment', 'key' => 'hello.world', 'tagKey' => 'tagValue'}, Time.now.to_i)
75
+ d.run
76
+
77
+ assert_equal(d.instance.statsd.messages, [
78
+ [:increment, 'hello.world', {tags: ["tagKey:tagValue"]}],
79
+ ])
80
+ end
81
+
82
+ def test_metric_type
83
+ d = create_driver(<<-EOC)
84
+ #{default_config}
85
+ metric_type decrement
86
+ EOC
87
+
88
+ d.emit({'key' => 'hello.world', 'tags' => {'tagKey' => 'tagValue'}}, Time.now.to_i)
89
+ d.run
90
+
91
+ assert_equal(d.instance.statsd.messages, [
92
+ [:decrement, 'hello.world', {tags: ["tagKey:tagValue"]}],
93
+ ])
94
+ end
95
+
70
96
  def test_use_tag_as_key
71
97
  d = create_driver(<<-EOC)
72
98
  #{default_config}
73
99
  use_tag_as_key true
74
100
  EOC
75
101
 
76
- d.instance.statsd = DummyStatsd.new
77
-
78
102
  d.emit({'type' => 'increment'}, Time.now.to_i)
79
103
  d.run
80
104
 
@@ -85,7 +109,6 @@ use_tag_as_key true
85
109
 
86
110
  def test_tags
87
111
  d = create_driver
88
- d.instance.statsd = DummyStatsd.new
89
112
  d.emit({'type' => 'increment', 'key' => 'hello.world', 'tags' => {'key' => 'value'}}, Time.now.to_i)
90
113
  d.run
91
114
 
@@ -102,7 +125,9 @@ use_tag_as_key true
102
125
  end
103
126
 
104
127
  def create_driver(conf = default_config)
105
- Fluent::Test::BufferedOutputTestDriver.new(Fluent::DogstatsdOutput, 'dogstatsd.tag').configure(conf)
128
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::DogstatsdOutput, 'dogstatsd.tag').configure(conf).tap do |d|
129
+ d.instance.statsd = DummyStatsd.new
130
+ end
106
131
  end
107
132
  end
108
133
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-dogstatsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-09 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: dogstatsd-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.4.1
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
- version: '0'
40
+ version: 1.4.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,7 +80,6 @@ files:
80
80
  - Rakefile
81
81
  - fluent-plugin-dogstatsd.gemspec
82
82
  - lib/fluent/plugin/dogstatsd.rb
83
- - lib/fluent/plugin/dogstatsd/statsd_patch.rb
84
83
  - lib/fluent/plugin/dogstatsd/version.rb
85
84
  - lib/fluent/plugin/out_dogstatsd.rb
86
85
  - test/plugin/test_out_dogstatsd.rb
@@ -1,9 +0,0 @@
1
- require 'statsd'
2
-
3
- # https://github.com/DataDog/dogstatsd-ruby/pull/10
4
- class Statsd
5
- def flush_buffer()
6
- send_to_socket(@buffer.join("\n"))
7
- @buffer = Array.new
8
- end
9
- end