formatted-metrics 1.3.3 → 1.4.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: 0e34fb0eb47e3322da0002729515a63f9a739f59
4
- data.tar.gz: 8c02e2121204d4431cc2a16641ccba75246a5751
3
+ metadata.gz: 05827edaccbe8c352e7a7917205ab3847358414a
4
+ data.tar.gz: 8a8f41fcd65745cc921abfc86e2fe121997ef3a6
5
5
  SHA512:
6
- metadata.gz: 0d33c359d5e6b49ea67bd85b4c1e88d155bcdb99f14655daa386548fc1a94cbbe0a32c6dc5d56ed879dbe1c7c6ef41b9c6cadb1a67100b1730ff491717dd82e8
7
- data.tar.gz: 03f173d4bca12f951359a75cce422ea7da12d1bcf2d96b332a1528a273426d8bec91c4dd07dd3c2782c878c7cdf4b14d51bc6db745020c72ba40e19b75486bf0
6
+ metadata.gz: 884c1f799016fbd47d7fb629d9bd024a3d255c992935413a3c817dc5f11d48e98a931cbe87a35a510584bb4b7d8d8abbac204b80684355fe7c0913211d86966d
7
+ data.tar.gz: 293a0d7b835fe274f9eec139f6b19c6db6a1a8aa3ac5ef32b6123c342fb16f2fdc1d10dc33db41425930738160c5710f12925f9b7e4ecfd3dfc096212a8c7222
@@ -15,6 +15,7 @@ module Metrics
15
15
  autoload :Base, 'metrics/drivers/base'
16
16
  autoload :L2Met, 'metrics/drivers/l2met'
17
17
  autoload :Statsd, 'metrics/drivers/statsd'
18
+ autoload :DogStatsd, 'metrics/drivers/dog_statsd'
18
19
  end
19
20
 
20
21
  module Helpers
@@ -0,0 +1,32 @@
1
+ module Metrics::Drivers
2
+ class DogStatsd < Statsd
3
+
4
+ def emit(instrumenter)
5
+ name = name_for(instrumenter)
6
+ value = instrumenter.value
7
+ tags = formatted_tags(instrumenter.tags)
8
+
9
+ case instrumenter.type
10
+ when 'histogram'
11
+ client.histogram(name, value, tags: tags)
12
+ when 'measure', 'sample'
13
+ if instrumenter.units == 'ms'
14
+ client.timing(name, value, tags: tags)
15
+ else
16
+ client.gauge(name, value, tags: tags)
17
+ end
18
+ when 'count'
19
+ client.count(name, value, tags: tags)
20
+ else
21
+ raise ArgumentError.new("unsupported instrumenter type for dogstatsd: '%s'" % instrumenter.type)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def formatted_tags(tags)
28
+ tags.map { |k, v| "%s:%s" % [k, v.to_s.tr(' ', '_')] }
29
+ end
30
+
31
+ end
32
+ end
@@ -46,6 +46,10 @@ module Metrics
46
46
  options[:source]
47
47
  end
48
48
 
49
+ def tags
50
+ options[:tags] || {}
51
+ end
52
+
49
53
  def result
50
54
  return nil unless block
51
55
  return @result if defined?(@result)
@@ -1,3 +1,3 @@
1
1
  module FormattedMetrics
2
- VERSION = '1.3.3'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'securerandom'
3
+
4
+ describe Metrics::Drivers::DogStatsd do
5
+ let(:client) { double }
6
+
7
+ def instrumenter(*args)
8
+ Metrics::Instrumenter.new(*args)
9
+ end
10
+
11
+ def write(*instrumenters)
12
+ described_class.new(client, '{{name}}.source__{{source}}__', 'app').write(*instrumenters)
13
+ end
14
+
15
+ describe '.write' do
16
+
17
+ context 'tag support' do
18
+
19
+ it 'should pass an empty tag array if no tags are given' do
20
+ client.should_receive(:timing).with('rack.request.time.source__app__', 10.3333, tags: [])
21
+ write(instrumenter('rack.request.time', 10.3333, units: 'ms', type: 'sample'))
22
+ end
23
+
24
+ it 'should pass a tag to the dogstatsd-ruby client' do
25
+ client.should_receive(:gauge).with('rack.request.size.source__app__', 10, tags: ['tag0:long_value_with_lots_of_whitespace'])
26
+ write(instrumenter('rack.request.size', 10, type: 'measure', tags: {tag0: 'long value with lots of whitespace'}))
27
+ end
28
+
29
+ it 'should pass multiple tags to the dogstatsd-ruby client' do
30
+ client.should_receive(:count).with('foo.bar.source__app__', 10, tags: ['tag0:value0', 'tag1:a_tag_value', 'tag2:2222'])
31
+ write(instrumenter('foo.bar', 10, type: 'count', tags: {tag0: 'value0', tag1: :a_tag_value, tag2: 2222}))
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -43,6 +43,19 @@ describe Metrics::Instrumenter do
43
43
  end
44
44
  end
45
45
 
46
+ describe '.tags' do
47
+ subject { instrumenter.tags }
48
+
49
+ context 'by default' do
50
+ it {should eq Hash.new }
51
+ end
52
+
53
+ context 'when specified' do
54
+ let(:instrumenter) { described_class.new('jobs.busy', 10, units: 'jobs', tags: {tag0: 'value0', tag1: 'value1'}) }
55
+ it {should eq({tag0: 'value0', tag1: 'value1'})}
56
+ end
57
+ end
58
+
46
59
  describe '.result' do
47
60
  subject { instrumenter.result }
48
61
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatted-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - lib/metrics.rb
87
87
  - lib/metrics/configuration.rb
88
88
  - lib/metrics/core_ext.rb
89
+ - lib/metrics/drivers/dog_statsd.rb
89
90
  - lib/metrics/drivers/l2met.rb
90
91
  - lib/metrics/drivers/statsd.rb
91
92
  - lib/metrics/grouping.rb
@@ -99,6 +100,7 @@ files:
99
100
  - lib/rack/instrumentation.rb
100
101
  - lib/sidekiq/middleware/server/instrumentation.rb
101
102
  - spec/faraday/instrumentation_spec.rb
103
+ - spec/metrics/drivers/dog_statsd_spec.rb
102
104
  - spec/metrics/drivers/l2met_spec.rb
103
105
  - spec/metrics/drivers/statsd_spec.rb
104
106
  - spec/metrics/grouping_spec.rb
@@ -134,6 +136,7 @@ specification_version: 4
134
136
  summary: Easily output formatted metrics to stdout
135
137
  test_files:
136
138
  - spec/faraday/instrumentation_spec.rb
139
+ - spec/metrics/drivers/dog_statsd_spec.rb
137
140
  - spec/metrics/drivers/l2met_spec.rb
138
141
  - spec/metrics/drivers/statsd_spec.rb
139
142
  - spec/metrics/grouping_spec.rb