loggregator_emitter 5.0.1 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -1
- data/README.md +10 -8
- data/lib/loggregator_emitter/emit.rb +102 -11
- data/lib/sonde/envelope.pb.rb +10 -4
- data/lib/sonde/http.pb.rb +1 -33
- data/lib/sonde/metric.pb.rb +2 -0
- data/lib/sonde/sonde_extender.rb +13 -1
- data/loggregator_emitter.gemspec +5 -4
- data/spec/loggregator_emitter/emit_spec.rb +175 -14
- data/spec/spec_helper.rb +1 -0
- metadata +31 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce623535025497b97a8f11adcae61e83d3da8f97
|
4
|
+
data.tar.gz: edaff20710aef2d52d43ea383c808cbd21f86349
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a19fe40d7843694e3e12c35e0928355ab56f83703838766460ec573533980445a4e4270e2db5e0f81e07ec64091b6572d1f2d84fafdde868b5f98c233b607df
|
7
|
+
data.tar.gz: c037d51137815da7e2c1d6b0a541d9c5f1ef4524b35d87df326dbe578c96aeb7f47dd88ea78f4fda86aa3a17ed66a8898ae352f44c6883e9323f8d9709b4fd39
|
data/.travis.yml
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
notifications:
|
2
2
|
email:
|
3
3
|
- cf-loggregator@pivotallabs.com
|
4
|
+
|
5
|
+
sudo: required
|
6
|
+
dist: precise
|
7
|
+
group: legacy
|
4
8
|
language: ruby
|
9
|
+
|
5
10
|
rvm:
|
6
|
-
- 1.9.3
|
7
11
|
- 2.0.0
|
12
|
+
- 2.3.0
|
8
13
|
script:
|
9
14
|
- bundle exec rake nonperformance
|
10
15
|
- DISABLE_COVERAGE=true bundle exec rake performance
|
data/README.md
CHANGED
@@ -12,12 +12,12 @@ Call emit() or emit_error() on this emitter with the application GUID and the me
|
|
12
12
|
|
13
13
|
##### A valid source name is any 3 character string. Some common component sources are:
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
API (Cloud Controller)
|
16
|
+
RTR (Go Router)
|
17
|
+
UAA
|
18
|
+
DEA
|
19
|
+
APP (Warden container)
|
20
|
+
LGR (Loggregator)
|
21
21
|
|
22
22
|
### Setup
|
23
23
|
|
@@ -33,9 +33,11 @@ Call emit() or emit_error() on this emitter with the application GUID and the me
|
|
33
33
|
|
34
34
|
app_guid = "a8977cb6-3365-4be1-907e-0c878b3a4c6b" # The GUID(UUID) for the user's application
|
35
35
|
|
36
|
-
emitter.emit(app_guid,message) # Emits messages with a message type of OUT
|
36
|
+
emitter.emit(app_guid, message) # Emits messages with a message type of OUT
|
37
37
|
|
38
|
-
emitter.
|
38
|
+
emitter.emit(app_guid, message, {"key" => "value"}) # Emits messages with tags
|
39
|
+
|
40
|
+
emitter.emit_error(app_guid, error_message) # Emits messages with a message type of ERR
|
39
41
|
|
40
42
|
### Regenerating Protobuf library
|
41
43
|
|
@@ -16,7 +16,7 @@ module LoggregatorEmitter
|
|
16
16
|
@host, @port = loggregator_server.split(/:([^:]*$)/)
|
17
17
|
|
18
18
|
raise ArgumentError, "Must provide valid loggregator server: #{loggregator_server}" if !valid_hostname || !valid_port
|
19
|
-
@host = ::Resolv.getaddresses(@host).
|
19
|
+
@host = ::Resolv.getaddresses(@host).first
|
20
20
|
raise ArgumentError, "Must provide valid loggregator server: #{loggregator_server}" unless @host
|
21
21
|
|
22
22
|
raise ArgumentError, "Must provide a valid origin" unless origin
|
@@ -30,12 +30,30 @@ module LoggregatorEmitter
|
|
30
30
|
@source_instance = source_instance && source_instance.to_s
|
31
31
|
end
|
32
32
|
|
33
|
-
def emit(app_id, message)
|
34
|
-
emit_message(app_id, message, LogMessage::MessageType::OUT)
|
33
|
+
def emit(app_id, message, tags = nil)
|
34
|
+
emit_message(app_id, message, LogMessage::MessageType::OUT, tags)
|
35
35
|
end
|
36
36
|
|
37
|
-
def emit_error(app_id, message)
|
38
|
-
emit_message(app_id, message, LogMessage::MessageType::ERR)
|
37
|
+
def emit_error(app_id, message, tags = nil)
|
38
|
+
emit_message(app_id, message, LogMessage::MessageType::ERR, tags)
|
39
|
+
end
|
40
|
+
|
41
|
+
def emit_value_metric(name, value, unit, tags = nil)
|
42
|
+
return unless name && value && unit
|
43
|
+
|
44
|
+
send_protobuffer(create_value_metric_envelope(name, value, unit, tags))
|
45
|
+
end
|
46
|
+
|
47
|
+
def emit_counter(name, delta, tags = nil)
|
48
|
+
return unless name && delta
|
49
|
+
|
50
|
+
send_protobuffer(create_counter_envelope(name, delta, tags))
|
51
|
+
end
|
52
|
+
|
53
|
+
def emit_container_metric(app_id, instanceIndex, cpu, memory, disk, tags = nil)
|
54
|
+
return unless app_id && instanceIndex && cpu && memory && disk
|
55
|
+
|
56
|
+
send_protobuffer(create_container_metric_envelope(app_id, instanceIndex, cpu, memory, disk, tags))
|
39
57
|
end
|
40
58
|
|
41
59
|
private
|
@@ -52,7 +70,15 @@ module LoggregatorEmitter
|
|
52
70
|
message.split(/\n|\r/).reject { |a| a.empty? }
|
53
71
|
end
|
54
72
|
|
55
|
-
def
|
73
|
+
def set_tags(tags)
|
74
|
+
envelope_tags = []
|
75
|
+
tags.each do |k, v|
|
76
|
+
envelope_tags << ::Sonde::Envelope::TagsEntry.new(:key => k, :value => v)
|
77
|
+
end
|
78
|
+
envelope_tags
|
79
|
+
end
|
80
|
+
|
81
|
+
def emit_message(app_id, message, type, tags = nil)
|
56
82
|
return unless app_id && message && message.strip.length > 0
|
57
83
|
|
58
84
|
split_message(message).each do |m|
|
@@ -60,13 +86,13 @@ module LoggregatorEmitter
|
|
60
86
|
m = m.byteslice(0, MAX_MESSAGE_BYTE_SIZE-TRUNCATED_STRING.bytesize) + TRUNCATED_STRING
|
61
87
|
end
|
62
88
|
|
63
|
-
send_protobuffer(create_log_envelope(app_id, m, type))
|
89
|
+
send_protobuffer(create_log_envelope(app_id, m, type, tags))
|
64
90
|
end
|
65
91
|
end
|
66
92
|
|
67
|
-
def create_log_message(app_id, message, type)
|
93
|
+
def create_log_message(app_id, message, type, time)
|
68
94
|
lm = ::Sonde::LogMessage.new()
|
69
|
-
lm.time =
|
95
|
+
lm.time = time
|
70
96
|
lm.message = message
|
71
97
|
lm.app_id = app_id
|
72
98
|
lm.source_instance = @source_instance
|
@@ -75,14 +101,79 @@ module LoggregatorEmitter
|
|
75
101
|
lm
|
76
102
|
end
|
77
103
|
|
78
|
-
def create_log_envelope(app_id, message, type)
|
104
|
+
def create_log_envelope(app_id, message, type, tags = nil)
|
79
105
|
le = ::Sonde::Envelope.new()
|
80
106
|
le.origin = @origin
|
107
|
+
le.time = Time.now
|
81
108
|
le.eventType = ::Sonde::Envelope::EventType::LogMessage
|
82
|
-
le.logMessage = create_log_message(app_id, message, type)
|
109
|
+
le.logMessage = create_log_message(app_id, message, type, le.time)
|
110
|
+
if tags != nil
|
111
|
+
le.tags = set_tags(tags)
|
112
|
+
end
|
83
113
|
le
|
84
114
|
end
|
85
115
|
|
116
|
+
def create_value_metric(name, value, unit)
|
117
|
+
metric = ::Sonde::ValueMetric.new()
|
118
|
+
metric.name = name
|
119
|
+
metric.value = value
|
120
|
+
metric.unit = unit
|
121
|
+
metric
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_value_metric_envelope(name, value, unit, tags = nil)
|
125
|
+
envelope = ::Sonde::Envelope.new()
|
126
|
+
envelope.time = Time.now
|
127
|
+
envelope.origin = @origin
|
128
|
+
envelope.eventType = ::Sonde::Envelope::EventType::ValueMetric
|
129
|
+
envelope.valueMetric = create_value_metric(name, value, unit)
|
130
|
+
if tags != nil
|
131
|
+
envelope.tags = set_tags(tags)
|
132
|
+
end
|
133
|
+
envelope
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_counter_event(name, delta)
|
137
|
+
counter = ::Sonde::CounterEvent.new()
|
138
|
+
counter.name = name
|
139
|
+
counter.delta = delta
|
140
|
+
counter
|
141
|
+
end
|
142
|
+
|
143
|
+
def create_counter_envelope(name, delta, tags = nil)
|
144
|
+
envelope = ::Sonde::Envelope.new()
|
145
|
+
envelope.time = Time.now
|
146
|
+
envelope.origin = @origin
|
147
|
+
envelope.eventType = ::Sonde::Envelope::EventType::CounterEvent
|
148
|
+
envelope.counterEvent = create_counter_event(name, delta)
|
149
|
+
if tags != nil
|
150
|
+
envelope.tags = set_tags(tags)
|
151
|
+
end
|
152
|
+
envelope
|
153
|
+
end
|
154
|
+
|
155
|
+
def create_container_metric(app_id, instanceIndex, cpu, memory, disk)
|
156
|
+
metric = ::Sonde::ContainerMetric.new()
|
157
|
+
metric.applicationId = app_id
|
158
|
+
metric.instanceIndex = instanceIndex
|
159
|
+
metric.cpuPercentage = cpu
|
160
|
+
metric.memoryBytes = memory
|
161
|
+
metric.diskBytes = disk
|
162
|
+
metric
|
163
|
+
end
|
164
|
+
|
165
|
+
def create_container_metric_envelope(app_id, instanceIndex, cpu, memory, disk, tags = nil)
|
166
|
+
envelope = ::Sonde::Envelope.new()
|
167
|
+
envelope.time = Time.now
|
168
|
+
envelope.origin = @origin
|
169
|
+
envelope.eventType = ::Sonde::Envelope::EventType::ContainerMetric
|
170
|
+
envelope.containerMetric = create_container_metric(app_id, instanceIndex, cpu, memory, disk)
|
171
|
+
if tags != nil
|
172
|
+
envelope.tags = set_tags(tags)
|
173
|
+
end
|
174
|
+
envelope
|
175
|
+
end
|
176
|
+
|
86
177
|
def send_protobuffer(lm)
|
87
178
|
result = lm.encode.buf
|
88
179
|
result.unpack("C*")
|
data/lib/sonde/envelope.pb.rb
CHANGED
@@ -7,8 +7,6 @@ module Sonde
|
|
7
7
|
include Beefcake::Message
|
8
8
|
|
9
9
|
module EventType
|
10
|
-
HttpStart = 2
|
11
|
-
HttpStop = 3
|
12
10
|
HttpStartStop = 4
|
13
11
|
LogMessage = 5
|
14
12
|
ValueMetric = 6
|
@@ -16,9 +14,18 @@ module Sonde
|
|
16
14
|
Error = 8
|
17
15
|
ContainerMetric = 9
|
18
16
|
end
|
17
|
+
|
18
|
+
class TagsEntry
|
19
|
+
include Beefcake::Message
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
class Envelope
|
24
|
+
|
25
|
+
class TagsEntry
|
26
|
+
optional :key, :string, 1
|
27
|
+
optional :value, :string, 2
|
28
|
+
end
|
22
29
|
required :origin, :string, 1
|
23
30
|
required :eventType, Envelope::EventType, 2
|
24
31
|
optional :timestamp, :int64, 6
|
@@ -26,8 +33,7 @@ module Sonde
|
|
26
33
|
optional :job, :string, 14
|
27
34
|
optional :index, :string, 15
|
28
35
|
optional :ip, :string, 16
|
29
|
-
|
30
|
-
optional :httpStop, HttpStop, 5
|
36
|
+
repeated :tags, Envelope::TagsEntry, 17
|
31
37
|
optional :httpStartStop, HttpStartStop, 7
|
32
38
|
optional :logMessage, LogMessage, 8
|
33
39
|
optional :valueMetric, ValueMetric, 9
|
data/lib/sonde/http.pb.rb
CHANGED
@@ -55,42 +55,10 @@ module Sonde
|
|
55
55
|
VERSION_CONTROL = 44
|
56
56
|
end
|
57
57
|
|
58
|
-
class HttpStart
|
59
|
-
include Beefcake::Message
|
60
|
-
end
|
61
|
-
|
62
|
-
class HttpStop
|
63
|
-
include Beefcake::Message
|
64
|
-
end
|
65
|
-
|
66
58
|
class HttpStartStop
|
67
59
|
include Beefcake::Message
|
68
60
|
end
|
69
61
|
|
70
|
-
class HttpStart
|
71
|
-
required :timestamp, :int64, 1
|
72
|
-
required :requestId, UUID, 2
|
73
|
-
required :peerType, PeerType, 3
|
74
|
-
required :method, Method, 4
|
75
|
-
required :uri, :string, 5
|
76
|
-
required :remoteAddress, :string, 6
|
77
|
-
required :userAgent, :string, 7
|
78
|
-
optional :parentRequestId, UUID, 8
|
79
|
-
optional :applicationId, UUID, 9
|
80
|
-
optional :instanceIndex, :int32, 10
|
81
|
-
optional :instanceId, :string, 11
|
82
|
-
end
|
83
|
-
|
84
|
-
class HttpStop
|
85
|
-
required :timestamp, :int64, 1
|
86
|
-
required :uri, :string, 2
|
87
|
-
required :requestId, UUID, 3
|
88
|
-
required :peerType, PeerType, 4
|
89
|
-
required :statusCode, :int32, 5
|
90
|
-
required :contentLength, :int64, 6
|
91
|
-
optional :applicationId, UUID, 7
|
92
|
-
end
|
93
|
-
|
94
62
|
class HttpStartStop
|
95
63
|
required :startTimestamp, :int64, 1
|
96
64
|
required :stopTimestamp, :int64, 2
|
@@ -102,9 +70,9 @@ module Sonde
|
|
102
70
|
required :userAgent, :string, 8
|
103
71
|
required :statusCode, :int32, 9
|
104
72
|
required :contentLength, :int64, 10
|
105
|
-
optional :parentRequestId, UUID, 11
|
106
73
|
optional :applicationId, UUID, 12
|
107
74
|
optional :instanceIndex, :int32, 13
|
108
75
|
optional :instanceId, :string, 14
|
76
|
+
repeated :forwarded, :string, 15
|
109
77
|
end
|
110
78
|
end
|
data/lib/sonde/metric.pb.rb
CHANGED
data/lib/sonde/sonde_extender.rb
CHANGED
@@ -14,4 +14,16 @@ module Sonde
|
|
14
14
|
Time.at(num_secs, fractional_usecs)
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
|
+
class Envelope
|
19
|
+
def time=(time)
|
20
|
+
self.timestamp = (time.tv_sec * 1000000000) + time.tv_nsec
|
21
|
+
end
|
22
|
+
|
23
|
+
def time
|
24
|
+
num_secs = @timestamp / 1000000000
|
25
|
+
fractional_usecs = (@timestamp % 1000000000).to_f / 1000
|
26
|
+
Time.at(num_secs, fractional_usecs)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/loggregator_emitter.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "loggregator_emitter"
|
5
|
-
spec.version = '5.
|
5
|
+
spec.version = '5.1.1'
|
6
6
|
spec.authors = ["Pivotal"]
|
7
7
|
spec.email = ["cf-eng@pivotallabs.com"]
|
8
8
|
spec.description = "Library to emit data to Loggregator"
|
@@ -15,12 +15,13 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.test_files = spec.files.grep(%r{^(spec)/})
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
18
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.0.0")
|
19
19
|
|
20
20
|
spec.add_dependency "beefcake", "~> 1.0.0"
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "coveralls", "~> 0.8", ">= 0.8.14"
|
23
24
|
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "rspec", "~> 2.14.1"
|
25
|
-
spec.add_development_dependency "
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14", ">= 2.14.1"
|
26
|
+
spec.add_development_dependency "timecop"
|
26
27
|
end
|
@@ -6,7 +6,7 @@ require "loggregator_emitter"
|
|
6
6
|
describe LoggregatorEmitter do
|
7
7
|
|
8
8
|
before :all do
|
9
|
-
@free_port =
|
9
|
+
@free_port = test_port
|
10
10
|
@server = FakeLoggregatorServer.new(@free_port)
|
11
11
|
@server.start
|
12
12
|
end
|
@@ -19,68 +19,84 @@ describe LoggregatorEmitter do
|
|
19
19
|
@server.reset
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_port
|
23
|
+
server = TCPServer.new('localhost', 0)
|
24
|
+
server.addr[1]
|
25
|
+
end
|
26
|
+
|
22
27
|
describe "configuring emitter" do
|
23
28
|
describe "valid configurations" do
|
24
29
|
it "is valid with IP and proper source name" do
|
25
|
-
expect { LoggregatorEmitter::Emitter.new("0.0.0.0
|
30
|
+
expect { LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "origin", "DEA") }.not_to raise_error
|
26
31
|
end
|
27
32
|
|
28
33
|
it "is valid with resolveable hostname and proper source name" do
|
29
|
-
expect { LoggregatorEmitter::Emitter.new("localhost
|
34
|
+
expect { LoggregatorEmitter::Emitter.new("localhost:#{@free_port}", "origin", "DEA") }.not_to raise_error
|
30
35
|
end
|
31
36
|
|
32
37
|
it "accepts a string as source type/name" do
|
33
|
-
expect { LoggregatorEmitter::Emitter.new("localhost
|
38
|
+
expect { LoggregatorEmitter::Emitter.new("localhost:#{@free_port}", "origin", "STG") }.not_to raise_error
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
37
42
|
describe "invalid configurations" do
|
38
43
|
describe "error based on loggregator_server" do
|
39
44
|
it "raises if host has protocol" do
|
40
|
-
expect { LoggregatorEmitter::Emitter.new("http://0.0.0.0
|
45
|
+
expect { LoggregatorEmitter::Emitter.new("http://0.0.0.0:#{@free_port}", "origin", "DEA") }.to raise_error(ArgumentError)
|
41
46
|
end
|
42
47
|
|
43
48
|
it "raises if host is blank" do
|
44
|
-
expect { LoggregatorEmitter::Emitter.new("
|
49
|
+
expect { LoggregatorEmitter::Emitter.new(":#{@free_port}", "origin", "DEA") }.to raise_error(ArgumentError)
|
45
50
|
end
|
46
51
|
|
47
52
|
it "raises if host is unresolvable" do
|
48
|
-
expect { LoggregatorEmitter::Emitter.new("i.cant.resolve.foo
|
53
|
+
expect { LoggregatorEmitter::Emitter.new("i.cant.resolve.foo:#{@free_port}", "origin", "DEA") }.to raise_error(ArgumentError)
|
49
54
|
end
|
50
55
|
|
51
56
|
it "raises if origin is blank" do
|
52
|
-
expect { LoggregatorEmitter::Emitter.new("
|
57
|
+
expect { LoggregatorEmitter::Emitter.new(":#{@free_port}", "", "DEA") }.to raise_error(ArgumentError)
|
53
58
|
end
|
54
59
|
|
55
60
|
it "raises if source_type is an unknown integer" do
|
56
|
-
expect { LoggregatorEmitter::Emitter.new("localhost
|
61
|
+
expect { LoggregatorEmitter::Emitter.new("localhost:#{@free_port}", "origin", 7) }.to raise_error(ArgumentError)
|
57
62
|
end
|
58
63
|
|
59
64
|
it "raises if source_type is not an integer or string" do
|
60
|
-
expect { LoggregatorEmitter::Emitter.new("localhost
|
61
|
-
expect { LoggregatorEmitter::Emitter.new("localhost
|
65
|
+
expect { LoggregatorEmitter::Emitter.new("localhost:#{@free_port}", "origin", nil) }.to raise_error(ArgumentError)
|
66
|
+
expect { LoggregatorEmitter::Emitter.new("localhost:#{@free_port}", "origin", 12.0) }.to raise_error(ArgumentError)
|
62
67
|
end
|
63
68
|
|
64
69
|
it "raises if source_type is too large of a string" do
|
65
|
-
expect { LoggregatorEmitter::Emitter.new("localhost
|
70
|
+
expect { LoggregatorEmitter::Emitter.new("localhost:#{@free_port}", "origin", "ABCD") }.to raise_error(ArgumentError)
|
66
71
|
end
|
67
72
|
|
68
73
|
it "raises if source_type is too small of a string" do
|
69
|
-
expect { LoggregatorEmitter::Emitter.new("localhost
|
74
|
+
expect { LoggregatorEmitter::Emitter.new("localhost:#{@free_port}", "origin", "AB") }.to raise_error(ArgumentError)
|
70
75
|
end
|
71
76
|
end
|
72
77
|
end
|
73
78
|
end
|
74
79
|
|
80
|
+
def test_tags(tags)
|
81
|
+
expected_tags = []
|
82
|
+
tags.each do |k, v|
|
83
|
+
expected_tags << ::Sonde::Envelope::TagsEntry.new(:key => k, :value => v)
|
84
|
+
end
|
85
|
+
expected_tags
|
86
|
+
end
|
75
87
|
|
88
|
+
let(:timestamp) {Time.now}
|
76
89
|
describe "emit_log_envelope" do
|
77
90
|
def make_emitter(host)
|
78
91
|
LoggregatorEmitter::Emitter.new("#{host}:#{@free_port}", "origin", "API", 42)
|
79
92
|
end
|
80
93
|
|
81
94
|
it "successfully writes envelope protobuffers" do
|
95
|
+
tag = {"key1" => "value1"}
|
82
96
|
emitter = make_emitter("0.0.0.0")
|
83
|
-
|
97
|
+
Timecop.freeze timestamp do
|
98
|
+
emitter.emit("my_app_id", "Hello there!", tag)
|
99
|
+
end
|
84
100
|
|
85
101
|
@server.wait_for_messages(1)
|
86
102
|
|
@@ -89,12 +105,32 @@ describe LoggregatorEmitter do
|
|
89
105
|
expect(messages.length).to eq 1
|
90
106
|
message = messages[0]
|
91
107
|
|
108
|
+
expect(message.time).to be_within(1).of timestamp
|
109
|
+
expect(message.logMessage.time).to be_within(1).of timestamp
|
92
110
|
expect(message.logMessage.message).to eq "Hello there!"
|
93
111
|
expect(message.logMessage.app_id).to eq "my_app_id"
|
94
112
|
expect(message.logMessage.source_instance).to eq "42"
|
113
|
+
expect(message.tags).to eq test_tags(tag)
|
95
114
|
expect(message.logMessage.message_type).to eq ::Sonde::LogMessage::MessageType::OUT
|
96
115
|
end
|
97
116
|
|
117
|
+
it "successfully handles envelope with multiple tags" do
|
118
|
+
tags = {"key1" => "value1", "key2" => "value2"}
|
119
|
+
emitter = make_emitter("0.0.0.0")
|
120
|
+
Timecop.freeze timestamp do
|
121
|
+
emitter.emit("my_app_id", "Hello there!", tags)
|
122
|
+
end
|
123
|
+
|
124
|
+
@server.wait_for_messages(1)
|
125
|
+
|
126
|
+
messages = @server.messages
|
127
|
+
|
128
|
+
expect(messages.length).to eq 1
|
129
|
+
message = messages[0]
|
130
|
+
|
131
|
+
expect(message.tags).to eq test_tags(tags)
|
132
|
+
end
|
133
|
+
|
98
134
|
it "gracefully handles failures to send messages" do
|
99
135
|
emitter = make_emitter("0.0.0.0")
|
100
136
|
UDPSocket.any_instance.stub(:sendmsg_nonblock).and_raise("Operation not permitted - sendmsg(2) (Errno::EPERM)")
|
@@ -118,6 +154,131 @@ describe LoggregatorEmitter do
|
|
118
154
|
end
|
119
155
|
end
|
120
156
|
|
157
|
+
describe "#emit_value_metric" do
|
158
|
+
let(:emitter) { LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "origin", "DEA")}
|
159
|
+
|
160
|
+
it 'successfully writes envelope protobuffers' do
|
161
|
+
tag = {"key1" => "value1"}
|
162
|
+
Timecop.freeze timestamp do
|
163
|
+
emitter.emit_value_metric('my-metric', 5155, 'my-units', tag)
|
164
|
+
end
|
165
|
+
|
166
|
+
@server.wait_for_messages(1)
|
167
|
+
messages = @server.messages
|
168
|
+
|
169
|
+
expect(messages.length).to eq 1
|
170
|
+
message = messages[0]
|
171
|
+
|
172
|
+
expect(message.time).to be_within(1).of(timestamp)
|
173
|
+
expect(message.valueMetric.value).to eq(5155)
|
174
|
+
expect(message.valueMetric.name).to eq('my-metric')
|
175
|
+
expect(message.valueMetric.unit).to eq('my-units')
|
176
|
+
expect(message.tags).to eq test_tags(tag)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "successfully handles envelope with multiple tags" do
|
180
|
+
tags = {"key1" => "value1", "key2" => "value2"}
|
181
|
+
Timecop.freeze timestamp do
|
182
|
+
emitter.emit_value_metric('my-metric', 5155, 'my-units', tags)
|
183
|
+
end
|
184
|
+
|
185
|
+
@server.wait_for_messages(1)
|
186
|
+
messages = @server.messages
|
187
|
+
|
188
|
+
expect(messages.length).to eq 1
|
189
|
+
message = messages[0]
|
190
|
+
|
191
|
+
expect(message.tags).to eq test_tags(tags)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "#emit_counter" do
|
196
|
+
let(:emitter) { LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "origin", "DEA")}
|
197
|
+
|
198
|
+
it 'successfully writes envelope protobuffers' do
|
199
|
+
tag = {"key1" => "value1"}
|
200
|
+
Timecop.freeze timestamp do
|
201
|
+
emitter.emit_counter('my-counter', 5, tag)
|
202
|
+
end
|
203
|
+
|
204
|
+
@server.wait_for_messages(1)
|
205
|
+
|
206
|
+
messages = @server.messages
|
207
|
+
|
208
|
+
expect(messages.length).to eq 1
|
209
|
+
message = messages[0]
|
210
|
+
|
211
|
+
expect(message.time).to be_within(1).of(timestamp)
|
212
|
+
expect(message.counterEvent.delta).to eq(5)
|
213
|
+
expect(message.counterEvent.name).to eq('my-counter')
|
214
|
+
expect(message.tags).to eq test_tags(tag)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "successfully handles envelope with multiple tags" do
|
218
|
+
tags = {"key1" => "value1", "key2" => "value2"}
|
219
|
+
Timecop.freeze timestamp do
|
220
|
+
emitter.emit_counter('my-counter', 5, tags)
|
221
|
+
end
|
222
|
+
|
223
|
+
@server.wait_for_messages(1)
|
224
|
+
|
225
|
+
messages = @server.messages
|
226
|
+
|
227
|
+
expect(messages.length).to eq 1
|
228
|
+
message = messages[0]
|
229
|
+
|
230
|
+
expect(message.tags).to eq test_tags(tags)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "#emit_container_metric" do
|
235
|
+
let(:emitter) { LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "origin", "DEA")}
|
236
|
+
|
237
|
+
it 'successfully writes envelope protobuffers' do
|
238
|
+
tag = {"key1" => "value1"}
|
239
|
+
Timecop.freeze timestamp do
|
240
|
+
emitter.emit_container_metric('app-id', 3, 1.3, 1024, 2048, tag)
|
241
|
+
end
|
242
|
+
|
243
|
+
@server.wait_for_messages(1)
|
244
|
+
|
245
|
+
messages = @server.messages
|
246
|
+
|
247
|
+
expect(messages.length).to eq 1
|
248
|
+
message = messages[0]
|
249
|
+
|
250
|
+
expect(message.time).to be_within(1).of(timestamp)
|
251
|
+
expect(message.containerMetric.applicationId).to eq('app-id')
|
252
|
+
expect(message.containerMetric.instanceIndex).to eq(3)
|
253
|
+
expect(message.containerMetric.cpuPercentage).to eq(1.3)
|
254
|
+
expect(message.containerMetric.memoryBytes).to eq(1024)
|
255
|
+
expect(message.containerMetric.diskBytes).to eq(2048)
|
256
|
+
expect(message.tags).to eq test_tags(tag)
|
257
|
+
end
|
258
|
+
|
259
|
+
it "successfully handles envelope with multiple tags" do
|
260
|
+
tags = {"key1" => "value1", "key2" => "value2"}
|
261
|
+
Timecop.freeze timestamp do
|
262
|
+
emitter.emit_container_metric('app-id', 3, 1.3, 1024, 2048, tags)
|
263
|
+
end
|
264
|
+
|
265
|
+
@server.wait_for_messages(1)
|
266
|
+
|
267
|
+
messages = @server.messages
|
268
|
+
|
269
|
+
expect(messages.length).to eq 1
|
270
|
+
message = messages[0]
|
271
|
+
|
272
|
+
expect(message.time).to be_within(1).of(timestamp)
|
273
|
+
expect(message.containerMetric.applicationId).to eq('app-id')
|
274
|
+
expect(message.containerMetric.instanceIndex).to eq(3)
|
275
|
+
expect(message.containerMetric.cpuPercentage).to eq(1.3)
|
276
|
+
expect(message.containerMetric.memoryBytes).to eq(1024)
|
277
|
+
expect(message.containerMetric.diskBytes).to eq(2048)
|
278
|
+
expect(message.tags).to eq test_tags(tags)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
121
282
|
{"emit" => LogMessage::MessageType::OUT, "emit_error" => LogMessage::MessageType::ERR}.each do |emit_method, message_type|
|
122
283
|
describe "##{emit_method}" do
|
123
284
|
def make_emitter(host)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loggregator_emitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pivotal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: beefcake
|
@@ -38,6 +38,26 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: coveralls
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.8'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.8.14
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.8'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.8.14
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: rake
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -57,6 +77,9 @@ dependencies:
|
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
59
79
|
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.14'
|
82
|
+
- - ">="
|
60
83
|
- !ruby/object:Gem::Version
|
61
84
|
version: 2.14.1
|
62
85
|
type: :development
|
@@ -64,10 +87,13 @@ dependencies:
|
|
64
87
|
version_requirements: !ruby/object:Gem::Requirement
|
65
88
|
requirements:
|
66
89
|
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '2.14'
|
92
|
+
- - ">="
|
67
93
|
- !ruby/object:Gem::Version
|
68
94
|
version: 2.14.1
|
69
95
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
96
|
+
name: timecop
|
71
97
|
requirement: !ruby/object:Gem::Requirement
|
72
98
|
requirements:
|
73
99
|
- - ">="
|
@@ -126,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
152
|
requirements:
|
127
153
|
- - ">="
|
128
154
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
155
|
+
version: 2.0.0
|
130
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
157
|
requirements:
|
132
158
|
- - ">="
|
@@ -134,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
160
|
version: '0'
|
135
161
|
requirements: []
|
136
162
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.5.1
|
138
164
|
signing_key:
|
139
165
|
specification_version: 4
|
140
166
|
summary: Library to emit data to Loggregator
|