logplex 0.0.1.pre.2 → 0.0.1.pre.3
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.
- data/README.md +4 -3
- data/lib/logplex/configuration.rb +6 -4
- data/lib/logplex/publisher.rb +13 -3
- data/lib/logplex/version.rb +1 -1
- data/spec/logplex/publisher_spec.rb +62 -22
- metadata +10 -10
data/README.md
CHANGED
@@ -41,9 +41,10 @@ You can configure default values for logplex message posting:
|
|
41
41
|
|
42
42
|
```ruby
|
43
43
|
Logplex.configure do |config|
|
44
|
-
config.logplex_url
|
45
|
-
config.process
|
46
|
-
config.host
|
44
|
+
config.logplex_url = 'https://logplex.example.com'
|
45
|
+
config.process = 'stats'
|
46
|
+
config.host = 'host'
|
47
|
+
config.publish_timeout = 2
|
47
48
|
end
|
48
49
|
```
|
49
50
|
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module Logplex
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :logplex_url,
|
4
|
-
|
5
|
-
|
4
|
+
:process,
|
5
|
+
:host,
|
6
|
+
:publish_timeout
|
6
7
|
|
7
8
|
def initialize
|
8
|
-
@logplex_url
|
9
|
-
@host
|
9
|
+
@logplex_url = 'https://east.logplex.io'
|
10
|
+
@host = 'localhost'
|
11
|
+
@publish_timeout = 1
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
data/lib/logplex/publisher.rb
CHANGED
@@ -2,9 +2,14 @@
|
|
2
2
|
require 'base64'
|
3
3
|
require 'restclient'
|
4
4
|
require 'logplex/message'
|
5
|
+
require 'timeout'
|
5
6
|
|
6
7
|
module Logplex
|
7
8
|
class Publisher
|
9
|
+
PUBLISH_ERRORS = [RestClient::InternalServerError,
|
10
|
+
RestClient::Unauthorized,
|
11
|
+
Timeout::Error].freeze
|
12
|
+
|
8
13
|
def initialize(token, logplex_url=nil)
|
9
14
|
@token = token
|
10
15
|
@logplex_url = logplex_url || Logplex.configuration.logplex_url
|
@@ -15,9 +20,14 @@ module Logplex
|
|
15
20
|
messages.map! { |m| Message.new(m, opts.merge(token: @token)) }
|
16
21
|
messages.each(&:validate)
|
17
22
|
if messages.inject(true) { |accum, m| m.valid? }
|
18
|
-
|
19
|
-
|
20
|
-
|
23
|
+
begin
|
24
|
+
Timeout::timeout(Logplex.configuration.publish_timeout) do
|
25
|
+
api_post(messages.map(&:syslog_frame).join(''))
|
26
|
+
true
|
27
|
+
end
|
28
|
+
rescue *PUBLISH_ERRORS
|
29
|
+
false
|
30
|
+
end
|
21
31
|
end
|
22
32
|
end
|
23
33
|
|
data/lib/logplex/version.rb
CHANGED
@@ -5,42 +5,82 @@ require 'support/fake_logplex'
|
|
5
5
|
|
6
6
|
describe Logplex::Publisher, '#publish' do
|
7
7
|
before do
|
8
|
-
ShamRack.mount(FakeLogplex.new, 'logplex.example.com', 443)
|
9
|
-
|
10
8
|
Logplex.configure do |config|
|
11
9
|
config.process = "postgres"
|
12
10
|
config.host = "host"
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
restore_default_config
|
20
|
-
end
|
14
|
+
context 'with a working logplex' do
|
15
|
+
before do
|
16
|
+
ShamRack.mount(FakeLogplex.new, 'logplex.example.com', 443)
|
21
17
|
|
22
|
-
|
23
|
-
FakeLogplex.register_token('t.some-token')
|
18
|
+
end
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
after do
|
21
|
+
ShamRack.unmount_all
|
22
|
+
FakeLogplex.clear!
|
23
|
+
restore_default_config
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
26
|
+
it 'encodes a message and publishes it' do
|
27
|
+
FakeLogplex.register_token('t.some-token')
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
message = 'I have a message for you'
|
30
|
+
publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
|
31
|
+
publisher.publish(message)
|
35
32
|
|
36
|
-
|
33
|
+
expect(FakeLogplex).to have_received_message(message)
|
34
|
+
end
|
37
35
|
|
38
|
-
|
36
|
+
it 'sends many messages in one request when passed an array' do
|
37
|
+
FakeLogplex.register_token('t.some-token')
|
38
|
+
messages = ['I have a message for you', 'here is another', 'some final thoughts']
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
|
41
|
+
|
42
|
+
publisher.publish(messages)
|
43
|
+
|
44
|
+
messages.each do |message|
|
45
|
+
expect(FakeLogplex).to have_received_message(message)
|
46
|
+
end
|
47
|
+
|
48
|
+
expect(FakeLogplex.requests_received).to eq(1)
|
42
49
|
end
|
43
50
|
|
44
|
-
|
51
|
+
it 'returns true' do
|
52
|
+
FakeLogplex.register_token('t.some-token')
|
53
|
+
|
54
|
+
message = 'I have a message for you'
|
55
|
+
publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
|
56
|
+
expect(publisher.publish(message)).to be_true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns false when there's an auth error" do
|
60
|
+
message = 'I have a message for you'
|
61
|
+
publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
|
62
|
+
expect(publisher.publish(message)).to be_false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when the logplex service is acting up' do
|
67
|
+
before do
|
68
|
+
ShamRack.at('logplex.example.com', 443) do
|
69
|
+
[500, {}, []]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
after { ShamRack.unmount_all }
|
74
|
+
|
75
|
+
it 'returns false' do
|
76
|
+
publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
|
77
|
+
expect(publisher.publish('hi')).to be_false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "handles timeouts" do
|
82
|
+
RestClient.stub(:post).and_raise Timeout::Error
|
83
|
+
publisher = Logplex::Publisher.new('t.some-token', 'https://logplex.example.com')
|
84
|
+
expect(publisher.publish('hi')).to be_false
|
45
85
|
end
|
46
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logplex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.3
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: valcro
|
16
|
-
requirement: &
|
16
|
+
requirement: &70108795420800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70108795420800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rest-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70108795449080 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70108795449080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70108795448440 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70108795448440
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sham_rack
|
49
|
-
requirement: &
|
49
|
+
requirement: &70108795447760 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70108795447760
|
58
58
|
description: Publish and Consume Logplex messages
|
59
59
|
email:
|
60
60
|
- harold.gimenez@gmail.com
|