tabs 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tabs/tabs.rb +12 -8
- data/lib/tabs/version.rb +1 -1
- data/spec/lib/tabs_spec.rb +11 -7
- metadata +1 -1
data/lib/tabs/tabs.rb
CHANGED
@@ -19,20 +19,18 @@ module Tabs
|
|
19
19
|
Config.redis
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
24
|
-
raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter"
|
25
|
-
get_metric(key).increment
|
22
|
+
def config
|
23
|
+
Config
|
26
24
|
end
|
27
25
|
|
28
|
-
def
|
29
|
-
|
26
|
+
def increment_counter(key)
|
27
|
+
create_metric(key, "counter") unless metric_exists?(key)
|
30
28
|
raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter"
|
31
|
-
get_metric(key).
|
29
|
+
get_metric(key).increment
|
32
30
|
end
|
33
31
|
|
34
32
|
def record_value(key, value)
|
35
|
-
|
33
|
+
create_metric(key, "value") unless metric_exists?(key)
|
36
34
|
raise MetricTypeMismatchError.new("Only value metrics can record a value") unless metric_type(key) == "value"
|
37
35
|
get_metric(key).record(value)
|
38
36
|
end
|
@@ -51,6 +49,12 @@ module Tabs
|
|
51
49
|
metric_klass(type).new(key)
|
52
50
|
end
|
53
51
|
|
52
|
+
def counter_total(key, period=nil)
|
53
|
+
raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key)
|
54
|
+
raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter"
|
55
|
+
get_metric(key).total
|
56
|
+
end
|
57
|
+
|
54
58
|
def get_stats(key, period, resolution)
|
55
59
|
raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key)
|
56
60
|
metric = get_metric(key)
|
data/lib/tabs/version.rb
CHANGED
data/spec/lib/tabs_spec.rb
CHANGED
@@ -87,15 +87,17 @@ describe Tabs do
|
|
87
87
|
|
88
88
|
describe "#increment_counter" do
|
89
89
|
|
90
|
-
it "raises an Tabs::UnknownMetricError if the metric does not exist" do
|
91
|
-
lambda { Tabs.increment_counter("foo") }.should raise_error(Tabs::UnknownMetricError)
|
92
|
-
end
|
93
|
-
|
94
90
|
it "raises a Tabs::MetricTypeMismatchError if the metric is the wrong type" do
|
95
91
|
Tabs.create_metric("foo", "value")
|
96
92
|
lambda { Tabs.increment_counter("foo") }.should raise_error(Tabs::MetricTypeMismatchError)
|
97
93
|
end
|
98
94
|
|
95
|
+
it "creates the metric if it doesn't exist" do
|
96
|
+
expect(Tabs.metric_exists?("foo")).to be_false
|
97
|
+
lambda { Tabs.increment_counter("foo") }.should_not raise_error
|
98
|
+
expect(Tabs.metric_exists?("foo")).to be_true
|
99
|
+
end
|
100
|
+
|
99
101
|
it "calls increment on the metric" do
|
100
102
|
metric = Tabs.create_metric("foo", "counter")
|
101
103
|
Tabs.stub(get_metric: metric)
|
@@ -105,10 +107,12 @@ describe Tabs do
|
|
105
107
|
|
106
108
|
end
|
107
109
|
|
108
|
-
describe "#
|
110
|
+
describe "#record_value" do
|
109
111
|
|
110
|
-
it "
|
111
|
-
|
112
|
+
it "creates the metric if it doesn't exist" do
|
113
|
+
expect(Tabs.metric_exists?("foo")).to be_false
|
114
|
+
lambda { Tabs.record_value("foo", 38) }.should_not raise_error
|
115
|
+
expect(Tabs.metric_exists?("foo")).to be_true
|
112
116
|
end
|
113
117
|
|
114
118
|
it "raises a Tabs::MetricTypeMismatchError if the metric is the wrong type" do
|