metricsd 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.3 (July 27, 2011)
2
+
3
+ Features:
4
+
5
+ - Added ability to specify default group
6
+
1
7
  ## 0.2.2 (July 27, 2011)
2
8
 
3
9
  Bugfixes:
@@ -224,7 +224,8 @@ module Metricsd
224
224
  # Packs metric into a string representation according to the MetricsD
225
225
  # protocol.
226
226
  def pack(key, value, opts)
227
- key = "#{opts[:group]}$#{key}" unless opts[:group].nil? || opts[:group].empty?
227
+ group = opts[:group] || Metricsd.default_group || ''
228
+ key = "#{group}$#{key}" unless group.empty?
228
229
  opts[:source].empty? ? "#{key}:#{value}" : "#{opts[:source]}@#{key}:#{value}"
229
230
  end
230
231
  end
@@ -1,3 +1,3 @@
1
1
  module Metricsd
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/metricsd.rb CHANGED
@@ -72,6 +72,16 @@ module Metricsd
72
72
  @@default_source = source
73
73
  end
74
74
 
75
+ # Gets the default group for all metrics.
76
+ def default_group
77
+ @@default_group
78
+ end
79
+
80
+ # Sets the default group for all metrics.
81
+ def default_group=(group)
82
+ @@default_group = group
83
+ end
84
+
75
85
  # Gets the logger used to output errors or warnings.
76
86
  def logger
77
87
  @@logger ||= if defined?(Rails)
@@ -95,6 +105,7 @@ module Metricsd
95
105
  @@enabled = true
96
106
  @@source = Socket.gethostname[/^([^.]+)/, 1]
97
107
  @@default_source = 'all'
108
+ @@default_group = nil
98
109
  @@logger = nil
99
110
  end
100
111
  end
data/spec/client_spec.rb CHANGED
@@ -184,6 +184,24 @@ describe Metricsd::Client do
184
184
  @socket.should_receive(:send).with('test2@custom.metric:23', 0)
185
185
  Metricsd::Client.record_value('custom.metric', 23, :source => 'test2')
186
186
  end
187
+
188
+ it 'should apply default group if specified' do
189
+ Metricsd.default_group = 'grp'
190
+ @socket.should_receive(:send).with('all@grp$custom.metric:23', 0)
191
+ Metricsd::Client.record_value('custom.metric', 23)
192
+ end
193
+
194
+ it 'should override default group with the specified one' do
195
+ Metricsd.default_group = 'grp'
196
+ @socket.should_receive(:send).with('all@group$custom.metric:23', 0)
197
+ Metricsd::Client.record_value('custom.metric', 23, :group => 'group')
198
+ end
199
+
200
+ it 'should clear group, if there is a default one, and empty string specified' do
201
+ Metricsd.default_group = 'grp'
202
+ @socket.should_receive(:send).with('all@custom.metric:23', 0)
203
+ Metricsd::Client.record_value('custom.metric', 23, :group => '')
204
+ end
187
205
  end
188
206
 
189
207
  describe '.record_values' do
@@ -25,6 +25,10 @@ describe Metricsd do
25
25
  Metricsd.default_source.should == 'all'
26
26
  end
27
27
 
28
+ it 'should have default_group = nil' do
29
+ Metricsd.default_group.should be_nil
30
+ end
31
+
28
32
  it 'should create logger' do
29
33
  Metricsd.logger.should be_a(Logger)
30
34
  end
@@ -76,6 +80,11 @@ describe Metricsd do
76
80
  Metricsd.default_source.should == 'nothing'
77
81
  end
78
82
 
83
+ it 'should allow to change default_group' do
84
+ Metricsd.default_group = 'mygroup'
85
+ Metricsd.default_group.should == 'mygroup'
86
+ end
87
+
79
88
  it 'should allow to change logger' do
80
89
  mock = Metricsd.logger = mock('Logger')
81
90
  Metricsd.logger.should be(mock)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metricsd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmytro Shteflyuk