loggregator_emitter 2.0.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,3 +1,6 @@
1
+ notifications:
2
+ email:
3
+ - cf-loggregator@pivotallabs.com
1
4
  language: ruby
2
5
  rvm:
3
6
  - 1.9.3
@@ -9,35 +9,18 @@ module LoggregatorEmitter
9
9
  MAX_MESSAGE_BYTE_SIZE = (9 * 1024) - 512
10
10
  TRUNCATED_STRING = "TRUNCATED"
11
11
 
12
- SOURCE_TYPE_BY_ID = {
13
- 1 => "CLOUD_CONTROLLER",
14
- 2 => "ROUTER",
15
- 3 => "UAA",
16
- 4 => "DEA",
17
- 5 => "WARDEN_CONTAINER",
18
- 6 => "LOGGREGATOR",
19
- }
20
-
21
- def initialize(loggregator_server, source_type_or_name, source_id = nil, secret=nil)
12
+ def initialize(loggregator_server, source_name, source_id = nil, secret=nil)
22
13
  @host, @port = loggregator_server.split(/:([^:]*$)/)
23
14
 
24
15
  raise ArgumentError, "Must provide valid loggregator server: #{loggregator_server}" if !valid_hostname || !valid_port
25
- raise ArgumentError, "Must provide valid source_type_or_name: #{source_type_or_name}" unless source_type_or_name
26
-
27
16
  @host = ::Resolv.getaddresses(@host).last
28
17
  raise ArgumentError, "Must provide valid loggregator server: #{loggregator_server}" unless @host
29
18
 
30
- case source_type_or_name
31
- when LogMessage::SourceType::CLOUD_CONTROLLER..LogMessage::SourceType::LOGGREGATOR
32
- @source_type = source_type_or_name
33
- @source_name = SOURCE_TYPE_BY_ID[source_type_or_name]
34
- when String
35
- raise ArgumentError, "Custom Source String must be 3 characters" unless source_type_or_name.size == 3
36
- @source_type = LogMessage::SourceType::UNKNOWN
37
- @source_name = source_type_or_name
38
- else
39
- raise ArgumentError, "Invalid source: #{source_type_or_name.inspect} Please use a string or a known source type constant"
40
- end
19
+ raise ArgumentError, "Must provide valid source_name: #{source_name}" unless source_name
20
+
21
+ raise ArgumentError, "source_name must be a 3-character string" unless source_name.is_a? String
22
+ raise ArgumentError, "Custom Source String must be 3 characters" unless source_name.size == 3
23
+ @source_name = source_name
41
24
 
42
25
  @secret = secret
43
26
  @source_id = source_id && source_id.to_s
@@ -87,7 +70,6 @@ module LoggregatorEmitter
87
70
  lm.message = message
88
71
  lm.app_id = app_id
89
72
  lm.source_id = @source_id
90
- lm.source_type = @source_type
91
73
  lm.source_name = @source_name
92
74
  lm.message_type = type
93
75
  lm
@@ -9,21 +9,11 @@ class LogMessage
9
9
  OUT = 1
10
10
  ERR = 2
11
11
  end
12
- module SourceType
13
- CLOUD_CONTROLLER = 1
14
- ROUTER = 2
15
- UAA = 3
16
- DEA = 4
17
- WARDEN_CONTAINER = 5
18
- LOGGREGATOR = 6
19
- UNKNOWN = 7
20
- end
21
12
 
22
13
  required :message, :bytes, 1
23
14
  required :message_type, LogMessage::MessageType, 2
24
15
  required :timestamp, :sint64, 3
25
16
  required :app_id, :string, 4
26
- required :source_type, LogMessage::SourceType, 5
27
17
  optional :source_id, :string, 6
28
18
  repeated :drain_urls, :string, 7
29
19
  optional :source_name, :string, 8
@@ -6,21 +6,10 @@ message LogMessage {
6
6
  ERR = 2;
7
7
  }
8
8
 
9
- enum SourceType {
10
- CLOUD_CONTROLLER = 1;
11
- ROUTER = 2;
12
- UAA = 3;
13
- DEA = 4;
14
- WARDEN_CONTAINER = 5;
15
- LOGGREGATOR = 6;
16
- UNKNOWN = 7;
17
- }
18
-
19
9
  required bytes message = 1;
20
10
  required MessageType message_type = 2;
21
11
  required sint64 timestamp = 3;
22
12
  required string app_id = 4;
23
- required SourceType source_type = 5;
24
13
  optional string source_id = 6;
25
14
  repeated string drain_urls = 7;
26
15
  optional string source_name = 8;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "loggregator_emitter"
5
- spec.version = '2.0.3'
5
+ spec.version = '3.0.0'
6
6
  spec.authors = ["Pivotal"]
7
7
  spec.email = ["cf-eng@pivotallabs.com"]
8
8
  spec.description = "Library to emit data to Loggregator"
@@ -19,12 +19,12 @@ describe LoggregatorEmitter do
19
19
 
20
20
  describe "configuring emitter" do
21
21
  describe "valid configurations" do
22
- it "is valid with IP and proper source type" do
23
- expect { LoggregatorEmitter::Emitter.new("0.0.0.0:12345", LogMessage::SourceType::DEA) }.not_to raise_error
22
+ it "is valid with IP and proper source name" do
23
+ expect { LoggregatorEmitter::Emitter.new("0.0.0.0:12345", "DEA") }.not_to raise_error
24
24
  end
25
25
 
26
- it "is valid with resolveable hostname and proper source type" do
27
- expect { LoggregatorEmitter::Emitter.new("localhost:12345", LogMessage::SourceType::DEA) }.not_to raise_error
26
+ it "is valid with resolveable hostname and proper source name" do
27
+ expect { LoggregatorEmitter::Emitter.new("localhost:12345", "DEA") }.not_to raise_error
28
28
  end
29
29
 
30
30
  it "accepts a string as source type/name" do
@@ -35,15 +35,15 @@ describe LoggregatorEmitter do
35
35
  describe "invalid configurations" do
36
36
  describe "error based on loggregator_server" do
37
37
  it "raises if host has protocol" do
38
- expect { LoggregatorEmitter::Emitter.new("http://0.0.0.0:12345", LogMessage::SourceType::DEA) }.to raise_error(ArgumentError)
38
+ expect { LoggregatorEmitter::Emitter.new("http://0.0.0.0:12345", "DEA") }.to raise_error(ArgumentError)
39
39
  end
40
40
 
41
41
  it "raises if host is blank" do
42
- expect { LoggregatorEmitter::Emitter.new(":12345", LogMessage::SourceType::DEA) }.to raise_error(ArgumentError)
42
+ expect { LoggregatorEmitter::Emitter.new(":12345", "DEA") }.to raise_error(ArgumentError)
43
43
  end
44
44
 
45
45
  it "raises if host is unresolvable" do
46
- expect { LoggregatorEmitter::Emitter.new("i.cant.resolve.foo:12345", LogMessage::SourceType::DEA) }.to raise_error(ArgumentError)
46
+ expect { LoggregatorEmitter::Emitter.new("i.cant.resolve.foo:12345", "DEA") }.to raise_error(ArgumentError)
47
47
  end
48
48
 
49
49
  it "raises if source is an unknown integer" do
@@ -69,7 +69,7 @@ describe LoggregatorEmitter do
69
69
 
70
70
  describe "emit_log_envelope" do
71
71
  def make_emitter(host)
72
- LoggregatorEmitter::Emitter.new("#{host}:#{@free_port}", LogMessage::SourceType::CLOUD_CONTROLLER, 42, "secret")
72
+ LoggregatorEmitter::Emitter.new("#{host}:#{@free_port}", "API", 42, "secret")
73
73
  end
74
74
 
75
75
  it "successfully writes envelope protobuffers" do
@@ -90,7 +90,6 @@ describe LoggregatorEmitter do
90
90
 
91
91
  expect(message.log_message.message).to eq "Hello there!"
92
92
  expect(message.log_message.app_id).to eq "my_app_id"
93
- expect(message.log_message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
94
93
  expect(message.log_message.source_id).to eq "42"
95
94
  expect(message.log_message.message_type).to eq LogMessage::MessageType::OUT
96
95
  end
@@ -114,7 +113,7 @@ describe LoggregatorEmitter do
114
113
  {"emit" => LogMessage::MessageType::OUT, "emit_error" => LogMessage::MessageType::ERR}.each do |emit_method, message_type|
115
114
  describe "##{emit_method}" do
116
115
  def make_emitter(host)
117
- LoggregatorEmitter::Emitter.new("#{host}:#{@free_port}", LogMessage::SourceType::CLOUD_CONTROLLER, 42)
116
+ LoggregatorEmitter::Emitter.new("#{host}:#{@free_port}", "API", 42)
118
117
  end
119
118
 
120
119
  it "successfully writes protobuffers using ipv4" do
@@ -131,7 +130,6 @@ describe LoggregatorEmitter do
131
130
  message = messages[0]
132
131
  expect(message.message).to eq "Hello there!"
133
132
  expect(message.app_id).to eq "my_app_id"
134
- expect(message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
135
133
  expect(message.source_id).to eq "42"
136
134
  expect(message.message_type).to eq message_type
137
135
 
@@ -209,28 +207,27 @@ describe LoggregatorEmitter do
209
207
  end
210
208
 
211
209
  it "when type is known" do
212
- @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", LogMessage::SourceType::CLOUD_CONTROLLER)
213
- expect(emit_message.source_name).to eq "CLOUD_CONTROLLER"
210
+ @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "API")
211
+ expect(emit_message.source_name).to eq "API"
214
212
  end
215
213
 
216
214
  it "when type is unknown" do
217
215
  @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "STG")
218
216
  expect(emit_message.source_name).to eq "STG"
219
- expect(emit_message.source_type).to eq LogMessage::SourceType::UNKNOWN
220
217
  end
221
218
 
222
219
  it "id can be nil" do
223
- @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", LogMessage::SourceType::CLOUD_CONTROLLER)
220
+ @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "API")
224
221
  expect(emit_message.source_id).to eq nil
225
222
  end
226
223
 
227
224
  it "id can be passed in as a string" do
228
- @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", LogMessage::SourceType::CLOUD_CONTROLLER, "some_source_id")
225
+ @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "API", "some_source_id")
229
226
  expect(emit_message.source_id).to eq "some_source_id"
230
227
  end
231
228
 
232
229
  it "id can be passed in as an integer" do
233
- @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", LogMessage::SourceType::CLOUD_CONTROLLER, 13)
230
+ @emitter = LoggregatorEmitter::Emitter.new("0.0.0.0:#{@free_port}", "API", 13)
234
231
  expect(emit_message.source_id).to eq "13"
235
232
  end
236
233
  end
@@ -8,8 +8,7 @@ describe LogMessage do
8
8
  {
9
9
  :message => "thesearebytes",
10
10
  :message_type => 1,
11
- :timestamp => 3,
12
- :source_type => "UAA"
11
+ :timestamp => 3
13
12
  })
14
13
 
15
14
  expect(msg.message_type_name).to eq("STDOUT")
@@ -20,8 +19,7 @@ describe LogMessage do
20
19
  {
21
20
  :message => "thesearebytes",
22
21
  :message_type => 2,
23
- :timestamp => 3,
24
- :source_type => "UAA"
22
+ :timestamp => 3
25
23
  })
26
24
 
27
25
  expect(msg.message_type_name).to eq("STDERR")
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: 2.0.3
4
+ version: 3.0.0
5
5
  prerelease:
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-12-02 00:00:00.000000000 Z
12
+ date: 2013-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beefcake
@@ -119,6 +119,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - - ! '>='
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
+ segments:
123
+ - 0
124
+ hash: -622288572178698844
122
125
  requirements: []
123
126
  rubyforge_project:
124
127
  rubygems_version: 1.8.25