lookout-rack-utils 3.5.0.28 → 3.6.0.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODJiODZkOTMzNDk3NWM2N2FmM2M4MzAwOTA2NmY1YjVjYTVkMGZmMA==
4
+ NTZkYmI0YjdiZjQ0YjAyZDFmYzA1YTk3M2ZmZTEyMmMzYmEwODJiNg==
5
5
  data.tar.gz: !binary |-
6
- OGI0MGUwODRmZDY3YmJkOTVlZGEzZGExZTE0ZGE2ZDE0MzRmYmU2NA==
6
+ MTljOWE4N2Q4ZjAwN2YzMTJiNjZhZDgyMjAzNjllOTBkY2YzZGIwYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTE3MDBhZTIzYzcwMTRkMjA2YjQ4Yzg2YWRhMjNiMTFmYTRjNjMxMTdlZDI5
10
- MTZiYTBhZDA1OGZjYTE5MWYyYjEzZDAwYzYxZjdlYTJiNDk2ZmQwMWZkMzY4
11
- NDJkOGU4MzVlYWJlN2NiNzkzZTQ2NWI1N2M2OGExNGYxZTNiYTI=
9
+ OGRlOGUzZTU1NTA4ZTIxYzFiYWI4YzllMzY2OThlMjMxY2ZjODY1MTFjZmMx
10
+ NzQ5OTMzM2Q3MDc0ZGQ2MDg3NDI1Yjk3NTM5ODA1ZmVlM2UwNzI5ZjAxNzk5
11
+ NDlmODM4ZDA1YTE2ZDRmNjg0NDJlZDFmNGMwZWY3MTc4MzZkZWY=
12
12
  data.tar.gz: !binary |-
13
- ODk0YjJkMjIyODVkY2VmNmQ4MDIxYzE3NjcxM2JlOWZiMGQ1NjFkNTRjYWMx
14
- MmE2OGE4Y2E1NjJiYzk5M2JlMGNmNDgyYmFiMmY4NjAzOWU4YzAxMzRhN2Vi
15
- YTI5M2E2NGFiZjg3OGQxOTczMzI4ZGVkMjFjNTQ4N2UzYWNkODU=
13
+ ZWZmODY1MDYzY2VkZWVjZDgwZWI1NmRmMDM3Y2JlYTM1M2FiY2I2NTJjMjQ2
14
+ MjFjNjNhNzU5NDIyYzIyNDY3ZTM2MTZmYzNlZTFkNDE0MGEyOTg5ODI4MjNk
15
+ OWMxOWY2YjgyNGUyMTQyZGViOGUyMmY5NWE3ZDY4NWUzNGI4MDE=
data/README.md CHANGED
@@ -33,9 +33,15 @@ Or install it yourself as:
33
33
  end
34
34
  ```
35
35
 
36
- You will also need to prime the instance before using it by calling
36
+ You will also need to prime the instance before using it by calling
37
37
  `Lookout::Rack::Utils::Graphite.instance`.
38
38
 
39
+ If you want to use a different Statsd implementation than
40
+ lookout-statsd, you can. Call +Lookout::Statsd.set_instance+ BEFORE
41
+ referencing the +Lookout::Rack::Utils::Graphite.instance+ in order to
42
+ use a different Statsd implementation. You'll need to configure the
43
+ Statsd object manually in that case.
44
+
39
45
  ### Lookout::Rack::Utils::I18n
40
46
  You'll need configatron set up:
41
47
 
@@ -1,12 +1,16 @@
1
1
  require 'singleton'
2
2
  require 'configatron'
3
- require 'statsd'
3
+ require 'lookout/statsd'
4
4
 
5
5
  require 'lookout/rack/utils'
6
6
 
7
7
  module Lookout::Rack::Utils
8
8
  # Statsd proxy. This class initializes the Statsd client and
9
- # delegates all stats related calls to it.
9
+ # delegates all stats related calls to it. It uses Lookout's statsd
10
+ # (https://github.com/lookout/statsd) as a wrapper, which can be
11
+ # setup to use another implementation under the hood. Call
12
+ # +Lookout::Statsd.set_instance+ BEFORE referencing the +instance+
13
+ # here in order to use a different Statsd implementation.
10
14
  #
11
15
  # Use as:
12
16
  # Lookout::Rack::Utils::Graphite.increment('device.associated')
@@ -16,25 +20,36 @@ module Lookout::Rack::Utils
16
20
  # end
17
21
  #
18
22
  class Graphite
19
- include Singleton
20
-
23
+ # Private Constructor -- treat this class like the Singleton it used to be
21
24
  def initialize
22
- prefix = configatron.statsd.prefix
23
- unless ENV['RACK_ENV'] == 'production'
24
- prefix = "dev.#{ENV['USER']}.#{prefix}"
25
+ if !Lookout::Statsd.instance_set?
26
+ prefix = configatron.statsd.prefix
27
+ unless ENV['RACK_ENV'] == 'production'
28
+ prefix = "dev.#{ENV['USER']}.#{prefix}"
29
+ end
30
+
31
+ Lookout::Statsd.create_instance(:host => configatron.statsd.host,
32
+ :port => configatron.statsd.port,
33
+ :prefix => prefix)
25
34
  end
35
+ end
36
+
37
+ # Provide same interface as old Singleton, but in test-friendly manner
38
+ def self.instance
39
+ @instance ||= new
40
+ end
26
41
 
27
- ::Statsd.create_instance(:host => configatron.statsd.host,
28
- :port => configatron.statsd.port,
29
- :prefix => prefix)
42
+ # Clear instance, for use in testing only
43
+ def self.clear_instance
44
+ @instance = nil
30
45
  end
31
46
 
32
47
  def self.method_missing(meth, *args, &block)
33
- self.instance && ::Statsd.instance.send(meth, *args, &block)
48
+ self.instance && Lookout::Statsd.instance.send(meth, *args, &block)
34
49
  end
35
50
 
36
51
  def self.respond_to?(method, include_private = false)
37
- super || (self.instance && ::Statsd.instance.respond_to?(method, include_private))
52
+ super || (self.instance && Lookout::Statsd.instance.respond_to?(method, include_private))
38
53
  end
39
54
  end
40
55
  end
@@ -1,7 +1,7 @@
1
1
  module Lookout
2
2
  module Rack
3
3
  module Utils
4
- VERSION = "3.5.0"
4
+ VERSION = "3.6.0"
5
5
  end
6
6
  end
7
7
  end
@@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency "rack-graphite", '~> 1.1'
33
33
  spec.add_dependency "configatron", '~> 2.13'
34
34
  spec.add_dependency "log4r"
35
- spec.add_dependency "lookout-statsd", '~> 2.0.0'
35
+ spec.add_dependency "lookout-statsd", '~> 3.0'
36
36
  end
@@ -2,38 +2,85 @@ require 'spec_helper'
2
2
  require 'lookout/rack/utils/graphite'
3
3
 
4
4
  describe Lookout::Rack::Utils::Graphite do
5
+ let(:statsd_instance) { nil }
5
6
  subject(:graphite) { described_class }
6
7
 
7
8
  before :each do
8
- graphite.instance # Initialize statsd singleton
9
9
  configatron.statsd.stub(:prefix).and_return('test')
10
+ Lookout::Statsd.clear_instance
11
+ described_class.clear_instance
12
+ Lookout::Statsd.set_instance(statsd_instance)
13
+ graphite.instance # Initialize statsd singleton
10
14
  end
11
15
 
12
- context 'offers statsd methods' do
13
- it { should respond_to :increment }
14
- it { should respond_to :decrement }
15
- it { should respond_to :timing }
16
- it { should respond_to :update_counter }
16
+ after :each do
17
+ Lookout::Statsd.clear_instance
18
+ described_class.clear_instance
17
19
  end
18
20
 
19
- it 'should delegate to statsd' do
20
- Statsd.instance.should_receive(:increment).once.with('device.associated')
21
- Lookout::Rack::Utils::Graphite.increment('device.associated')
21
+ context "without configuring statsd_instance" do
22
+ context 'offers statsd methods' do
23
+ it { should respond_to :increment }
24
+ it { should respond_to :decrement }
25
+ it { should respond_to :timing }
26
+ it { should respond_to :update_counter }
27
+ end
28
+
29
+ it 'should delegate to statsd' do
30
+ Lookout::Statsd.instance.should_receive(:increment).once.with('device.associated')
31
+ Lookout::Rack::Utils::Graphite.increment('device.associated')
32
+ end
33
+
34
+ describe '#timing' do
35
+ it 'should delegate the block to statsd' do
36
+ expect { |block|
37
+ Lookout::Statsd.instance.should_receive(:timing).once.with('device.became_aware', &block)
38
+ Lookout::Rack::Utils::Graphite.timing('device.became_aware', &block)
39
+ }.to yield_control
40
+ end
41
+
42
+ it 'should delegate the sample rate and block to statsd' do
43
+ expect { |block|
44
+ Lookout::Statsd.instance.should_receive(:timing).once.with('device.became_aware', 0.05, &block)
45
+ Lookout::Rack::Utils::Graphite.timing('device.became_aware', 0.05, &block)
46
+ }.to yield_control
47
+ end
48
+ end
22
49
  end
23
50
 
24
- describe '#timing' do
25
- it 'should delegate the block to statsd' do
26
- expect { |block|
27
- Statsd.instance.should_receive(:timing).once.with('device.became_aware', &block)
28
- Lookout::Rack::Utils::Graphite.timing('device.became_aware', &block)
29
- }.to yield_control
51
+ context "setting statsd_instance" do
52
+ let(:statsd_instance) { double('Statsd',
53
+ :increment => true,
54
+ :decrement => true,
55
+ :timing => true,
56
+ :update_counter => true) }
57
+
58
+ context 'offers statsd methods' do
59
+ it { should respond_to :increment }
60
+ it { should respond_to :decrement }
61
+ it { should respond_to :timing }
62
+ it { should respond_to :update_counter }
30
63
  end
31
64
 
32
- it 'should delegate the sample rate and block to statsd' do
33
- expect { |block|
34
- Statsd.instance.should_receive(:timing).once.with('device.became_aware', 0.05, &block)
35
- Lookout::Rack::Utils::Graphite.timing('device.became_aware', 0.05, &block)
36
- }.to yield_control
65
+ it 'should delegate to statsd' do
66
+ expect(statsd_instance).to receive(:increment).once.with('device.associated')
67
+ Lookout::Rack::Utils::Graphite.increment('device.associated')
68
+ end
69
+
70
+ describe '#timing' do
71
+ it 'should delegate the block to statsd' do
72
+ expect { |block|
73
+ expect(statsd_instance).to receive(:timing).once.with('device.became_aware', &block)
74
+ Lookout::Rack::Utils::Graphite.timing('device.became_aware', &block)
75
+ }.to yield_control
76
+ end
77
+
78
+ it 'should delegate the sample rate and block to statsd' do
79
+ expect { |block|
80
+ expect(statsd_instance).to receive(:timing).once.with('device.became_aware', 0.05, &block)
81
+ Lookout::Rack::Utils::Graphite.timing('device.became_aware', 0.05, &block)
82
+ }.to yield_control
83
+ end
37
84
  end
38
85
  end
39
86
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookout-rack-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0.28
4
+ version: 3.6.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-16 00:00:00.000000000 Z
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - ~>
186
186
  - !ruby/object:Gem::Version
187
- version: 2.0.0
187
+ version: '3.0'
188
188
  type: :runtime
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ~>
193
193
  - !ruby/object:Gem::Version
194
- version: 2.0.0
194
+ version: '3.0'
195
195
  description: A collection of rack utils.
196
196
  email:
197
197
  - ian.smith@lookout.com