weatherman 0.0.2 → 0.0.3

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.
@@ -23,10 +23,7 @@ module Weatherman
23
23
 
24
24
  def run
25
25
  @thread ||= Thread.new do
26
- while true
27
- report
28
- sleep @period
29
- end
26
+ broadcast sample_metric while sleep @period
30
27
  end
31
28
  end
32
29
 
@@ -39,16 +36,20 @@ module Weatherman
39
36
  !@thread.nil?
40
37
  end
41
38
 
42
- def report
43
- value = @collector.call
44
-
45
- cloud_watch.put_metric_data @namespace, [{
46
- 'MetricName' => @name,
47
- 'Value' => value,
48
- 'Dimensions' => @dimensions.map { |k, v| { k.to_s => v } }
49
- }]
39
+ def sample_metric
40
+ @collector.call
41
+ end
50
42
 
51
- value
43
+ def broadcast(value)
44
+ begin
45
+ cloud_watch.put_metric_data @namespace, [{
46
+ 'MetricName' => @name,
47
+ 'Value' => value,
48
+ 'Dimensions' => @dimensions.map { |k, v| { k.to_s => v } }
49
+ }]
50
+ rescue
51
+ #TODO: Add loggging here, and throughout the gem
52
+ end
52
53
  end
53
54
 
54
55
  end
@@ -1,3 +1,3 @@
1
1
  module Weatherman
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/spec/report_spec.rb CHANGED
@@ -39,7 +39,7 @@ module Weatherman
39
39
 
40
40
  report.run
41
41
 
42
- sleep 2
42
+ sleep 3
43
43
  calls.length.should >= 2
44
44
  end
45
45
 
@@ -91,36 +91,44 @@ module Weatherman
91
91
  end
92
92
  end
93
93
 
94
- describe 'report' do
94
+ describe 'sample_metric' do
95
95
  it 'should collect the metric' do
96
- @report.report.should == @metric_value
96
+ called = false
97
+ report = Report.new @metric_name do
98
+ called = true
99
+ @metric_value
100
+ end
101
+
102
+ result = report.sample_metric
103
+
104
+ result.should == @metric_value
105
+ called.should == true
97
106
  end
107
+ end
98
108
 
99
- it 'should report the metric' do
109
+ describe 'broadcast' do
110
+ it 'should send the metric to CloudWatch' do
100
111
  @report.cloud_watch.should_receive(:put_metric_data) do |namespace, metrics|
101
112
  namespace.should == @namespace
102
113
 
103
114
  metrics.length.should == 1
104
115
  metric = metrics.first
105
116
 
117
+ metric['Value'].should == @metric_value
106
118
  metric['MetricName'].should == @metric_name
107
119
  end
108
120
 
109
- @report.report
121
+ @report.broadcast @metric_value
110
122
  end
111
123
 
112
124
  it 'should include the instance ID as a default dimension' do
113
125
  @report.cloud_watch.should_receive(:put_metric_data) do |namespace, metrics|
114
- metrics.length.should == 1
115
-
116
- metric = metrics.first
117
- dimensions = metric['Dimensions']
118
-
126
+ dimensions = metrics.first['Dimensions']
119
127
  dimensions.length.should == 1
120
128
  dimensions.first['InstanceId'].should == @instance_id
121
129
  end
122
130
 
123
- @report.report
131
+ @report.broadcast @metric_value
124
132
  end
125
133
 
126
134
  it 'should include user-defined dimensions plus the instance ID' do
@@ -133,11 +141,7 @@ module Weatherman
133
141
  end
134
142
 
135
143
  report.cloud_watch.should_receive(:put_metric_data) do |namespace, metrics|
136
- metrics.length.should == 1
137
-
138
- metric = metrics.first
139
- dimensions = metric['Dimensions']
140
-
144
+ dimensions = metrics.first['Dimensions']
141
145
  dimensions.length.should == 3
142
146
 
143
147
  user_dimensions['InstanceId'] = @instance_id
@@ -149,7 +153,21 @@ module Weatherman
149
153
  end
150
154
  end
151
155
 
152
- report.report
156
+ report.broadcast @metric_value
157
+ end
158
+
159
+ it "should not kill a running report's thread if there is an error" do
160
+ report = Report.new @metric_name, :period => 1 do
161
+ @metric_value
162
+ end
163
+
164
+ report.cloud_watch.should_receive(:put_metric_data).and_raise('some error')
165
+
166
+ report.run
167
+ thread_count = Thread.list.length
168
+
169
+ sleep 1.1
170
+ Thread.list.length.should == thread_count
153
171
  end
154
172
  end
155
173
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weatherman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Marion