rack-stats 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57478c413f1cd1b052070b10d22cc7efa2bc3ca5
4
- data.tar.gz: db6b9b28a2cd768f3c387fd738d1697c25e6668e
3
+ metadata.gz: f929b49c78e4e0f740861cfefe7e0c9ac7f8578d
4
+ data.tar.gz: b7c518fb2cec24740373cbabcefe94d8c3eb240f
5
5
  SHA512:
6
- metadata.gz: 09de449d84aad70ff1b0d3415f53d9f48c0f16cfe4606f38ec6c98b4874428764b1549ffb634a470912956ea468acd38dcdb519b6382078773ed71a479292c6a
7
- data.tar.gz: f60e6c7904216a117ad9f041d7a50408e7994e3827f7362270055a9544a4eab340936e660e8d9f4f976abe2dacf47407b173a73d87610bc2d4ae15080091906d
6
+ metadata.gz: 0136a39a4e69d328cb302f16a0ccad319b5c903e1bf9e0fa5c24e8de8ebde50d64b0fc577f4f45d3c35c481f65d9b74f3b11eb891d8874c882615df8c8ff4ada
7
+ data.tar.gz: b1742b17aaab56ebccef81d977c5c54286f6295fdd9905c71ed727ba86e29a9cea24c2c11b3b2ff8c206ab28eb42f848b88eac1dda9819af4c923a2c5ff7e55c
@@ -6,12 +6,12 @@ require 'rack/stats/stat'
6
6
  module Rack
7
7
  class Stats
8
8
  class Runtime
9
- def initialize(statsd, app, env, stats)
9
+ def initialize(statsd, app, env, stats, namespace)
10
10
  @batch = Statsd::Batch.new statsd
11
11
  @app, @env, @timer = app, env, Timer.new
12
12
  @stats = stats.map do |stat|
13
13
  klass = stat[:type] == :increment ? Stat::Increment : Stat::Timing
14
- klass.new stat[:name], stat[:value], stat[:condition]
14
+ klass.new stat[:name], stat[:value], stat[:condition], namespace
15
15
  end
16
16
  end
17
17
 
@@ -2,13 +2,15 @@ module Rack
2
2
  class Stats
3
3
  module Stat
4
4
  class Base
5
- def initialize(compute_name, compute_value = nil, condition = nil)
6
- @compute_name, @compute_value, @condition = \
7
- compute_name, compute_value, condition
5
+ def initialize(compute_name, compute_value = nil,
6
+ condition = nil, namespace = nil)
7
+ @compute_name, @compute_value, @condition, @namespace = \
8
+ compute_name, compute_value, condition, namespace
8
9
  end
9
10
 
10
11
  def execute(batch, request, duration, response)
11
- if @condition.nil? || @condition.call(request, duration, response)
12
+ if duration.ms > 0 && \
13
+ (@condition.nil? || @condition.call(request, duration, response))
12
14
  send_data(batch, request, duration, response)
13
15
  end
14
16
  end
@@ -18,7 +20,10 @@ module Rack
18
20
  def send_data(batch, request, duration, response)
19
21
  batch.send(
20
22
  :timing,
21
- [@compute_name.call(request, duration, response)].compact.join('.'),
23
+ [
24
+ @namespace,
25
+ @compute_name.call(request, duration, response)
26
+ ].flatten.compact.join('.'),
22
27
  @compute_value.call(request, duration, response)
23
28
  )
24
29
  end
@@ -28,7 +33,10 @@ module Rack
28
33
  def send_data(batch, request, duration, response)
29
34
  batch.send(
30
35
  :increment,
31
- [@compute_name.call(request, duration, response)].compact.join('.')
36
+ [
37
+ @namespace,
38
+ @compute_name.call(request, duration, response)
39
+ ].flatten.compact.join('.')
32
40
  )
33
41
  end
34
42
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Stats
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
data/lib/rack/stats.rb CHANGED
@@ -36,12 +36,11 @@ module Rack
36
36
  @app = app
37
37
  @namespace = args.fetch(:namespace, ENV['RACK_STATS_NAMESPACE'])
38
38
  @statsd = Statsd.new(*args.fetch(:statsd, '127.0.0.1:8125').split(':'))
39
- @statsd.tap { |sd| sd.namespace = @namespace } if @namespace
40
39
  @stats = args.fetch(:stats, DEFAULT_STATS)
41
40
  end
42
41
 
43
42
  def call(env)
44
- Runtime.new(@statsd, @app, env, @stats).execute
43
+ Runtime.new(@statsd, @app, env, @stats, @namespace).execute
45
44
  end
46
45
  end
47
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Montagne