Skip to content

Commit

Permalink
Merge pull request #39 from riemann/protobuf
Browse files Browse the repository at this point in the history
(#12) Switch from Beefcake to Protobuf
  • Loading branch information
jamtur01 authored Jun 25, 2022
2 parents c619a99 + 5ab5de4 commit ce2a46d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 52 deletions.
3 changes: 0 additions & 3 deletions lib/riemann.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# frozen_string_literal: true

module Riemann
require 'rubygems'
require 'beefcake'
require 'timeout'
require 'riemann/version'
require 'riemann/state'
require 'riemann/attribute'
Expand Down
8 changes: 3 additions & 5 deletions lib/riemann/attribute.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# frozen_string_literal: true

module Riemann
class Attribute
include Beefcake::Message

required :key, :string, 1
optional :value, :string, 2
class Attribute < Protobuf::Message
required :string, :key, 1
optional :string, :value, 2
end
end
40 changes: 20 additions & 20 deletions lib/riemann/event.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
# frozen_string_literal: true

module Riemann
class Event
class Event < Protobuf::Message
require 'set'
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

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

# 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 |_i, field|
RESERVED_FIELDS = fields.map do |field|
field.name.to_sym
end.reduce(VIRTUAL_FIELDS) do |set, field| # rubocop:disable Style/MultilineBlockChain
set << field
Expand Down Expand Up @@ -190,9 +189,10 @@ def initialize(hash = nil)
end

def metric
metric_d ||
metric_sint64 ||
metric_f
return metric_d if field?(:metric_d)
return metric_sint64 if field?(:metric_sint64)

metric_f
end

def metric=(value)
Expand Down
14 changes: 6 additions & 8 deletions lib/riemann/message.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# frozen_string_literal: true

module Riemann
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
class Message < Protobuf::Message
optional :bool, :ok, 2
optional :string, :error, 3
repeated State, :states, 4
optional Query, :query, 5
repeated Event, :events, 6

def encode_with_length
encoded_string = encode.to_s
Expand Down
4 changes: 1 addition & 3 deletions lib/riemann/query.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

module Riemann
class Query
include Beefcake::Message

class Query < Protobuf::Message
optional :string, :string, 1
end
end
24 changes: 12 additions & 12 deletions lib/riemann/state.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

module Riemann
class State
include Beefcake::Message
require 'protobuf'

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
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

def initialize
super
Expand Down
2 changes: 1 addition & 1 deletion riemann-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ce2a46d

Please sign in to comment.