ffwd-protobuf 0.1.7 → 0.2.0
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 +7 -0
- data/lib/ffwd/plugin/protobuf/serializer/protocol0.rb +29 -47
- data/lib/ffwd/plugin/protobuf/version.rb +1 -1
- data/lib/ffwd/plugin/protobuf.rb +23 -28
- data/lib/ffwd/protocol0.pb.rb +47 -85
- metadata +20 -30
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 84b35690dd6945a213fe79d32afb2dea240912fc
|
4
|
+
data.tar.gz: dd4a200177efac7375d734e9a3d926f3c59ce291
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb76a0e1314cf2165024788c7a1ed4bedc753e21e7fe3011039a244ba045087a1cf965f2bf995d4c2d0947d2be797e57d4ee5f7882e603eac29193387cf903e8
|
7
|
+
data.tar.gz: bb96764eeaf676988049a13f5ffa0bf77cd24bf59acb48bcaab5654615d72406da89516a40d8597bba40ddbc364616965d95076e93282ef8b1702ff0d804a9f7
|
@@ -28,82 +28,64 @@ module FFWD::Plugin::Protobuf::Serializer
|
|
28
28
|
module Protocol0
|
29
29
|
P = ::FFWD::Protocol0
|
30
30
|
|
31
|
+
METRIC_FIELDS = [:key, :value, :host]
|
32
|
+
EVENT_FIELDS = [:key, :value, :host, :state, :description, :ttl]
|
33
|
+
|
31
34
|
def self.load string
|
32
|
-
message = P::Message.
|
33
|
-
message.parse_from_string string
|
35
|
+
message = P::Message.decode(string)
|
34
36
|
|
35
|
-
if message.
|
37
|
+
if message.event
|
36
38
|
yield :event, receive_event(message.event)
|
37
39
|
end
|
38
40
|
|
39
|
-
if message.
|
41
|
+
if message.metric
|
40
42
|
yield :metric, receive_metric(message.metric)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
|
-
def self.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
d
|
50
|
-
d[:
|
51
|
-
d[:
|
52
|
-
d[:
|
53
|
-
d[:tags] = from_tags e.tags if e.tags
|
54
|
-
d[:attributes] = from_attributes e.attributes if e.attributes
|
46
|
+
def self.map_fields fields, s
|
47
|
+
Hash[fields.map{|f| [f, s.send(f)]}.reject{|f, v| v.nil?}]
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.receive_event event
|
51
|
+
d = map_fields EVENT_FIELDS, event
|
52
|
+
d[:time] = Time.at(event.time.to_f / 1000) if event.time
|
53
|
+
d[:tags] = from_tags event.tags if event.tags
|
54
|
+
d[:attributes] = from_attributes event.attributes if event.attributes
|
55
55
|
return d
|
56
56
|
end
|
57
57
|
|
58
|
-
def self.receive_metric
|
59
|
-
d =
|
60
|
-
d[:proc] =
|
61
|
-
d[:time] = Time.at(
|
62
|
-
d[:
|
63
|
-
d[:
|
64
|
-
d[:host] = m.host if m.has_field?(:host)
|
65
|
-
d[:tags] = from_tags m.tags if m.tags
|
66
|
-
d[:attributes] = from_attributes m.attributes if m.attributes
|
58
|
+
def self.receive_metric metric
|
59
|
+
d = map_fields METRIC_FIELDS, metric
|
60
|
+
d[:proc] = metric.proc if metric.proc
|
61
|
+
d[:time] = Time.at(metric.time.to_f / 1000) if metric.time
|
62
|
+
d[:tags] = from_tags metric.tags if metric.tags
|
63
|
+
d[:attributes] = from_attributes metric.attributes if metric.attributes
|
67
64
|
return d
|
68
65
|
end
|
69
66
|
|
70
|
-
def self.from_attributes
|
71
|
-
Hash[
|
67
|
+
def self.from_attributes source
|
68
|
+
Hash[source.map{|a| [a.key, a.value]}]
|
72
69
|
end
|
73
70
|
|
74
|
-
def self.from_tags
|
75
|
-
Array.new
|
71
|
+
def self.from_tags source
|
72
|
+
Array.new source
|
76
73
|
end
|
77
74
|
|
78
75
|
def self.dump_event event
|
79
|
-
e = P::Event.new
|
76
|
+
e = P::Event.new map_fields(EVENT_FIELDS, event)
|
80
77
|
e.time = (event.time.to_f * 1000).to_i if event.time
|
81
|
-
e.key = event.key if event.key
|
82
|
-
e.value = event.value.to_f if event.value
|
83
|
-
e.host = event.host if event.host
|
84
|
-
e.state = event.state if event.state
|
85
|
-
e.description = event.description if event.description
|
86
|
-
e.ttl = event.ttl if event.ttl
|
87
78
|
e.tags = to_tags event.tags if event.tags
|
88
79
|
e.attributes = to_attributes event.attributes if event.attributes
|
89
|
-
|
90
|
-
message = P::Message.new
|
91
|
-
message.event = e
|
92
|
-
message.serialize_to_string
|
80
|
+
P::Message.new(:event => e).encode
|
93
81
|
end
|
94
82
|
|
95
83
|
def self.dump_metric metric
|
96
|
-
m = P::Metric.new
|
84
|
+
m = P::Metric.new map_fields(METRIC_FIELDS, metric)
|
97
85
|
m.time = (metric.time.to_f * 1000).to_i if metric.time
|
98
|
-
m.key = metric.key if metric.key
|
99
|
-
m.value = metric.value.to_f if metric.value
|
100
|
-
m.host = metric.host if metric.host
|
101
86
|
m.tags = to_tags metric.tags if metric.tags
|
102
87
|
m.attributes = to_attributes metric.attributes if metric.attributes
|
103
|
-
|
104
|
-
message = P::Message.new
|
105
|
-
message.metric = m
|
106
|
-
message.serialize_to_string
|
88
|
+
P::Message.new(:metric => m).encode
|
107
89
|
end
|
108
90
|
|
109
91
|
private
|
data/lib/ffwd/plugin/protobuf.rb
CHANGED
@@ -37,6 +37,10 @@ module FFWD::Plugin::Protobuf
|
|
37
37
|
"protobuf_udp_out"
|
38
38
|
end
|
39
39
|
|
40
|
+
def initialize connect, config
|
41
|
+
@connect = connect
|
42
|
+
end
|
43
|
+
|
40
44
|
def send_all events, metrics
|
41
45
|
events.each do |event|
|
42
46
|
send_event event
|
@@ -48,11 +52,11 @@ module FFWD::Plugin::Protobuf
|
|
48
52
|
end
|
49
53
|
|
50
54
|
def send_event event
|
51
|
-
|
55
|
+
@connect.send_data Serializer.dump_event(event)
|
52
56
|
end
|
53
57
|
|
54
58
|
def send_metric metric
|
55
|
-
|
59
|
+
@connect.send_data Serializer.dump_metric(metric)
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
@@ -60,10 +64,9 @@ module FFWD::Plugin::Protobuf
|
|
60
64
|
include FFWD::Logging
|
61
65
|
include EM::Protocols::FrameObjectProtocol
|
62
66
|
|
63
|
-
def initialize bind, core,
|
67
|
+
def initialize bind, core, config
|
64
68
|
@bind = bind
|
65
69
|
@core = core
|
66
|
-
@log = log
|
67
70
|
end
|
68
71
|
|
69
72
|
def self.plugin_type
|
@@ -85,10 +88,10 @@ module FFWD::Plugin::Protobuf
|
|
85
88
|
end
|
86
89
|
end
|
87
90
|
rescue => e
|
88
|
-
|
91
|
+
log.error "Failed to receive data", e
|
89
92
|
|
90
|
-
if
|
91
|
-
|
93
|
+
if log.debug?
|
94
|
+
log.debug("DUMP: " + FFWD.dump2hex(datagram))
|
92
95
|
end
|
93
96
|
end
|
94
97
|
end
|
@@ -100,39 +103,31 @@ module FFWD::Plugin::Protobuf
|
|
100
103
|
OUTPUTS = {:udp => OutputUDP}
|
101
104
|
INPUTS = {:udp => InputUDP}
|
102
105
|
|
103
|
-
def self.setup_output
|
104
|
-
|
105
|
-
|
106
|
+
def self.setup_output config
|
107
|
+
config[:host] ||= DEFAULT_HOST
|
108
|
+
config[:port] ||= DEFAULT_PORT
|
109
|
+
config[:protocol] ||= DEFAULT_PROTOCOL
|
106
110
|
|
107
|
-
protocol = FFWD.parse_protocol
|
111
|
+
protocol = FFWD.parse_protocol config[:protocol]
|
108
112
|
|
109
113
|
unless handler = OUTPUTS[protocol.family]
|
110
|
-
raise "No
|
114
|
+
raise "No handler for protocol family: #{protocol.family}"
|
111
115
|
end
|
112
116
|
|
113
|
-
protocol.connect
|
117
|
+
protocol.connect config, log, handler
|
114
118
|
end
|
115
119
|
|
116
|
-
def self.setup_input
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
unless connection = INPUTS[protocol.family]
|
122
|
-
raise "No connection for protocol family: #{protocol.family}"
|
123
|
-
end
|
124
|
-
|
125
|
-
protocol.bind opts, core, log, connection, log
|
126
|
-
end
|
120
|
+
def self.setup_input config
|
121
|
+
config[:host] ||= DEFAULT_HOST
|
122
|
+
config[:port] ||= DEFAULT_PORT
|
123
|
+
config[:protocol] ||= DEFAULT_PROTOCOL
|
127
124
|
|
128
|
-
|
129
|
-
opts[:port] ||= DEFAULT_PORT
|
130
|
-
protocol = FFWD.parse_protocol(opts[:protocol] || DEFAULT_PROTOCOL)
|
125
|
+
protocol = FFWD.parse_protocol config[:protocol]
|
131
126
|
|
132
127
|
unless connection = INPUTS[protocol.family]
|
133
128
|
raise "No connection for protocol family: #{protocol.family}"
|
134
129
|
end
|
135
130
|
|
136
|
-
protocol.
|
131
|
+
protocol.bind config, log, connection
|
137
132
|
end
|
138
133
|
end
|
data/lib/ffwd/protocol0.pb.rb
CHANGED
@@ -1,93 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# package FFWD.Protocol0;
|
4
|
-
#
|
5
|
-
# message Metric {
|
6
|
-
# // processor to use for metric.
|
7
|
-
# optional string proc = 1;
|
8
|
-
# // time in ms when metric was generated.
|
9
|
-
# optional int64 time = 2;
|
10
|
-
# // key of metric.
|
11
|
-
# optional string key = 3;
|
12
|
-
# // value of metric.
|
13
|
-
# optional double value = 4;
|
14
|
-
# // host where metric originated.
|
15
|
-
# optional string host = 5;
|
16
|
-
# // tags associated to metric.
|
17
|
-
# repeated string tags = 6;
|
18
|
-
# // attributes associated to metric.
|
19
|
-
# repeated Attribute attributes = 7;
|
20
|
-
# }
|
21
|
-
#
|
22
|
-
# message Event {
|
23
|
-
# // time in ms when the event was generated.
|
24
|
-
# optional int64 time = 1;
|
25
|
-
# // key of event.
|
26
|
-
# optional string key = 2;
|
27
|
-
# // value of event.
|
28
|
-
# optional double value = 3;
|
29
|
-
# // host where event originated.
|
30
|
-
# optional string host = 4;
|
31
|
-
# // indicated state of this event.
|
32
|
-
# optional string state = 5;
|
33
|
-
# // description of event.
|
34
|
-
# optional string description = 6;
|
35
|
-
# // time this event should be considered valid in seconds.
|
36
|
-
# optional int64 ttl = 7;
|
37
|
-
# // tags associated to event.
|
38
|
-
# repeated string tags = 8;
|
39
|
-
# // attributes associated to event.
|
40
|
-
# repeated Attribute attributes = 9;
|
41
|
-
# }
|
42
|
-
#
|
43
|
-
# message Attribute {
|
44
|
-
# required string key = 1;
|
45
|
-
# optional string value = 2;
|
46
|
-
# }
|
47
|
-
#
|
48
|
-
# message Message {
|
49
|
-
# optional Metric metric = 1;
|
50
|
-
# optional Event event = 2;
|
51
|
-
# }
|
52
|
-
|
53
|
-
require 'protobuf/message/message'
|
54
|
-
require 'protobuf/message/enum'
|
55
|
-
require 'protobuf/message/service'
|
56
|
-
require 'protobuf/message/extend'
|
1
|
+
## Generated from proto/protocol0.proto for ffwd.protocol0
|
2
|
+
require "beefcake"
|
57
3
|
|
58
4
|
module FFWD
|
59
5
|
module Protocol0
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
optional :int64, :time, 2
|
64
|
-
optional :string, :key, 3
|
65
|
-
optional :double, :value, 4
|
66
|
-
optional :string, :host, 5
|
67
|
-
repeated :string, :tags, 6
|
68
|
-
repeated :Attribute, :attributes, 7
|
6
|
+
|
7
|
+
class Metric
|
8
|
+
include Beefcake::Message
|
69
9
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
optional :string, :key, 2
|
74
|
-
optional :double, :value, 3
|
75
|
-
optional :string, :host, 4
|
76
|
-
optional :string, :state, 5
|
77
|
-
optional :string, :description, 6
|
78
|
-
optional :int64, :ttl, 7
|
79
|
-
repeated :string, :tags, 8
|
80
|
-
repeated :Attribute, :attributes, 9
|
10
|
+
|
11
|
+
class Event
|
12
|
+
include Beefcake::Message
|
81
13
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
optional :string, :value, 2
|
14
|
+
|
15
|
+
class Attribute
|
16
|
+
include Beefcake::Message
|
86
17
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
18
|
+
|
19
|
+
class Message
|
20
|
+
include Beefcake::Message
|
21
|
+
end
|
22
|
+
|
23
|
+
class Metric
|
24
|
+
optional :proc, :string, 1
|
25
|
+
optional :time, :int64, 2
|
26
|
+
optional :key, :string, 3
|
27
|
+
optional :value, :double, 4
|
28
|
+
optional :host, :string, 5
|
29
|
+
repeated :tags, :string, 6
|
30
|
+
repeated :attributes, Attribute, 7
|
31
|
+
end
|
32
|
+
|
33
|
+
class Event
|
34
|
+
optional :time, :int64, 1
|
35
|
+
optional :key, :string, 2
|
36
|
+
optional :value, :double, 3
|
37
|
+
optional :host, :string, 4
|
38
|
+
optional :state, :string, 5
|
39
|
+
optional :description, :string, 6
|
40
|
+
optional :ttl, :int64, 7
|
41
|
+
repeated :tags, :string, 8
|
42
|
+
repeated :attributes, Attribute, 9
|
43
|
+
end
|
44
|
+
|
45
|
+
class Attribute
|
46
|
+
required :key, :string, 1
|
47
|
+
optional :value, :string, 2
|
48
|
+
end
|
49
|
+
|
50
|
+
class Message
|
51
|
+
optional :metric, Metric, 1
|
52
|
+
optional :event, Event, 2
|
91
53
|
end
|
92
54
|
end
|
93
|
-
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffwd-protobuf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- John-John Tedro
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: beefcake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: ffwd
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - '='
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
33
|
+
version: 0.2.0
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - '='
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
40
|
+
version: 0.2.0
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec-mocks
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description:
|
@@ -82,34 +73,33 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- lib/ffwd/protocol0.pb.rb
|
86
|
-
- lib/ffwd/plugin/protobuf/version.rb
|
87
|
-
- lib/ffwd/plugin/protobuf/serializer/protocol0.rb
|
88
|
-
- lib/ffwd/plugin/protobuf/serializer.rb
|
89
76
|
- lib/ffwd/plugin/protobuf.rb
|
77
|
+
- lib/ffwd/plugin/protobuf/serializer.rb
|
78
|
+
- lib/ffwd/plugin/protobuf/serializer/protocol0.rb
|
79
|
+
- lib/ffwd/plugin/protobuf/version.rb
|
80
|
+
- lib/ffwd/protocol0.pb.rb
|
90
81
|
homepage: https://github.com/spotify/ffwd
|
91
82
|
licenses:
|
92
83
|
- Apache 2.0
|
84
|
+
metadata: {}
|
93
85
|
post_install_message:
|
94
86
|
rdoc_options: []
|
95
87
|
require_paths:
|
96
88
|
- lib
|
97
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
90
|
requirements:
|
100
|
-
- -
|
91
|
+
- - '>='
|
101
92
|
- !ruby/object:Gem::Version
|
102
93
|
version: '0'
|
103
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
95
|
requirements:
|
106
|
-
- -
|
96
|
+
- - '>='
|
107
97
|
- !ruby/object:Gem::Version
|
108
98
|
version: '0'
|
109
99
|
requirements: []
|
110
100
|
rubyforge_project:
|
111
|
-
rubygems_version:
|
101
|
+
rubygems_version: 2.0.3
|
112
102
|
signing_key:
|
113
|
-
specification_version:
|
103
|
+
specification_version: 4
|
114
104
|
summary: protobuf reference protocol support for FFWD.
|
115
105
|
test_files: []
|