fozzie 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fozzie/adapter.rb +1 -1
- data/lib/fozzie/adapter/datadog.rb +26 -0
- data/lib/fozzie/adapter/statsd.rb +94 -95
- data/lib/fozzie/bulk_dsl.rb +27 -28
- data/lib/fozzie/configuration.rb +0 -2
- data/lib/fozzie/dsl.rb +17 -19
- data/lib/fozzie/interface.rb +140 -140
- data/lib/fozzie/version.rb +3 -3
- data/spec/lib/fozzie/adapter/datadog_spec.rb +31 -0
- data/spec/lib/fozzie/adapter/statsd_spec.rb +82 -82
- data/spec/lib/fozzie/configuration_spec.rb +125 -125
- data/spec/lib/fozzie/rack/sinatra_spec.rb +31 -31
- data/spec/shared_examples/interface.rb +154 -160
- data/spec/spec_helper.rb +32 -29
- metadata +4 -2
@@ -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
|
-
|
4
|
-
subject.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
subject.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
subject.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
subject.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
a
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
a
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
a
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
a
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
subject.
|
107
|
-
|
108
|
-
|
109
|
-
res
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
subject.
|
119
|
-
|
120
|
-
|
121
|
-
res
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
141
|
-
|
142
|
-
it "
|
143
|
-
subject.
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
config.
|
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
|
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-
|
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
|