riemann-client 0.2.0 → 0.2.1

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.
data/lib/riemann/event.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Riemann
2
2
  class Event
3
+ require 'set'
3
4
  include Beefcake::Message
4
5
 
5
6
  optional :time, :int64, 1
@@ -15,6 +16,17 @@ module Riemann
15
16
  optional :metric_d, :double, 14
16
17
  optional :metric_f, :float, 15
17
18
 
19
+ # Fields which don't really exist in protobufs, but which are reserved
20
+ # and can't be used as attributes.
21
+ VIRTUAL_FIELDS = Set.new([:metric])
22
+ # Fields which are specially encoded in the Event protobuf--that is, they
23
+ # can't be used as attributes.
24
+ RESERVED_FIELDS = fields.map do |i, field|
25
+ field.name.to_sym
26
+ end.reduce(VIRTUAL_FIELDS) do |set, field|
27
+ set << field
28
+ end
29
+
18
30
  # Average a set of states together. Chooses the mean metric, the mode
19
31
  # state, mode service, and the mean time. If init is provided, its values
20
32
  # override (where present) the computed ones.
@@ -162,10 +174,14 @@ module Riemann
162
174
  super hash
163
175
  end
164
176
 
165
- # Add extra attributes to the event as Attribute instances with values converted to String
166
- keys = hash.keys.map {|k| k.to_sym } - self.fields.values.map {|f| f.name.to_sym }
167
- self.attributes = keys.map {|key| Attribute.new(:key => key.to_s, :value => (hash[key] || hash[key.to_sym]).to_s) }
168
-
177
+ # Add extra attributes to the event as Attribute instances with values
178
+ # converted to String
179
+ self.attributes = hash.map do |key, value|
180
+ unless RESERVED_FIELDS.include? key.to_sym
181
+ Attribute.new(:key => key.to_s,
182
+ :value => (hash[key] || hash[key.to_sym]).to_s)
183
+ end
184
+ end.compact
169
185
  else
170
186
  super()
171
187
  end
@@ -192,20 +208,19 @@ module Riemann
192
208
 
193
209
  # Look up attributes
194
210
  def [](k)
195
- if(respond_to? k)
211
+ if RESERVED_FIELDS.include? k.to_sym
196
212
  super
197
213
  else
198
- r = attributes.select {|a| a.key.to_sym == k.to_sym }.map {|a| a.value}
199
- r.size > 1 ? r : r.first
214
+ r = attributes.find {|a| a.key.to_s == k.to_s }.value
200
215
  end
201
216
  end
202
217
 
203
218
  # Set attributes
204
219
  def []=(k, v)
205
- if(respond_to?("#{k}="))
220
+ if RESERVED_FIELDS.include? k.to_sym
206
221
  super
207
222
  else
208
- a = self.attributes.select {|a| a.key.to_sym == k.to_sym }.first
223
+ a = self.attributes.find {|a| a.key == k.to_s }
209
224
  if(a)
210
225
  a.value = v.to_s
211
226
  else
@@ -213,7 +228,5 @@ module Riemann
213
228
  end
214
229
  end
215
230
  end
216
-
217
231
  end
218
-
219
232
  end
@@ -1,3 +1,3 @@
1
1
  module Riemann
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -75,7 +75,6 @@ files:
75
75
  - lib/riemann/message.rb
76
76
  - lib/riemann/metric_thread.rb
77
77
  - lib/riemann/query.rb
78
- - lib/riemann/repl-port
79
78
  - lib/riemann/state.rb
80
79
  - lib/riemann/version.rb
81
80
  - LICENSE
@@ -1 +0,0 @@
1
- 56061