diff --git a/lib/riemann.rb b/lib/riemann.rb index 9b00d52..1cb676e 100644 --- a/lib/riemann.rb +++ b/lib/riemann.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true module Riemann + require 'rubygems' + require 'beefcake' + require 'timeout' require 'riemann/version' require 'riemann/state' require 'riemann/attribute' diff --git a/lib/riemann/attribute.rb b/lib/riemann/attribute.rb index eabd02e..acd4d39 100644 --- a/lib/riemann/attribute.rb +++ b/lib/riemann/attribute.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true module Riemann - class Attribute < Protobuf::Message - required :string, :key, 1 - optional :string, :value, 2 + class Attribute + include Beefcake::Message + + required :key, :string, 1 + optional :value, :string, 2 end end diff --git a/lib/riemann/event.rb b/lib/riemann/event.rb index 9ae7453..e735200 100644 --- a/lib/riemann/event.rb +++ b/lib/riemann/event.rb @@ -1,29 +1,30 @@ # frozen_string_literal: true module Riemann - class Event < Protobuf::Message + class Event require 'set' - - optional :int64, :time, 1 - optional :string, :state, 2 - optional :string, :service, 3 - optional :string, :host, 4 - optional :string, :description, 5 - repeated :string, :tags, 7 - optional :float, :ttl, 8 - repeated Attribute, :attributes, 9 - optional :int64, :time_micros, 10 - - optional :sint64, :metric_sint64, 13 - optional :double, :metric_d, 14 - optional :float, :metric_f, 15 + include Beefcake::Message + + optional :time, :int64, 1 + optional :state, :string, 2 + optional :service, :string, 3 + optional :host, :string, 4 + optional :description, :string, 5 + repeated :tags, :string, 7 + optional :ttl, :float, 8 + repeated :attributes, Attribute, 9 + optional :time_micros, :int64, 10 + + optional :metric_sint64, :sint64, 13 + optional :metric_d, :double, 14 + optional :metric_f, :float, 15 # Fields which don't really exist in protobufs, but which are reserved # and can't be used as attributes. VIRTUAL_FIELDS = Set.new([:metric]) # Fields which are specially encoded in the Event protobuf--that is, they # can't be used as attributes. - RESERVED_FIELDS = fields.map do |field| + RESERVED_FIELDS = fields.map do |_i, field| field.name.to_sym end.reduce(VIRTUAL_FIELDS) do |set, field| # rubocop:disable Style/MultilineBlockChain set << field @@ -189,10 +190,9 @@ def initialize(hash = nil) end def metric - return metric_d if field?(:metric_d) - return metric_sint64 if field?(:metric_sint64) - - metric_f + metric_d || + metric_sint64 || + metric_f end def metric=(value) diff --git a/lib/riemann/message.rb b/lib/riemann/message.rb index 610302c..372ad08 100644 --- a/lib/riemann/message.rb +++ b/lib/riemann/message.rb @@ -1,12 +1,14 @@ # frozen_string_literal: true module Riemann - class Message < Protobuf::Message - optional :bool, :ok, 2 - optional :string, :error, 3 - repeated State, :states, 4 - optional Query, :query, 5 - repeated Event, :events, 6 + class Message + include Beefcake::Message + + optional :ok, :bool, 2 + optional :error, :string, 3 + repeated :states, State, 4 + optional :query, Query, 5 + repeated :events, Event, 6 def encode_with_length encoded_string = encode.to_s diff --git a/lib/riemann/query.rb b/lib/riemann/query.rb index 546a43a..aaef526 100644 --- a/lib/riemann/query.rb +++ b/lib/riemann/query.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true module Riemann - class Query < Protobuf::Message + class Query + include Beefcake::Message + optional :string, :string, 1 end end diff --git a/lib/riemann/state.rb b/lib/riemann/state.rb index 6bad8dd..948c9bb 100644 --- a/lib/riemann/state.rb +++ b/lib/riemann/state.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require 'protobuf' - module Riemann - class State < Protobuf::Message - optional :int64, :time, 1 - optional :string, :state, 2 - optional :string, :service, 3 - optional :string, :host, 4 - optional :string, :description, 5 - optional :bool, :once, 6 - repeated :string, :tags, 7 - optional :float, :ttl, 8 - optional :float, :metric_f, 15 + class State + include Beefcake::Message + + optional :time, :int64, 1 + optional :state, :string, 2 + optional :service, :string, 3 + optional :host, :string, 4 + optional :description, :string, 5 + optional :once, :bool, 6 + repeated :tags, :string, 7 + optional :ttl, :float, 8 + optional :metric_f, :float, 15 def initialize super diff --git a/riemann-client.gemspec b/riemann-client.gemspec index fd089d5..5917caf 100644 --- a/riemann-client.gemspec +++ b/riemann-client.gemspec @@ -29,6 +29,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rubocop' spec.add_development_dependency 'timecop' + spec.add_dependency 'beefcake', ['>= 1.0.0 '] spec.add_dependency 'mtrc', '>= 0.0.4' - spec.add_dependency 'protobuf', '~> 3.0' end