ffwd-protobuf 0.1.6
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.
- checksums.yaml +15 -0
- data/lib/ffwd/plugin/protobuf/protocol.pb.rb +105 -0
- data/lib/ffwd/plugin/protobuf/version.rb +22 -0
- data/lib/ffwd/plugin/protobuf.rb +244 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTFmZTlmNTgzODA5NGQ3Yjc0Y2M0ZTE4OTFlNWI4ZTFlZWU1NzQyZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTM4MTYxMWI1MzgwY2Q5NDAxMzFjNGJkZTkzNTQ5NTAwY2JlODVkNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjBhZDYxZGZjN2ExY2IwZWY1NDFjODk1MDQwN2NlNjM5MmMyODYwY2IyYjk1
|
10
|
+
YjU4ZDU3NjY2ZTljMmQ0OTQ2NjJmYjY2MmM1OGJiY2Y4NWY1ZmNmNzViYWVh
|
11
|
+
NzQ2MzlmMjA1NDg4MDc4MDYzMWM3YTIwNzcwODc3MmY3MTk3ZTg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzU3MTY2Y2Q5MmNmMmUyYTA0Y2U4NWI4NzllMDIzMTRiOTgxNTRhYmM4OTBm
|
14
|
+
NWY0ZjZjM2FlMGU1NWFiNjI4MDkxYjZkMTk5ZjRmMTU0MmE4N2E4NGM3Mzhk
|
15
|
+
MWE4YjY3NTcwYTg0MjliYjgxMDJjMmQ3OTVjMWIwZjUxMThhMDM=
|
@@ -0,0 +1,105 @@
|
|
1
|
+
### Generated by rprotoc. DO NOT EDIT!
|
2
|
+
### <proto file: ./proto/protocol.proto>
|
3
|
+
# package FFWD.Plugin.Protobuf.Protocol;
|
4
|
+
#
|
5
|
+
# option java_package = "com.spotify.ffwd";
|
6
|
+
# option java_outer_classname = "Protocol";
|
7
|
+
#
|
8
|
+
# message Metric {
|
9
|
+
# // time in ms when metric was generated.
|
10
|
+
# optional int64 time = 1;
|
11
|
+
# // key of metric.
|
12
|
+
# optional string key = 2;
|
13
|
+
# // value of metric.
|
14
|
+
# optional double value = 3;
|
15
|
+
# // host where metric originated.
|
16
|
+
# optional string host = 4;
|
17
|
+
# // source metric of the metric.
|
18
|
+
# optional string source = 5;
|
19
|
+
# // tags associated to metric.
|
20
|
+
# repeated string tags = 6;
|
21
|
+
# // attributes associated to metric.
|
22
|
+
# repeated Attribute attributes = 7;
|
23
|
+
# }
|
24
|
+
#
|
25
|
+
# message Event {
|
26
|
+
# // time in ms when the event was generated.
|
27
|
+
# optional int64 time = 1;
|
28
|
+
# // key of event.
|
29
|
+
# optional string key = 2;
|
30
|
+
# // value of event.
|
31
|
+
# optional double value = 3;
|
32
|
+
# // host where event originated.
|
33
|
+
# optional string host = 4;
|
34
|
+
# // source event (if any).
|
35
|
+
# optional string source = 5;
|
36
|
+
# // indicated state of this event.
|
37
|
+
# optional string state = 6;
|
38
|
+
# // description of event.
|
39
|
+
# optional string description = 7;
|
40
|
+
# // time this event should be considered valid in seconds.
|
41
|
+
# optional int64 ttl = 8;
|
42
|
+
# // tags associated to event.
|
43
|
+
# repeated string tags = 9;
|
44
|
+
# // attributes associated to event.
|
45
|
+
# repeated Attribute attributes = 10;
|
46
|
+
# }
|
47
|
+
#
|
48
|
+
# message Attribute {
|
49
|
+
# required string key = 1;
|
50
|
+
# optional string value = 2;
|
51
|
+
# }
|
52
|
+
#
|
53
|
+
# message Message {
|
54
|
+
# optional Metric metric = 1;
|
55
|
+
# optional Event event = 2;
|
56
|
+
# }
|
57
|
+
|
58
|
+
require 'protobuf/message/message'
|
59
|
+
require 'protobuf/message/enum'
|
60
|
+
require 'protobuf/message/service'
|
61
|
+
require 'protobuf/message/extend'
|
62
|
+
|
63
|
+
module FFWD
|
64
|
+
module Plugin
|
65
|
+
module Protobuf
|
66
|
+
module Protocol
|
67
|
+
::Protobuf::OPTIONS[:"java_package"] = "com.spotify.ffwd"
|
68
|
+
::Protobuf::OPTIONS[:"java_outer_classname"] = "Protocol"
|
69
|
+
class Metric < ::Protobuf::Message
|
70
|
+
defined_in __FILE__
|
71
|
+
optional :int64, :time, 1
|
72
|
+
optional :string, :key, 2
|
73
|
+
optional :double, :value, 3
|
74
|
+
optional :string, :host, 4
|
75
|
+
optional :string, :source, 5
|
76
|
+
repeated :string, :tags, 6
|
77
|
+
repeated :Attribute, :attributes, 7
|
78
|
+
end
|
79
|
+
class Event < ::Protobuf::Message
|
80
|
+
defined_in __FILE__
|
81
|
+
optional :int64, :time, 1
|
82
|
+
optional :string, :key, 2
|
83
|
+
optional :double, :value, 3
|
84
|
+
optional :string, :host, 4
|
85
|
+
optional :string, :source, 5
|
86
|
+
optional :string, :state, 6
|
87
|
+
optional :string, :description, 7
|
88
|
+
optional :int64, :ttl, 8
|
89
|
+
repeated :string, :tags, 9
|
90
|
+
repeated :Attribute, :attributes, 10
|
91
|
+
end
|
92
|
+
class Attribute < ::Protobuf::Message
|
93
|
+
defined_in __FILE__
|
94
|
+
required :string, :key, 1
|
95
|
+
optional :string, :value, 2
|
96
|
+
end
|
97
|
+
class Message < ::Protobuf::Message
|
98
|
+
defined_in __FILE__
|
99
|
+
optional :Metric, :metric, 1
|
100
|
+
optional :Event, :event, 2
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# $LICENSE
|
2
|
+
# Copyright 2013-2014 Spotify AB. All rights reserved.
|
3
|
+
#
|
4
|
+
# The contents of this file are licensed under the Apache License, Version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
module FFWD
|
17
|
+
module Plugin
|
18
|
+
module Protobuf
|
19
|
+
VERSION = "0.1.6"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
# $LICENSE
|
2
|
+
# Copyright 2013-2014 Spotify AB. All rights reserved.
|
3
|
+
#
|
4
|
+
# The contents of this file are licensed under the Apache License, Version 2.0
|
5
|
+
# (the "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations under
|
14
|
+
# the License.
|
15
|
+
|
16
|
+
require 'eventmachine'
|
17
|
+
require 'em/protocols/frame_object_protocol'
|
18
|
+
|
19
|
+
require 'ffwd/connection'
|
20
|
+
require 'ffwd/handler'
|
21
|
+
require 'ffwd/logging'
|
22
|
+
require 'ffwd/plugin'
|
23
|
+
require 'ffwd/protocol'
|
24
|
+
require 'ffwd/event'
|
25
|
+
require 'ffwd/metric'
|
26
|
+
|
27
|
+
require_relative 'protobuf/protocol.pb'
|
28
|
+
|
29
|
+
module FFWD::Plugin::Protobuf
|
30
|
+
include FFWD::Plugin
|
31
|
+
include FFWD::Logging
|
32
|
+
|
33
|
+
P = ::FFWD::Plugin::Protobuf::Protocol
|
34
|
+
|
35
|
+
register_plugin "protobuf"
|
36
|
+
|
37
|
+
module Serializer
|
38
|
+
def self.dump m
|
39
|
+
m.serialize_to_string
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.load string
|
43
|
+
m = P::Message.new
|
44
|
+
m.parse_from_string string
|
45
|
+
return m
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Output < FFWD::Handler
|
50
|
+
include EM::Protocols::ObjectProtocol
|
51
|
+
include Serializer
|
52
|
+
|
53
|
+
def self.plugin_type
|
54
|
+
"protobuf_out"
|
55
|
+
end
|
56
|
+
|
57
|
+
def serializer
|
58
|
+
Serializer
|
59
|
+
end
|
60
|
+
|
61
|
+
def send_all events, metrics
|
62
|
+
events.each do |event|
|
63
|
+
send_event event
|
64
|
+
end
|
65
|
+
|
66
|
+
metrics.each do |metric|
|
67
|
+
send_metric metric
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def send_event event
|
72
|
+
message = P::Message.new
|
73
|
+
e = P::Event.new
|
74
|
+
e.time = (event.time.to_f * 1000).to_i if event.time
|
75
|
+
e.key = event.key if event.key
|
76
|
+
e.value = to_value event.value if event.value
|
77
|
+
e.host = event.host if event.host
|
78
|
+
e.source = event.source if event.source
|
79
|
+
e.state = event.state if event.state
|
80
|
+
e.description = event.description if event.description
|
81
|
+
e.ttl = event.ttl if event.ttl
|
82
|
+
e.tags = to_tags event.tags if event.tags
|
83
|
+
e.attributes = to_attributes event.attributes if event.attributes
|
84
|
+
message.event = e
|
85
|
+
send_object message
|
86
|
+
end
|
87
|
+
|
88
|
+
def send_metric metric
|
89
|
+
message = P::Message.new
|
90
|
+
m = P::Metric.new
|
91
|
+
m.time = (metric.time.to_f * 1000).to_i if metric.time
|
92
|
+
m.key = metric.key if metric.key
|
93
|
+
m.value = to_value metric.value if metric.value
|
94
|
+
m.host = metric.host if metric.host
|
95
|
+
m.source = metric.source if metric.source
|
96
|
+
m.tags = to_tags metric.tags if metric.tags
|
97
|
+
m.attributes = to_attributes metric.attributes if metric.attributes
|
98
|
+
message.metric = m
|
99
|
+
send_object message
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def to_value value
|
105
|
+
v = P::Value.new
|
106
|
+
v.value_d = value
|
107
|
+
return v
|
108
|
+
end
|
109
|
+
|
110
|
+
def to_attributes attributes
|
111
|
+
attributes.map do |key, value|
|
112
|
+
P::Attribute.new(:key => key, :value => value)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_tags tags
|
117
|
+
Array.new tags
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class Input < FFWD::Connection
|
122
|
+
include FFWD::Logging
|
123
|
+
include EM::Protocols::FrameObjectProtocol
|
124
|
+
|
125
|
+
def initialize bind, core, log
|
126
|
+
@bind = bind
|
127
|
+
@core = core
|
128
|
+
@log = log
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.plugin_type
|
132
|
+
"protobuf_in"
|
133
|
+
end
|
134
|
+
|
135
|
+
def serializer
|
136
|
+
Serializer
|
137
|
+
end
|
138
|
+
|
139
|
+
def receive_object message
|
140
|
+
if message.has_field?(:event)
|
141
|
+
receive_event message.event
|
142
|
+
end
|
143
|
+
|
144
|
+
if message.has_field?(:metric)
|
145
|
+
receive_metric message.metric
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def handle_exception datagram, e
|
150
|
+
@log.error("Failed to decode protobuf object", e)
|
151
|
+
if @log.debug?
|
152
|
+
@log.debug("FRAME: " + FFWD.dump2hex(datagram))
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def receive_event e
|
157
|
+
d = {}
|
158
|
+
d[:time] = Time.at(e.time.to_f / 1000) if e.has_field?(:time)
|
159
|
+
d[:key] = e.key if e.has_field?(:key)
|
160
|
+
d[:value] = e.value if e.has_field?(:value)
|
161
|
+
d[:host] = e.host if e.has_field?(:host)
|
162
|
+
d[:source] = e.source if e.has_field?(:source)
|
163
|
+
d[:state] = e.state if e.has_field?(:state)
|
164
|
+
d[:description] = e.description if e.has_field?(:description)
|
165
|
+
d[:ttl] = e.ttl if e.has_field?(:ttl)
|
166
|
+
d[:tags] = from_tags m.tags if m.tags
|
167
|
+
d[:attributes] = from_attributes m.attributes if m.attributes
|
168
|
+
@core.input.event d
|
169
|
+
@bind.increment :received_events
|
170
|
+
rescue => e
|
171
|
+
@log.error "Failed to receive event", e
|
172
|
+
@bind.increment :failed_events
|
173
|
+
end
|
174
|
+
|
175
|
+
def receive_metric m
|
176
|
+
d = {}
|
177
|
+
d[:time] = Time.at(m.time.to_f / 1000) if m.has_field?(:time)
|
178
|
+
d[:key] = m.key if m.has_field?(:key)
|
179
|
+
d[:value] = m.value if m.has_field?(:value)
|
180
|
+
d[:host] = m.host if m.has_field?(:host)
|
181
|
+
d[:source] = m.source if m.has_field?(:source)
|
182
|
+
d[:tags] = from_tags m.tags if m.tags
|
183
|
+
d[:attributes] = from_attributes m.attributes if m.attributes
|
184
|
+
@core.input.metric d
|
185
|
+
@bind.increment :received_metrics
|
186
|
+
rescue => e
|
187
|
+
@log.error "Failed to receive event", e
|
188
|
+
@bind.increment :failed_metrics
|
189
|
+
end
|
190
|
+
|
191
|
+
private
|
192
|
+
|
193
|
+
def from_attributes attributes
|
194
|
+
Hash[attributes.map{|a| [a.key, a.value]}]
|
195
|
+
end
|
196
|
+
|
197
|
+
def from_tags tags
|
198
|
+
Array.new tags
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
DEFAULT_HOST = "localhost"
|
203
|
+
DEFAULT_PORT = 19091
|
204
|
+
DEFAULT_PROTOCOL = 'udp'
|
205
|
+
|
206
|
+
OUTPUTS = {:udp => Output}
|
207
|
+
INPUTS = {:udp => Input}
|
208
|
+
|
209
|
+
def self.setup_output opts, core
|
210
|
+
opts[:host] ||= DEFAULT_HOST
|
211
|
+
opts[:port] ||= DEFAULT_PORT
|
212
|
+
|
213
|
+
protocol = FFWD.parse_protocol(opts[:protocol] || DEFAULT_PROTOCOL)
|
214
|
+
|
215
|
+
unless type = OUTPUTS[protocol.family]
|
216
|
+
raise "No type for protocol family: #{protocol.family}"
|
217
|
+
end
|
218
|
+
|
219
|
+
protocol.connect opts, core, log, type
|
220
|
+
end
|
221
|
+
|
222
|
+
def self.setup_input opts, core
|
223
|
+
opts[:host] ||= DEFAULT_HOST
|
224
|
+
opts[:port] ||= DEFAULT_PORT
|
225
|
+
protocol = FFWD.parse_protocol(opts[:protocol] || DEFAULT_PROTOCOL)
|
226
|
+
|
227
|
+
unless connection = INPUTS[protocol.family]
|
228
|
+
raise "No connection for protocol family: #{protocol.family}"
|
229
|
+
end
|
230
|
+
|
231
|
+
protocol.bind opts, core, log, connection, log
|
232
|
+
end
|
233
|
+
|
234
|
+
def self.setup_tunnel opts, core, tunnel
|
235
|
+
opts[:port] ||= DEFAULT_PORT
|
236
|
+
protocol = FFWD.parse_protocol(opts[:protocol] || DEFAULT_PROTOCOL)
|
237
|
+
|
238
|
+
unless connection = INPUTS[protocol.family]
|
239
|
+
raise "No connection for protocol family: #{protocol.family}"
|
240
|
+
end
|
241
|
+
|
242
|
+
protocol.tunnel opts, core, tunnel, log, connection, log
|
243
|
+
end
|
244
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ffwd-protobuf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John-John Tedro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby_protobuf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ffwd
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-mocks
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- udoprog@spotify.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/ffwd/plugin/protobuf.rb
|
77
|
+
- lib/ffwd/plugin/protobuf/version.rb
|
78
|
+
- lib/ffwd/plugin/protobuf/protocol.pb.rb
|
79
|
+
homepage: https://github.com/spotify/ffwd
|
80
|
+
licenses:
|
81
|
+
- Apache 2.0
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.0.3
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: protobuf reference protocol support for FFWD.
|
103
|
+
test_files: []
|