fozzie 1.0.3 → 1.1.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.
@@ -1,31 +1,31 @@
1
- require 'fozzie/rack/middleware'
2
- require 'sinatra/base'
3
- require 'rack/test'
4
-
5
- describe "Sinatra Server with Middleware" do
6
- include Rack::Test::Methods
7
-
8
- def app
9
- Sinatra.new do
10
- set :environment, :test
11
- use Fozzie::Rack::Middleware
12
- get('/') { "echo" }
13
- get('/somewhere/nice') { "echo" }
14
- end
15
- end
16
-
17
- it "sends stats request on root" do
18
- S.should_receive(:timing).with('index.render', anything, anything)
19
- get '/'
20
- last_response.should be_ok
21
- last_response.body.should == 'echo'
22
- end
23
-
24
- it "sends stats request on nested path" do
25
- S.should_receive(:timing).with('somewhere.nice.render', anything, anything)
26
-
27
- get '/somewhere/nice'
28
- last_response.should be_ok
29
- last_response.body.should == 'echo'
30
- end
31
- end
1
+ require 'fozzie/rack/middleware'
2
+ require 'sinatra/base'
3
+ require 'rack/test'
4
+
5
+ describe "Sinatra Server with Middleware" do
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ Sinatra.new do
10
+ set :environment, :test
11
+ use Fozzie::Rack::Middleware
12
+ get('/') { "echo" }
13
+ get('/somewhere/nice') { "echo" }
14
+ end
15
+ end
16
+
17
+ it "sends stats request on root" do
18
+ S.should_receive(:timing).with('index.render', anything, anything, anything)
19
+ get '/'
20
+ last_response.should be_ok
21
+ last_response.body.should == 'echo'
22
+ end
23
+
24
+ it "sends stats request on nested path" do
25
+ S.should_receive(:timing).with('somewhere.nice.render', anything, anything, anything)
26
+
27
+ get '/somewhere/nice'
28
+ last_response.should be_ok
29
+ last_response.body.should == 'echo'
30
+ end
31
+ end
@@ -1,160 +1,154 @@
1
- shared_examples "interface" do
2
-
3
- it "#increment" do
4
- subject.should_receive(:send).with('wat', 1, :count, 1)
5
- subject.increment 'wat'
6
- end
7
-
8
- it "#decrement" do
9
- subject.should_receive(:send).with('wat', -1, :count, 1)
10
- subject.decrement 'wat'
11
- end
12
-
13
- it "#count" do
14
- subject.should_receive(:send).with('wat', 5, :count, 1)
15
- subject.count 'wat', 5
16
- end
17
-
18
- it "#timing" do
19
- subject.should_receive(:send).with('wat', 500, :timing, 1)
20
- subject.timing 'wat', 500
21
- end
22
-
23
- it "times a given block" do
24
- subject.should_receive(:timing).with do |b, val, timing|
25
- b == 'data.bin' && (1..11).include?(val)
26
- end.exactly(3).times
27
-
28
- subject.time_for('data.bin') { sleep 0.01 }
29
- subject.time_to_do('data.bin') { sleep 0.01 }
30
- subject.time('data.bin') { sleep 0.01 }
31
- end
32
-
33
- describe "event" do
34
- it "for a commit" do
35
- subject.should_receive(:gauge).with(['event', 'commit', nil], anything).twice
36
- subject.commit
37
- subject.committed
38
- end
39
-
40
- it "for a build" do
41
- subject.should_receive(:gauge).with(['event', 'build', nil], anything).twice
42
- subject.build
43
- subject.built
44
- end
45
-
46
- it "for a deploy" do
47
- subject.should_receive(:gauge).with(['event', 'deploy', nil], anything).twice
48
- subject.deploy
49
- subject.deployed
50
- end
51
-
52
- it "for anything" do
53
- subject.should_receive(:send).with(['event', 'foo', nil], anything, :gauge, 1)
54
- subject.event 'foo'
55
- end
56
-
57
- it "accepts an app name" do
58
- subject.should_receive(:send).with(['event', 'foo', 'fozzie'], anything, :gauge, 1)
59
- subject.event 'foo', 'fozzie'
60
- end
61
- end
62
-
63
- describe "#increment_on" do
64
- it "registers success" do
65
- subject.should_receive(:increment).with(["event.increment", "success"], 1)
66
- subject.increment_on('event.increment', true).should == true
67
- end
68
-
69
- it "registers failure" do
70
- subject.should_receive(:increment).with(["event.increment", "fail"], 1)
71
- subject.increment_on('event.increment', false).should == false
72
- end
73
-
74
- it "simply questions the passed val with if" do
75
- a = double
76
- a.should_receive(:save).and_return({})
77
- subject.should_receive(:increment).with(["event.increment", "success"], 1)
78
- subject.increment_on('event.increment', a.save).should == {}
79
- end
80
-
81
- it "registers fail on nil return" do
82
- a = double
83
- a.should_receive(:save).and_return(nil)
84
- subject.should_receive(:increment).with(["event.increment", "fail"], 1)
85
- subject.increment_on('event.increment', a.save).should == nil
86
- end
87
-
88
- describe "performing actions" do
89
- it "registers success" do
90
- a = double
91
- a.should_receive(:save).and_return(true)
92
- subject.should_receive(:increment).with(["event.increment", "success"], 1)
93
- subject.increment_on('event.increment', a.save).should == true
94
- end
95
-
96
- it "registers failure" do
97
- a = double
98
- a.should_receive(:save).and_return(false)
99
- subject.should_receive(:increment).with(["event.increment", "fail"], 1)
100
- subject.increment_on('event.increment', a.save).should == false
101
- end
102
-
103
- it "registers positive even when nested" do
104
- a = double
105
- a.should_receive(:save).and_return(true)
106
- subject.should_receive(:timing).with('event.run', anything, anything)
107
- subject.should_receive(:increment).with(["event.increment", "success"], 1)
108
-
109
- res = subject.time_to_do "event.run" do
110
- subject.increment_on('event.increment', a.save)
111
- end
112
- res.should == true
113
- end
114
-
115
- it "registers negative even when nested" do
116
- a = double
117
- a.should_receive(:save).and_return(false)
118
- subject.should_receive(:timing).with('event.run', anything, anything)
119
- subject.should_receive(:increment).with(["event.increment", "fail"], 1)
120
-
121
- res = subject.time_to_do "event.run" do
122
- subject.increment_on('event.increment', a.save)
123
- end
124
- res.should == false
125
- end
126
- end
127
- end
128
-
129
- describe "#bulk" do
130
-
131
- it "registers statistics in a single call" do
132
- Fozzie.c.adapter.should_receive(:register).once
133
-
134
- subject.bulk do
135
- increment :foo
136
- decrement :bar
137
- end
138
- end
139
-
140
- end
141
-
142
- it "registers a gauge measurement" do
143
- subject.should_receive(:send).with("mystat", 99, :gauge, 1)
144
- subject.gauge("mystat", 99)
145
- end
146
-
147
- it "raises exception if natural exception from block" do
148
- proc { subject.time_to_do('data.bin', 1, :gauge, 1) { raise ArgumentError, "testing" } }.should raise_error(ArgumentError)
149
- end
150
-
151
- it "only calls the block once on error" do
152
- Fozzie.c.adapter.stub(:send) { raise SocketError }
153
- i = 0
154
- p = proc {|n| (n + 1) }
155
- val = subject.time_to_do('data.bin') { i+= p.call(i) }
156
-
157
- val.should == 1
158
- end
159
-
160
- end
1
+ shared_examples "interface" do
2
+ it "#increment" do
3
+ subject.should_receive(:send).with('wat', 1, :count, 1, {})
4
+ subject.increment 'wat'
5
+ end
6
+
7
+ it "#decrement" do
8
+ subject.should_receive(:send).with('wat', -1, :count, 1, {})
9
+ subject.decrement 'wat'
10
+ end
11
+
12
+ it "#count" do
13
+ subject.should_receive(:send).with('wat', 5, :count, 1, {})
14
+ subject.count 'wat', 5
15
+ end
16
+
17
+ it "#timing" do
18
+ subject.should_receive(:send).with('wat', 500, :timing, 1, {})
19
+ subject.timing 'wat', 500
20
+ end
21
+
22
+ it "times a given block" do
23
+ subject.should_receive(:timing).with(/data.bin/, kind_of(Numeric), 1, {}).exactly(3).times
24
+
25
+ subject.time_for('data.bin') { true }
26
+ subject.time_to_do('data.bin') { true }
27
+ subject.time('data.bin') { true }
28
+ end
29
+
30
+ describe "event" do
31
+ it "for a commit" do
32
+ subject.should_receive(:gauge).with(['event', 'commit', nil], anything, 1, {}).twice
33
+ subject.commit
34
+ subject.committed
35
+ end
36
+
37
+ it "for a build" do
38
+ subject.should_receive(:gauge).with(['event', 'build', nil], anything, 1, {}).twice
39
+ subject.build
40
+ subject.built
41
+ end
42
+
43
+ it "for a deploy" do
44
+ subject.should_receive(:gauge).with(['event', 'deploy', nil], anything, 1, {}).twice
45
+ subject.deploy
46
+ subject.deployed
47
+ end
48
+
49
+ it "for anything" do
50
+ subject.should_receive(:send).with(['event', 'foo', nil], anything, :gauge, 1, {})
51
+ subject.event 'foo'
52
+ end
53
+
54
+ it "accepts an app name" do
55
+ subject.should_receive(:send).with(['event', 'foo', 'fozzie'], anything, :gauge, 1, {})
56
+ subject.event 'foo', 'fozzie'
57
+ end
58
+ end
59
+
60
+ describe "#increment_on" do
61
+ it "registers success" do
62
+ subject.should_receive(:increment).with(["event.increment", "success"], 1, {})
63
+ subject.increment_on('event.increment', true).should == true
64
+ end
65
+
66
+ it "registers failure" do
67
+ subject.should_receive(:increment).with(["event.increment", "fail"], 1, {})
68
+ subject.increment_on('event.increment', false).should == false
69
+ end
70
+
71
+ it "simply questions the passed val with if" do
72
+ a = double
73
+ a.should_receive(:save).and_return({})
74
+ subject.should_receive(:increment).with(["event.increment", "success"], 1, {})
75
+ subject.increment_on('event.increment', a.save).should == {}
76
+ end
77
+
78
+ it "registers fail on nil return" do
79
+ a = double
80
+ a.should_receive(:save).and_return(nil)
81
+ subject.should_receive(:increment).with(["event.increment", "fail"], 1, {})
82
+ subject.increment_on('event.increment', a.save).should == nil
83
+ end
84
+
85
+ describe "performing actions" do
86
+ it "registers success" do
87
+ a = double
88
+ a.should_receive(:save).and_return(true)
89
+ subject.should_receive(:increment).with(["event.increment", "success"], 1, {})
90
+ subject.increment_on('event.increment', a.save).should == true
91
+ end
92
+
93
+ it "registers failure" do
94
+ a = double
95
+ a.should_receive(:save).and_return(false)
96
+ subject.should_receive(:increment).with(["event.increment", "fail"], 1, {})
97
+ subject.increment_on('event.increment', a.save).should == false
98
+ end
99
+
100
+ it "registers positive even when nested" do
101
+ a = double
102
+ a.should_receive(:save).and_return(true)
103
+ subject.should_receive(:timing).with('event.run', anything, anything, {})
104
+ subject.should_receive(:increment).with(["event.increment", "success"], 1, {})
105
+
106
+ res = subject.time_to_do "event.run" do
107
+ subject.increment_on('event.increment', a.save)
108
+ end
109
+ res.should == true
110
+ end
111
+
112
+ it "registers negative even when nested" do
113
+ a = double
114
+ a.should_receive(:save).and_return(false)
115
+ subject.should_receive(:timing).with('event.run', anything, anything, {})
116
+ subject.should_receive(:increment).with(["event.increment", "fail"], 1, {})
117
+
118
+ res = subject.time_to_do "event.run" do
119
+ subject.increment_on('event.increment', a.save)
120
+ end
121
+ res.should == false
122
+ end
123
+ end
124
+ end
125
+
126
+ describe "#bulk" do
127
+ it "registers statistics in a single call" do
128
+ Fozzie.c.adapter.should_receive(:register).once
129
+
130
+ subject.bulk do
131
+ increment :foo
132
+ decrement :bar
133
+ end
134
+ end
135
+ end
136
+
137
+ it "registers a gauge measurement" do
138
+ subject.should_receive(:send).with("mystat", 99, :gauge, 1, {})
139
+ subject.gauge("mystat", 99)
140
+ end
141
+
142
+ it "raises exception if natural exception from block" do
143
+ proc { subject.time_to_do('data.bin', 1, :gauge, 1) { raise ArgumentError, "testing" } }.should raise_error(ArgumentError)
144
+ end
145
+
146
+ it "only calls the block once on error" do
147
+ Fozzie.c.adapter.stub(:send) { raise SocketError }
148
+ i = 0
149
+ p = proc {|n| (n + 1) }
150
+ val = subject.time_to_do('data.bin') { i+= p.call(i) }
151
+
152
+ val.should == 1
153
+ end
154
+ end
@@ -1,29 +1,32 @@
1
- ENV['RACK_ENV'] ||= 'test'
2
-
3
- # Basic path registers
4
- root = File.expand_path('../', File.dirname(__FILE__))
5
- lib = File.expand_path('lib', root)
6
- $:.unshift(root, lib)
7
-
8
- # Shared Examples
9
- Dir[File.expand_path('spec/shared_examples/*.rb')].each {|r| require r }
10
-
11
- require 'fozzie'
12
-
13
- module Fozzie
14
- class Adapter::TestAdapter
15
- def register(*params); end
16
- def delimeter; ""; end
17
- def safe_separator; ""; end
18
- end
19
- end
20
-
21
- Fozzie.configure do |config|
22
- config.host = '127.0.0.1'
23
- config.port = 8809
24
- config.adapter = "TestAdapter"
25
- end
26
-
27
- RSpec.configure do |config|
28
- config.order = :random
29
- end
1
+ ENV['RACK_ENV'] ||= 'test'
2
+
3
+ # Basic path registers
4
+ root = File.expand_path('../', File.dirname(__FILE__))
5
+ lib = File.expand_path('lib', root)
6
+ $:.unshift(root, lib)
7
+
8
+ require 'fozzie'
9
+
10
+ module Fozzie
11
+ class Adapter::TestAdapter
12
+ def register(*params); end
13
+ def delimeter; ""; end
14
+ def safe_separator; ""; end
15
+ end
16
+ end
17
+
18
+ Fozzie.configure do |config|
19
+ config.host = '127.0.0.1'
20
+ config.port = 8809
21
+ config.adapter = "TestAdapter"
22
+ end
23
+
24
+ RSpec.configure do |config|
25
+ config.order = :random
26
+ config.expect_with(:rspec) { |c| c.syntax = :should }
27
+ config.mock_with(:rspec) { |c| c.syntax = :should }
28
+ config.raise_errors_for_deprecations!
29
+ end
30
+
31
+ # Shared Examples
32
+ Dir[File.expand_path('spec/shared_examples/*.rb')].each {|r| require r }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fozzie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Watts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-uname
@@ -104,6 +104,7 @@ files:
104
104
  - lib/core_ext/string/snakecase.rb
105
105
  - lib/fozzie.rb
106
106
  - lib/fozzie/adapter.rb
107
+ - lib/fozzie/adapter/datadog.rb
107
108
  - lib/fozzie/adapter/statsd.rb
108
109
  - lib/fozzie/bulk_dsl.rb
109
110
  - lib/fozzie/configuration.rb
@@ -117,6 +118,7 @@ files:
117
118
  - resources/mill.min.js.example
118
119
  - spec/config/fozzie.yml
119
120
  - spec/lib/core_ext/module/monitor_spec.rb
121
+ - spec/lib/fozzie/adapter/datadog_spec.rb
120
122
  - spec/lib/fozzie/adapter/statsd_spec.rb
121
123
  - spec/lib/fozzie/bulk_dsl_spec.rb
122
124
  - spec/lib/fozzie/configuration_spec.rb