Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "(#12) Switch from Beefcake to Protobuf" #42

Merged
merged 1 commit into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/riemann.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
8 changes: 5 additions & 3 deletions lib/riemann/attribute.rb
Original file line number Diff line number Diff line change
@@ -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
40 changes: 20 additions & 20 deletions lib/riemann/event.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions lib/riemann/message.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/riemann/query.rb
Original file line number Diff line number Diff line change
@@ -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
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

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