fozzie 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
- module Fozzie
2
- VERSION = "1.0.3"
3
- end
1
+ module Fozzie
2
+ VERSION = "1.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'fozzie/adapter/datadog'
3
+
4
+ module Fozzie::Adapter
5
+ describe Datadog do
6
+ it_behaves_like "fozzie adapter"
7
+
8
+ # Switch to Statsd adapter for the duration of this test
9
+ before(:all) do
10
+ Fozzie.c.adapter = :Datadog
11
+ end
12
+
13
+ after(:all) do
14
+ Fozzie.c.adapter = :TestAdapter
15
+ end
16
+
17
+ describe "#register" do
18
+ it "appends tags to the metrics" do
19
+ subject.should_receive(:send_to_socket).with(%r{\|#country:usa,testing$})
20
+
21
+ subject.register(:bucket => "foo", :value => 1, :type => :gauge, :sample_rate => 1, tags: ['country:usa','testing'])
22
+ end
23
+
24
+ it "does not append tags when none are specified" do
25
+ subject.should_receive(:send_to_socket).with(%r{foo:1\|g$})
26
+
27
+ subject.register(:bucket => "foo", :value => 1, :type => :gauge, :sample_rate => 1)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,82 +1,82 @@
1
- require 'spec_helper'
2
- require 'fozzie/adapter/statsd'
3
-
4
- module Fozzie::Adapter
5
- describe Statsd do
6
- it_behaves_like "fozzie adapter"
7
-
8
- # Switch to Statsd adapter for the duration of this test
9
- before(:all) do
10
- Fozzie.c.adapter = :Statsd
11
- end
12
-
13
- after(:all) do
14
- Fozzie.c.adapter = :TestAdapter
15
- end
16
-
17
- it "downcases any stat value" do
18
- subject.should_receive(:send_to_socket).with {|bin| bin.match /\.foo/ }
19
-
20
- subject.register(:bin => "FOO", :value => 1, :type => :gauge, :sample_rate => 1)
21
- end
22
-
23
- describe "#format_bucket" do
24
- it "accepts arrays" do
25
- subject.format_bucket([:foo, '2']).should match /foo.2$/
26
- subject.format_bucket([:foo, '2']).should match /foo.2$/
27
- subject.format_bucket(%w{foo bar}).should match /foo.bar$/
28
- end
29
-
30
- it "converts any values to strings for stat value, ignoring nil" do
31
- subject.format_bucket([:foo, 1, nil, "@", "BAR"]).should =~ /foo.1._.bar/
32
- end
33
-
34
- it "replaces invalid chracters" do
35
- subject.format_bucket([:foo, ':']).should match /foo.#{subject.class::RESERVED_CHARS_REPLACEMENT}$/
36
- subject.format_bucket([:foo, '@']).should match /foo.#{subject.class::RESERVED_CHARS_REPLACEMENT}$/
37
- subject.format_bucket('foo.bar.|').should match /foo.bar.#{subject.class::RESERVED_CHARS_REPLACEMENT}$/
38
- end
39
- end
40
-
41
- describe "#format_value" do
42
- it "defaults type to gauge when type is not mapped" do
43
- subject.format_value(1, :foo, 1).should eq '1|g'
44
- end
45
-
46
- it "converts basic values to string" do
47
- subject.format_value(1, :count, 1).should eq '1|c'
48
- end
49
- end
50
-
51
- it "ensures block is called on socket error" do
52
- subject.socket.stub(:send) { raise SocketError }
53
-
54
- proc { subject.register(:bin => 'data.bin', :value => 1, :type => :gauge, :sample_rate => 1) { sleep 0.01 } }.should_not raise_error
55
- proc { subject.register(:bin => 'data.bin', :value => 1, :type => :gauge, :sample_rate => 1) { sleep 0.01 } }.should_not raise_error
56
- end
57
-
58
- it "raises Timeout on slow lookup" do
59
- Fozzie.c.timeout = 0.01
60
- subject.socket.stub(:send).with(any_args) { sleep 0.4 }
61
-
62
- subject.register(:bin => 'data.bin', :value => 1, :type => :gauge, :sample_rate => 1).should eq false
63
- end
64
-
65
- describe "multiple stats in a single call" do
66
-
67
- it "collects stats together with delimeter" do
68
- Fozzie.c.disable_prefix
69
-
70
- stats = [
71
- { :bin => 'foo', :value => 1, :type => :count, :sample_rate => 1 },
72
- { :bin => 'bar', :value => 1, :type => :gauge, :sample_rate => 1 },
73
- { :bin => %w{foo bar}, :value => 100, :type => :timing, :sample_rate => 1 }
74
- ]
75
-
76
- subject.should_receive(:send_to_socket).with "foo:1|c\nbar:1|g\nfoo.bar:100|ms"
77
-
78
- subject.register(stats)
79
- end
80
- end
81
- end
82
- end
1
+ require 'spec_helper'
2
+ require 'fozzie/adapter/statsd'
3
+
4
+ module Fozzie::Adapter
5
+ describe Statsd do
6
+ it_behaves_like "fozzie adapter"
7
+
8
+ # Switch to Statsd adapter for the duration of this test
9
+ before(:all) do
10
+ Fozzie.c.adapter = :Statsd
11
+ end
12
+
13
+ after(:all) do
14
+ Fozzie.c.adapter = :TestAdapter
15
+ end
16
+
17
+ it "downcases any stat value" do
18
+ subject.should_receive(:send_to_socket).with(/\.foo/)
19
+
20
+ subject.register(:bucket => "FOO", :value => 1, :type => :gauge, :sample_rate => 1)
21
+ end
22
+
23
+ describe "#format_bucket" do
24
+ it "accepts arrays" do
25
+ subject.format_bucket([:foo, '2']).should match(/foo.2$/)
26
+ subject.format_bucket([:foo, '2']).should match(/foo.2$/)
27
+ subject.format_bucket(%w{foo bar}).should match(/foo.bar$/)
28
+ end
29
+
30
+ it "converts any values to strings for stat value, ignoring nil" do
31
+ subject.format_bucket([:foo, 1, nil, "@", "BAR"]).should =~ /foo.1._.bar/
32
+ end
33
+
34
+ it "replaces invalid chracters" do
35
+ subject.format_bucket([:foo, ':']).should match(/foo.#{subject.class::RESERVED_CHARS_REPLACEMENT}$/)
36
+ subject.format_bucket([:foo, '@']).should match(/foo.#{subject.class::RESERVED_CHARS_REPLACEMENT}$/)
37
+ subject.format_bucket('foo.bar.|').should match(/foo.bar.#{subject.class::RESERVED_CHARS_REPLACEMENT}$/)
38
+ end
39
+ end
40
+
41
+ describe "#format_value" do
42
+ it "defaults type to gauge when type is not mapped" do
43
+ subject.format_value(1, :foo, 1).should eq '1|g'
44
+ end
45
+
46
+ it "converts basic values to string" do
47
+ subject.format_value(1, :count, 1).should eq '1|c'
48
+ end
49
+ end
50
+
51
+ it "ensures block is called on socket error" do
52
+ subject.socket.stub(:send) { raise SocketError }
53
+
54
+ proc { subject.register(:bucket => 'data.bin', :value => 1, :type => :gauge, :sample_rate => 1) { sleep 0.01 } }.should_not raise_error
55
+ proc { subject.register(:bucket => 'data.bin', :value => 1, :type => :gauge, :sample_rate => 1) { sleep 0.01 } }.should_not raise_error
56
+ end
57
+
58
+ it "raises Timeout on slow lookup" do
59
+ Fozzie.c.timeout = 0.01
60
+ subject.socket.stub(:send).with(any_args) { sleep 0.4 }
61
+
62
+ subject.register(:bucket => 'data.bin', :value => 1, :type => :gauge, :sample_rate => 1).should eq false
63
+ end
64
+
65
+ describe "multiple stats in a single call" do
66
+
67
+ it "collects stats together with delimeter" do
68
+ Fozzie.c.disable_prefix
69
+
70
+ stats = [
71
+ { :bucket => 'foo', :value => 1, :type => :count, :sample_rate => 1 },
72
+ { :bucket => 'bar', :value => 1, :type => :gauge, :sample_rate => 1 },
73
+ { :bucket => %w{foo bar}, :value => 100, :type => :timing, :sample_rate => 1 }
74
+ ]
75
+
76
+ subject.should_receive(:send_to_socket).with "foo:1|c\nbar:1|g\nfoo.bar:100|ms"
77
+
78
+ subject.register(stats)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -1,125 +1,125 @@
1
- require 'spec_helper'
2
- require 'resolv'
3
-
4
- describe Fozzie::Configuration do
5
- it "#host" do
6
- subject.host.should be_kind_of(String)
7
- end
8
-
9
- it "#port" do
10
- subject.port.should be_kind_of(Fixnum)
11
- end
12
-
13
- it "attempts to load configuration from yaml" do
14
- c = Fozzie::Configuration.new({
15
- env: 'test',
16
- config_path: 'spec/',
17
- adapter: :TestAdapter
18
- })
19
- c.stub(:origin_name => "")
20
- c.host.should eq '1.1.1.1'
21
- c.port.should eq 9876
22
- c.appname.should eq 'fozzie'
23
- c.data_prefix.should eq "fozzie#{c.safe_separator}test"
24
- end
25
-
26
- it "defaults env" do
27
- subject.env.should eq 'test'
28
- end
29
-
30
- describe "#adapter" do
31
- it "throw error on incorrect assignment" do
32
- -> { Fozzie::Configuration.new({:env => 'test', :adapter => 'foo'}) }.should raise_error(Fozzie::AdapterMissing)
33
- end
34
-
35
- it "defaults adapter to Statsd" do
36
- subject.adapter.should be_kind_of(Fozzie::Adapter::Statsd)
37
- end
38
- end
39
-
40
- describe "#disable_prefix" do
41
- it "sets the data_prefix to nil" do
42
- subject.disable_prefix
43
- subject.data_prefix.should be_nil
44
- end
45
- end
46
-
47
- describe "#prefix and #data_prefix" do
48
- it "creates a #data_prefix" do
49
- subject.stub(:origin_name => "")
50
- subject.data_prefix.should eq 'test'
51
- end
52
-
53
- it "creates a #data_prefix with appname when set" do
54
- subject.stub(:origin_name => "")
55
- subject.appname = 'astoria'
56
- subject.data_prefix.should eq 'astoria.test'
57
- end
58
-
59
- it "creates a #data_prefix with origin" do
60
- subject.appname = 'astoria'
61
- subject.data_prefix.should match /^astoria\.(\S+)\.test$/
62
- end
63
-
64
- it "allows dynamic assignment of #prefix to derive #data_prefix" do
65
- subject.prefix = [:foo, :bar, :car]
66
- subject.data_prefix.should eq 'foo.bar.car'
67
- end
68
-
69
- it "allows dynamic injection of value to prefix" do
70
- subject.stub(:origin_name => "")
71
- subject.prefix << 'git-sha-1234'
72
- subject.data_prefix.should eq 'test.git-sha-1234'
73
- end
74
- end
75
-
76
- it "handles missing configuration namespace" do
77
- proc { Fozzie::Configuration.new({:env => 'blbala', :config_path => 'spec/'}) }.should_not raise_error
78
- end
79
-
80
- it "#namespaces" do
81
- subject.namespaces.should be_kind_of(Array)
82
- subject.namespaces.should include("Stats")
83
- subject.namespaces.should include("S")
84
- end
85
-
86
- describe "#sniff?" do
87
- it "defaults to false for testing" do
88
- subject.stub(:env => "test")
89
- subject.sniff?.should be_false
90
- end
91
-
92
- it "defaults true when in development" do
93
- subject.stub(:env => "development")
94
- subject.sniff?.should be_true
95
- end
96
-
97
- it "defaults true when in production" do
98
- subject.stub(:env => "production")
99
- subject.sniff?.should be_true
100
- end
101
- end
102
-
103
- describe "#sniff_envs allows configuration for #sniff?" do
104
- let!(:sniff_envs) { subject.stub(:sniff_envs => ['test']) }
105
-
106
- it "scopes to return false" do
107
- subject.stub(:env => "development")
108
- subject.sniff?.should be_false
109
- end
110
-
111
- it "scopes to return true" do
112
- subject.stub(:env => "test")
113
- subject.sniff?.should be_true
114
- end
115
-
116
- end
117
-
118
- describe "ignoring prefix" do
119
- it "does not use prefix when set to ignore" do
120
- subject.disable_prefix
121
- subject.ignore_prefix.should eq(true)
122
- end
123
- end
124
-
125
- end
1
+ require 'spec_helper'
2
+ require 'resolv'
3
+
4
+ describe Fozzie::Configuration do
5
+ it "#host" do
6
+ subject.host.should be_kind_of(String)
7
+ end
8
+
9
+ it "#port" do
10
+ subject.port.should be_kind_of(Fixnum)
11
+ end
12
+
13
+ it "attempts to load configuration from yaml" do
14
+ c = Fozzie::Configuration.new({
15
+ env: 'test',
16
+ config_path: 'spec/',
17
+ adapter: :TestAdapter
18
+ })
19
+ c.stub(:origin_name => "")
20
+ c.host.should eq '1.1.1.1'
21
+ c.port.should eq 9876
22
+ c.appname.should eq 'fozzie'
23
+ c.data_prefix.should eq "fozzie#{c.safe_separator}test"
24
+ end
25
+
26
+ it "defaults env" do
27
+ subject.env.should eq 'test'
28
+ end
29
+
30
+ describe "#adapter" do
31
+ it "throw error on incorrect assignment" do
32
+ -> { Fozzie::Configuration.new({:env => 'test', :adapter => 'foo'}) }.should raise_error(Fozzie::AdapterMissing)
33
+ end
34
+
35
+ it "defaults adapter to Statsd" do
36
+ subject.adapter.should be_kind_of(Fozzie::Adapter::Statsd)
37
+ end
38
+ end
39
+
40
+ describe "#disable_prefix" do
41
+ it "sets the data_prefix to nil" do
42
+ subject.disable_prefix
43
+ subject.data_prefix.should be_nil
44
+ end
45
+ end
46
+
47
+ describe "#prefix and #data_prefix" do
48
+ it "creates a #data_prefix" do
49
+ subject.stub(:origin_name => "")
50
+ subject.data_prefix.should eq 'test'
51
+ end
52
+
53
+ it "creates a #data_prefix with appname when set" do
54
+ subject.stub(:origin_name => "")
55
+ subject.appname = 'astoria'
56
+ subject.data_prefix.should eq 'astoria.test'
57
+ end
58
+
59
+ it "creates a #data_prefix with origin" do
60
+ subject.appname = 'astoria'
61
+ subject.data_prefix.should match /^astoria\.(\S+)\.test$/
62
+ end
63
+
64
+ it "allows dynamic assignment of #prefix to derive #data_prefix" do
65
+ subject.prefix = [:foo, :bar, :car]
66
+ subject.data_prefix.should eq 'foo.bar.car'
67
+ end
68
+
69
+ it "allows dynamic injection of value to prefix" do
70
+ subject.stub(:origin_name => "")
71
+ subject.prefix << 'git-sha-1234'
72
+ subject.data_prefix.should eq 'test.git-sha-1234'
73
+ end
74
+ end
75
+
76
+ it "handles missing configuration namespace" do
77
+ proc { Fozzie::Configuration.new({:env => 'blbala', :config_path => 'spec/'}) }.should_not raise_error
78
+ end
79
+
80
+ it "#namespaces" do
81
+ subject.namespaces.should be_kind_of(Array)
82
+ subject.namespaces.should include("Stats")
83
+ subject.namespaces.should include("S")
84
+ end
85
+
86
+ describe "#sniff?" do
87
+ it "defaults to false for testing" do
88
+ subject.stub(:env => "test")
89
+ subject.sniff?.should be false
90
+ end
91
+
92
+ it "defaults true when in development" do
93
+ subject.stub(:env => "development")
94
+ subject.sniff?.should be true
95
+ end
96
+
97
+ it "defaults true when in production" do
98
+ subject.stub(:env => "production")
99
+ subject.sniff?.should be true
100
+ end
101
+ end
102
+
103
+ describe "#sniff_envs allows configuration for #sniff?" do
104
+ let!(:sniff_envs) { subject.stub(:sniff_envs => ['test']) }
105
+
106
+ it "scopes to return false" do
107
+ subject.stub(:env => "development")
108
+ subject.sniff?.should be false
109
+ end
110
+
111
+ it "scopes to return true" do
112
+ subject.stub(:env => "test")
113
+ subject.sniff?.should be true
114
+ end
115
+
116
+ end
117
+
118
+ describe "ignoring prefix" do
119
+ it "does not use prefix when set to ignore" do
120
+ subject.disable_prefix
121
+ subject.ignore_prefix.should eq(true)
122
+ end
123
+ end
124
+
125
+ end