lookout-statsd 3.0.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lookout/statsd.rb +11 -0
- data/spec/statsd_spec.rb +35 -0
- data/statsd.gemspec +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- 
         | 
| 2 2 | 
             
            SHA1: 
         | 
| 3 | 
            -
               | 
| 4 | 
            -
               | 
| 3 | 
            +
              metadata.gz: 242c2e64f28a0bd1cda881eb66c29266ed252495
         | 
| 4 | 
            +
              data.tar.gz: 6908899a20d708998dd44d43c970f4d6b4041a8f
         | 
| 5 5 | 
             
            SHA512: 
         | 
| 6 | 
            -
               | 
| 7 | 
            -
               | 
| 6 | 
            +
              metadata.gz: bb16f079fcf070e6ddd2b5f9ecd3900b1ade9439aca1042fbaffa6208d64ac871f8721d4bda43ba7408fdaf31818ebd7e02341dc62ef36ec2cf92a3e5145b4e7
         | 
| 7 | 
            +
              data.tar.gz: 39e7f363c2d2e65365012ab10c74b60d266a8b01adbb67f7a6790d9ed31e22f2224240cd2d7ea48cbb8dccd6e2a560fe8b09f629859b76b5d59260b9b7750011
         | 
    
        data/lib/lookout/statsd.rb
    CHANGED
    
    | @@ -77,6 +77,15 @@ module Lookout | |
| 77 77 | 
             
                  value
         | 
| 78 78 | 
             
                end
         | 
| 79 79 |  | 
| 80 | 
            +
                # +stat+ to log timing for, from provided block
         | 
| 81 | 
            +
                def time(stat, sample_rate = 1)
         | 
| 82 | 
            +
                  start_time = Time.now.to_f
         | 
| 83 | 
            +
                  value = yield
         | 
| 84 | 
            +
                ensure
         | 
| 85 | 
            +
                  timing(stat, ((Time.now.to_f - start_time) * 1000).floor, sample_rate)
         | 
| 86 | 
            +
                  value
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 80 89 | 
             
                # +stats+ can be a string or an array of strings
         | 
| 81 90 | 
             
                def increment(stats, sample_rate = 1)
         | 
| 82 91 | 
             
                  update_counter stats, 1, sample_rate
         | 
| @@ -94,6 +103,8 @@ module Lookout | |
| 94 103 | 
             
                  send_stats(stats.map { |s| "#{p}#{s}:#{delta}|c" }, sample_rate)
         | 
| 95 104 | 
             
                end
         | 
| 96 105 |  | 
| 106 | 
            +
                alias_method :count, :update_counter
         | 
| 107 | 
            +
             | 
| 97 108 | 
             
                # +stat_or_stats+ may either be a Hash OR a String. If it's a
         | 
| 98 109 | 
             
                # String, then value must be specified. Other statsd client gems
         | 
| 99 110 | 
             
                # have mostly standardized on using the String+value format, but
         | 
    
        data/spec/statsd_spec.rb
    CHANGED
    
    | @@ -158,6 +158,32 @@ describe Lookout::StatsdClient do | |
| 158 158 | 
             
                end
         | 
| 159 159 | 
             
              end
         | 
| 160 160 |  | 
| 161 | 
            +
              describe '#time' do
         | 
| 162 | 
            +
                let(:c) { Lookout::StatsdClient.new }
         | 
| 163 | 
            +
                let(:value) { 1337 }
         | 
| 164 | 
            +
                let(:sample_rate) { 3 }
         | 
| 165 | 
            +
             | 
| 166 | 
            +
                before :each do
         | 
| 167 | 
            +
                  # Pretend our block took one second
         | 
| 168 | 
            +
                  Time.stub_chain(:now, :to_f).and_return(1, 2)
         | 
| 169 | 
            +
                end
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                it 'should wrap a block correctly' do
         | 
| 172 | 
            +
                  expect(c).to receive(:timing).with('foo', 1000, 1)
         | 
| 173 | 
            +
                  c.time('foo') { true }
         | 
| 174 | 
            +
                end
         | 
| 175 | 
            +
             | 
| 176 | 
            +
                it 'should pass along sample rate' do
         | 
| 177 | 
            +
                  expect(c).to receive(:timing).with('foo', 1000, sample_rate)
         | 
| 178 | 
            +
                  c.time('foo', sample_rate) { true }
         | 
| 179 | 
            +
                end
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                it 'should return the return value from the block' do
         | 
| 182 | 
            +
                  value = c.time('foo') { value }
         | 
| 183 | 
            +
                  expect(value).to eq value
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
              end
         | 
| 186 | 
            +
             | 
| 161 187 | 
             
              describe '#increment' do
         | 
| 162 188 | 
             
                let(:c) { Lookout::StatsdClient.new }
         | 
| 163 189 |  | 
| @@ -192,6 +218,15 @@ describe Lookout::StatsdClient do | |
| 192 218 | 
             
                end
         | 
| 193 219 | 
             
              end
         | 
| 194 220 |  | 
| 221 | 
            +
              describe '#count' do
         | 
| 222 | 
            +
                let(:c) { Lookout::StatsdClient.new }
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                it 'should behave like update_counter' do
         | 
| 225 | 
            +
                  c.should_receive(:send_stats).with(['foo:123|c'], 1)
         | 
| 226 | 
            +
                  c.update_counter('foo', 123, 1)
         | 
| 227 | 
            +
                end
         | 
| 228 | 
            +
              end
         | 
| 229 | 
            +
             | 
| 195 230 | 
             
              describe '#gauge' do
         | 
| 196 231 | 
             
                let(:c) { Lookout::StatsdClient.new }
         | 
| 197 232 |  | 
    
        data/statsd.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: lookout-statsd
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 3. | 
| 4 | 
            +
              version: 3.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - R. Tyler Croy
         | 
| @@ -11,7 +11,7 @@ autorequire: | |
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 13 |  | 
| 14 | 
            -
            date: 2016-07- | 
| 14 | 
            +
            date: 2016-07-18 00:00:00 Z
         | 
| 15 15 | 
             
            dependencies: []
         | 
| 16 16 |  | 
| 17 17 | 
             
            description: A simple ruby statsd client.
         |