loggregator_emitter 0.0.11.pre → 0.0.12.pre

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- loggregator_emitter (0.0.11.pre)
4
+ loggregator_emitter (0.0.12.pre)
5
5
  loggregator_messages (~> 0.0.1.pre)
6
6
 
7
7
  GEM
@@ -3,7 +3,7 @@ require 'socket'
3
3
 
4
4
  module LoggregatorEmitter
5
5
  class Emitter
6
- def initialize(loggregator_server, source_type)
6
+ def initialize(loggregator_server, source_type, source_id = nil)
7
7
  host, port = loggregator_server.split(":")
8
8
  raise RuntimeError, "Must provide valid loggregator server: #{loggregator_server}" if (host == nil || port == nil)
9
9
  raise RuntimeError, "Must provide IP address for loggregator server: #{loggregator_server}" unless host.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)
@@ -11,6 +11,7 @@ module LoggregatorEmitter
11
11
 
12
12
  raise RuntimeError, "Must provide valid source type" unless valid_source_type?(source_type)
13
13
  @source_type = source_type
14
+ @source_id = source_id && source_id.to_s
14
15
  end
15
16
 
16
17
  def emit(app_id, message)
@@ -33,6 +34,7 @@ module LoggregatorEmitter
33
34
  lm.time = Time.now
34
35
  lm.message = message
35
36
  lm.app_id = app_id
37
+ lm.source_id = @source_id
36
38
  lm.source_type = @source_type
37
39
  lm.message_type = type
38
40
  lm
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "loggregator_emitter"
5
- spec.version = '0.0.11.pre'
5
+ spec.version = '0.0.12.pre'
6
6
  spec.authors = ["Pivotal"]
7
7
  spec.email = ["cf-eng@pivotallabs.com"]
8
8
  spec.description = "Library to emit data to Loggregator"
@@ -4,7 +4,6 @@ require 'loggregator_emitter/emit'
4
4
  describe LoggregatorEmitter do
5
5
 
6
6
  describe 'configuring emitter' do
7
-
8
7
  it 'can be configured' do
9
8
  expect { LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::DEA) }.not_to raise_error
10
9
  end
@@ -32,7 +31,7 @@ describe LoggregatorEmitter do
32
31
 
33
32
  describe 'Sending To STDOUT' do
34
33
  before(:each) do
35
- @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER)
34
+ @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER, 42)
36
35
  end
37
36
 
38
37
  it 'successfully writes protobuffer to a socket' do
@@ -52,9 +51,9 @@ describe LoggregatorEmitter do
52
51
  expect(message.message).to eq 'Hello there!'
53
52
  expect(message.app_id).to eq "my_app_id"
54
53
  expect(message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
54
+ expect(message.source_id).to eq "42"
55
55
  expect(message.message_type).to eq LogMessage::MessageType::OUT
56
56
 
57
-
58
57
  message = messages[1]
59
58
  expect(message.message).to eq 'Hello again!'
60
59
  end
@@ -88,4 +87,32 @@ describe LoggregatorEmitter do
88
87
  expect(message.message).to eq 'Hello again!'
89
88
  end
90
89
  end
90
+
91
+ describe "source id" do
92
+ let(:emit_message) do
93
+ server = FakeLoggregatorServer.new(12345)
94
+ server.start
95
+
96
+ @emitter.emit_error("my_app_id", 'Hello there!')
97
+
98
+ server.stop(2)
99
+
100
+ server.messages[0]
101
+ end
102
+
103
+ it "can be nil" do
104
+ @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER)
105
+ expect(emit_message.source_id).to eq nil
106
+ end
107
+
108
+ it "can be passed in as a string" do
109
+ @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER, "some_source_id")
110
+ expect(emit_message.source_id).to eq "some_source_id"
111
+ end
112
+
113
+ it "can be passed in as an integer" do
114
+ @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER, 13)
115
+ expect(emit_message.source_id).to eq "13"
116
+ end
117
+ end
91
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggregator_emitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11.pre
4
+ version: 0.0.12.pre
5
5
  prerelease: 7
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-13 00:00:00.000000000 Z
12
+ date: 2013-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: loggregator_messages