loggregator_emitter 0.0.2.pre → 0.0.3.pre

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .idea
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- loggregator_emitter (0.0.2.pre)
4
+ loggregator_emitter (0.0.3.pre)
5
5
  loggregator_messages (~> 0.0.1.pre)
6
6
 
7
7
  GEM
@@ -1,24 +1,42 @@
1
1
  require "loggregator_messages"
2
2
  require 'socket'
3
+ require "steno"
3
4
 
4
5
  module LoggregatorEmitter
6
+ class Emitter
7
+ def initialize(loggregator_server, source_type)
8
+ host, port = loggregator_server.split(":")
9
+ raise RuntimeError, "Must provid validate loggregator server: #{loggregator_server}" if (host == nil || port == nil)
10
+ @sockaddr_in = Socket.sockaddr_in(port, host)
5
11
 
6
- def self.emit(loggregator_server, target, message)
7
- s = UDPSocket.new
8
- s.do_not_reverse_lookup = true
9
- lm = LogMessage.new()
10
- lm.timestamp = Time.now.to_i
11
- lm.message = message
12
- lm.app_id = target.app_id
13
- lm.source_type = LogMessage::SourceType::DEA
14
- lm.message_type = LogMessage::MessageType::OUT
12
+ raise RuntimeError, "Must provide valid source type" unless valid_source_type?(source_type)
13
+ @source_type = source_type
14
+ end
15
15
 
16
- result = lm.encode.buf
17
- result.unpack("C*")
18
- host, port = loggregator_server.split(":")
16
+ def emit(target, message)
17
+ s = UDPSocket.new
18
+ s.do_not_reverse_lookup = true
19
+ lm = LogMessage.new()
20
+ lm.timestamp = Time.now.to_i
21
+ lm.message = message
22
+ lm.app_id = target.app_id
23
+ lm.source_type = @source_type
24
+ lm.message_type = LogMessage::MessageType::OUT
19
25
 
20
- s.sendmsg_nonblock(result, 0, Socket.sockaddr_in(port,host))
21
- rescue Errno::ENOENT => e
22
- # Just ignore it.
26
+ result = lm.encode.buf
27
+ result.unpack("C*")
28
+
29
+ s.sendmsg_nonblock(result, 0, @sockaddr_in)
30
+ end
31
+
32
+ private
33
+ def valid_source_type?(source_type)
34
+ LogMessage::SourceType.constants.each do |name|
35
+ if LogMessage::SourceType.const_get(name) == source_type
36
+ return true
37
+ end
38
+ end
39
+ false
40
+ end
23
41
  end
24
42
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "loggregator_emitter"
5
- spec.version = '0.0.2.pre'
5
+ spec.version = '0.0.3.pre'
6
6
  spec.authors = ["Pivotal"]
7
7
  spec.email = ["cf-eng@pivotallabs.com"]
8
8
  spec.description = "Library to emit data to Loggregator"
@@ -2,30 +2,53 @@ require 'support/fake_loggregator_server'
2
2
  require 'loggregator_emitter/emit'
3
3
  require 'loggregator_emitter/target'
4
4
 
5
- describe "Writing to Sockets" do
6
- let(:target) { LoggregatorEmitter::Target.new("appId") }
5
+ describe LoggregatorEmitter do
7
6
 
8
- it "successfully writes protobuffer to a socket" do
9
- server = FakeLoggregatorServer.new(12345)
10
- server.start
7
+ let(:target) { LoggregatorEmitter::Target.new('appId') }
11
8
 
12
- LoggregatorEmitter.emit('0.0.0.0:12345', target, "Hello there!")
13
- LoggregatorEmitter.emit('0.0.0.0:12345', target, "Hello again!")
9
+ describe 'configuring emitter' do
14
10
 
15
- server.stop(2)
11
+ it 'can be configured' do
12
+ expect { LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::DEA) }.not_to raise_error
13
+ end
16
14
 
17
- messages = server.messages
15
+ it 'raises if loggregator_server is invalid' do
16
+ expect { LoggregatorEmitter::Emitter.new('0.0.0.0', LogMessage::SourceType::DEA) }.to raise_error(RuntimeError)
17
+ end
18
18
 
19
- expect(messages.length).to eq 2
20
- message = messages[0]
21
- expect(message.message).to eq "Hello there!"
22
- expect(message.app_id).to eq target.app_id
19
+ it 'doesnt raise if source_type is valid' do
20
+ expect { LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::DEA) }.not_to raise_error
21
+ end
23
22
 
24
- message = messages[1]
25
- expect(message.message).to eq "Hello again!"
23
+ it 'raises if source_type is invalid' do
24
+ expect { LoggregatorEmitter::Emitter.new('0.0.0.0:12345', 40) }.to raise_error(RuntimeError)
25
+ end
26
26
  end
27
27
 
28
- it "continues to work if there is no server listening" do
29
- expect{LoggregatorEmitter.emit('0.0.0.0:12345', target, "Hello there!")}.not_to raise_error
28
+ describe 'Writing to Sockets' do
29
+ before(:each) do
30
+ @emitter = LoggregatorEmitter::Emitter.new('0.0.0.0:12345', LogMessage::SourceType::CLOUD_CONTROLLER)
31
+ end
32
+
33
+ it 'successfully writes protobuffer to a socket' do
34
+ server = FakeLoggregatorServer.new(12345)
35
+ server.start
36
+
37
+ @emitter.emit(target, 'Hello there!')
38
+ @emitter.emit(target, 'Hello again!')
39
+
40
+ server.stop(2)
41
+
42
+ messages = server.messages
43
+
44
+ expect(messages.length).to eq 2
45
+ message = messages[0]
46
+ expect(message.message).to eq 'Hello there!'
47
+ expect(message.app_id).to eq target.app_id
48
+ expect(message.source_type).to eq LogMessage::SourceType::CLOUD_CONTROLLER
49
+
50
+ message = messages[1]
51
+ expect(message.message).to eq 'Hello again!'
52
+ end
30
53
  end
31
54
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggregator_emitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.pre
4
+ version: 0.0.3.pre
5
+ prerelease: 6
5
6
  platform: ruby
6
7
  authors:
7
8
  - Pivotal
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-08-20 00:00:00.000000000 Z
12
+ date: 2013-08-27 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: loggregator_messages
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: bundler
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rake
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ~>
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rspec
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -89,26 +98,27 @@ files:
89
98
  homepage: https://www.github.com/cloudfoundry/loggregator_emitter
90
99
  licenses:
91
100
  - Apache 2.0
92
- metadata: {}
93
101
  post_install_message:
94
102
  rdoc_options: []
95
103
  require_paths:
96
104
  - lib
97
105
  required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
98
107
  requirements:
99
108
  - - ! '>='
100
109
  - !ruby/object:Gem::Version
101
110
  version: 1.9.3
102
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
103
113
  requirements:
104
114
  - - ! '>'
105
115
  - !ruby/object:Gem::Version
106
116
  version: 1.3.1
107
117
  requirements: []
108
118
  rubyforge_project:
109
- rubygems_version: 2.0.4
119
+ rubygems_version: 1.8.25
110
120
  signing_key:
111
- specification_version: 4
121
+ specification_version: 3
112
122
  summary: Library to emit data to Loggregator
113
123
  test_files:
114
124
  - spec/loggregator_emitter/emit_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OTRlMTA3ZmJhMGIyZGEyMzVjY2JjZWQ1ZjQ3NjQyOWM0ZGI5MTgzOA==
5
- data.tar.gz: !binary |-
6
- MDZkY2ViMDdlYTBhMzE3YmM3M2RhMDcxMTU4MjdjZDgyYWU1OGZmMA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MzkyYmE1NGZlNWMzN2Y0OTliYmQ2NTllYjI1MGY1ZmNhN2ZhMGMyMzAzNWRm
10
- Mjc2OWVhZmZmMjVlNmRjZWZhYjFiMTJmYTBjZjc4NjllNDU1MDVmYjYyMTdi
11
- YTdlODkyY2Q4ZDI0ZDQ2MWViZTI5N2ExMzYwN2ZkYjEwYTVlNTA=
12
- data.tar.gz: !binary |-
13
- NGY3ZmZlNDVjZDgwOGE3OWNlNmE1MzhjZTczNjM4Nzk5ZjUxZjdhNWM0YWM5
14
- YTYzNDc1ZGIzNzg4NmMyNDYzMTUxZDFjNzg5OGYwMTRmMWMxMjk5OGVlZTM5
15
- YjMxNGFjMjFmYTFlOGI5MDU1Mjk5ZWJkMGRmY2RhYzllOTczMjY=