fozzie 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,12 +16,10 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
-
20
- s.add_dependency 'statsd'
21
- s.add_dependency 'bson_ext'
22
-
19
+
20
+ s.add_dependency 'statsd-ruby'
23
21
  s.add_development_dependency 'rake'
24
- s.add_development_dependency "rspec"
25
- s.add_development_dependency "mocha"
26
- s.add_development_dependency "simplecov"
22
+ s.add_development_dependency 'rspec'
23
+ s.add_development_dependency 'mocha'
24
+ s.add_development_dependency 'simplecov'
27
25
  end
@@ -3,7 +3,7 @@ class Hash
3
3
  # Return self as symbolized keys hash
4
4
  def symbolize_keys
5
5
  self.dup.inject({}) do |hsh, (k,v)|
6
- hsh[k.to_sym] = (v.respond_to?(:symbolize_keys) ? v.symbolize_keys : v)
6
+ hsh[k.to_s.to_sym] = (v.respond_to?(:symbolize_keys) ? v.symbolize_keys : v)
7
7
  hsh
8
8
  end
9
9
  end
@@ -3,31 +3,47 @@ require 'statsd'
3
3
  module Fozzie
4
4
  module Classes
5
5
 
6
- class AbstractFozzie < Statsd::Client
6
+ class AbstractFozzie < Statsd
7
7
  attr_reader :prefix
8
8
 
9
9
  def initialize(host, port, prefix = nil)
10
- @prefix = prefix
10
+ @namespace = prefix unless prefix.nil?
11
11
  super host, port
12
12
  end
13
13
 
14
- def time_for(data, &block)
15
- tick = Time.now.usec
16
- block.call
17
- tock = Time.now.usec
18
- timing(data, (tock - tick))
14
+ def time_to_do(stat, sample_rate=1, &block); time_for(stat, sample_rate, &block); end
15
+ def time_for(stat, sample_rate=1, &block)
16
+ begin
17
+ time(stat, sample_rate, &block)
18
+ rescue => exc
19
+ yield block
20
+ end
21
+ end
22
+
23
+ def committed; commit; end
24
+ def commit
25
+ event :commit
26
+ end
27
+
28
+ def build; built; end
29
+ def built
30
+ event :build
31
+ end
32
+
33
+ def deploy; deployed; end
34
+ def deployed
35
+ event :deploy
19
36
  end
20
37
 
21
38
  private
22
39
 
23
- # Overload the send_stats method to automicatially prefix the data bucket string
24
- def send_stats(data, sample_rate = 1)
25
- super "#{@prefix}#{data}", sample_rate
40
+ def event(type)
41
+ timing "event.#{type.to_s}", Time.now.usec
26
42
  end
27
43
 
28
44
  end
29
45
 
30
- NAMESPACES = %w{Stats S}
46
+ NAMESPACES = %w{Stats S Statistics Warehouse}
31
47
 
32
48
  def self.included(klass)
33
49
  host, port, prefix = Fozzie.c.host, Fozzie.c.port, Fozzie.c.data_prefix
@@ -13,10 +13,10 @@ module Fozzie
13
13
 
14
14
  self
15
15
  end
16
-
16
+
17
17
  def data_prefix
18
- s = "%s." % env
19
- s = appname << ".#{s}" unless appname.nil? || appname.empty?
18
+ s = env
19
+ s = [appname, s].join('.').strip unless appname.nil? || appname.empty?
20
20
  s
21
21
  end
22
22
 
@@ -36,10 +36,10 @@ module Fozzie
36
36
  # Default configuration settings
37
37
  # @return [Hash]
38
38
  def self.default_configuration
39
- {
40
- :host => '127.0.0.1',
41
- :port => 8125,
42
- :config_path => '',
39
+ {
40
+ :host => '127.0.0.1',
41
+ :port => 8125,
42
+ :config_path => '',
43
43
  :env => (ENV['RAILS_ENV'] || 'development'),
44
44
  :appname => ''
45
45
  }.dup
@@ -52,7 +52,8 @@ module Fozzie
52
52
  def config_from_yaml(args)
53
53
  fp = full_config_path(args[:config_path])
54
54
  return {} unless File.exists?(fp)
55
- YAML.load(File.open(fp))[args[:env]].symbolize_keys
55
+ cnf = YAML.load(File.open(fp))[args[:env]]
56
+ (cnf.kind_of?(Hash)) ? cnf.symbolize_keys : {}
56
57
  end
57
58
 
58
59
  end
@@ -1,3 +1,3 @@
1
1
  module Fozzie
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -15,7 +15,7 @@ describe Fozzie::Configuration do
15
15
  c.host.should == '1.1.1.1'
16
16
  c.port.should == 9876
17
17
  c.appname.should == 'fozzie'
18
- c.data_prefix.should == 'fozzie.test.'
18
+ c.data_prefix.should == 'fozzie.test'
19
19
  end
20
20
 
21
21
  it "defaults env" do
@@ -23,12 +23,16 @@ describe Fozzie::Configuration do
23
23
  end
24
24
 
25
25
  it "creates a data prefix" do
26
- subject.data_prefix.should == 'development.'
26
+ subject.data_prefix.should == 'development'
27
27
  end
28
28
 
29
29
  it "creates a data prefix with appname when set" do
30
30
  subject.appname = 'astoria'
31
- subject.data_prefix.should == 'astoria.development.'
31
+ subject.data_prefix.should == 'astoria.development'
32
+ end
33
+
34
+ it "handles missing configuration namespace" do
35
+ proc { Fozzie::Configuration.new({:env => 'blbala', :config_path => 'spec/'}) }.should_not raise_error
32
36
  end
33
37
 
34
38
  end
@@ -23,7 +23,8 @@ describe Fozzie do
23
23
  kl.should respond_to(:increment)
24
24
  kl.should respond_to(:decrement)
25
25
  kl.should respond_to(:timing)
26
- kl.should respond_to(:update_counter)
26
+ kl.should respond_to(:count)
27
+ kl.should respond_to(:time)
27
28
  end
28
29
  end
29
30
 
@@ -34,13 +35,38 @@ describe Fozzie do
34
35
  end
35
36
  end
36
37
 
37
- it "assigns prefix when passed" do
38
- Fozzie::AbstractFozzie.new(1,2, 'a').prefix.should == 'a'
38
+ it "assigns namespace when passed" do
39
+ Fozzie::AbstractFozzie.new(1,2, 'a').namespace.should == 'a'
39
40
  end
40
41
 
41
42
  it "times a given block" do
42
- Stats.expects(:timing).with() {|b, val| b == 'data.bin' && (100..1200).include?(val) }
43
+ Stats.expects(:timing).with() {|b, val, timing| b == 'data.bin' && (1000..1200).include?(val) }.twice
43
44
  Stats.time_for('data.bin') { sleep 1 }
45
+ Stats.time_to_do('data.bin') { sleep 1 }
46
+ end
47
+
48
+ it "registers a commit" do
49
+ Stats.expects(:timing).with('event.commit', anything).twice
50
+ Stats.commit
51
+ Stats.committed
52
+ end
53
+
54
+ it "registers a build" do
55
+ Stats.expects(:timing).with('event.build', anything).twice
56
+ Stats.build
57
+ Stats.built
58
+ end
59
+
60
+ it "registers a deploy" do
61
+ Stats.expects(:timing).with('event.deploy', anything).twice
62
+ Stats.deploy
63
+ Stats.deployed
64
+ end
65
+
66
+ it "ignores exception and yields block" do
67
+ Stats.stubs(:time).raises(ArgumentError)
68
+ proc { Stats.time_for('data.bin') { sleep 1 } }.should_not raise_error
69
+ proc { Stats.time_to_do('data.bin') { sleep 1 } }.should_not raise_error
44
70
  end
45
71
 
46
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fozzie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000 Z
12
+ date: 2012-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: statsd
16
- requirement: &70188658675780 !ruby/object:Gem::Requirement
15
+ name: statsd-ruby
16
+ requirement: &70261680612280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70188658675780
25
- - !ruby/object:Gem::Dependency
26
- name: bson_ext
27
- requirement: &70188658675220 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70188658675220
24
+ version_requirements: *70261680612280
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: rake
38
- requirement: &70188658674600 !ruby/object:Gem::Requirement
27
+ requirement: &70261680611680 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ! '>='
@@ -43,10 +32,10 @@ dependencies:
43
32
  version: '0'
44
33
  type: :development
45
34
  prerelease: false
46
- version_requirements: *70188658674600
35
+ version_requirements: *70261680611680
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: rspec
49
- requirement: &70188658674020 !ruby/object:Gem::Requirement
38
+ requirement: &70261680610860 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ! '>='
@@ -54,10 +43,10 @@ dependencies:
54
43
  version: '0'
55
44
  type: :development
56
45
  prerelease: false
57
- version_requirements: *70188658674020
46
+ version_requirements: *70261680610860
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: mocha
60
- requirement: &70188658648740 !ruby/object:Gem::Requirement
49
+ requirement: &70261680609720 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ! '>='
@@ -65,10 +54,10 @@ dependencies:
65
54
  version: '0'
66
55
  type: :development
67
56
  prerelease: false
68
- version_requirements: *70188658648740
57
+ version_requirements: *70261680609720
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: simplecov
71
- requirement: &70188658648100 !ruby/object:Gem::Requirement
60
+ requirement: &70261680608580 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ! '>='
@@ -76,7 +65,7 @@ dependencies:
76
65
  version: '0'
77
66
  type: :development
78
67
  prerelease: false
79
- version_requirements: *70188658648100
68
+ version_requirements: *70261680608580
80
69
  description: Gem allows statistics gathering from Ruby and Ruby on Rails applications
81
70
  to Statsd
82
71
  email:
@@ -119,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
108
  version: '0'
120
109
  segments:
121
110
  - 0
122
- hash: -3087295047866477868
111
+ hash: 4014469359470497890
123
112
  required_rubygems_version: !ruby/object:Gem::Requirement
124
113
  none: false
125
114
  requirements:
@@ -128,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
117
  version: '0'
129
118
  segments:
130
119
  - 0
131
- hash: -3087295047866477868
120
+ hash: 4014469359470497890
132
121
  requirements: []
133
122
  rubyforge_project: fozzie
134
123
  rubygems_version: 1.8.10