lens 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.hound.yml +2 -0
- data/.rubocop.yml +237 -0
- data/.travis.yml +22 -0
- data/Gemfile +5 -1
- data/README.md +27 -20
- data/lens.gemspec +12 -11
- data/lib/lens/allocations_data.rb +52 -0
- data/lib/lens/compression.rb +13 -0
- data/lib/lens/configuration.rb +12 -2
- data/lib/lens/core.rb +12 -11
- data/lib/lens/event.rb +27 -0
- data/lib/lens/event_formatter.rb +34 -5
- data/lib/lens/exceptions.rb +3 -0
- data/lib/lens/gc.rb +30 -0
- data/lib/lens/gzip_util.rb +12 -0
- data/lib/lens/railtie.rb +11 -21
- data/lib/lens/sender.rb +29 -48
- data/lib/lens/trace.rb +44 -14
- data/lib/lens/version.rb +1 -1
- data/lib/lens/worker.rb +138 -0
- data/lib/lens.rb +17 -10
- data/spec/lens/event_formatter_spec.rb +7 -1
- data/spec/lens/lens_spec.rb +105 -0
- data/spec/lens/sender_spec.rb +2 -3
- data/spec/lens/trace_spec.rb +50 -0
- data/spec/lens/worker_spec.rb +119 -0
- data/spec/spec_helper.rb +26 -6
- data/spec/support/helpers.rb +2 -10
- metadata +47 -17
- data/Gemfile.lock +0 -112
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lens::Worker do
|
4
|
+
let(:worker) { Lens::Worker.new({}) }
|
5
|
+
before { Lens::Worker.start({}) }
|
6
|
+
after { Lens::Worker.stop }
|
7
|
+
|
8
|
+
describe '.start' do
|
9
|
+
it 'creates thread' do
|
10
|
+
Lens::Worker.stop
|
11
|
+
expect(Lens::Worker.instance).to be nil
|
12
|
+
|
13
|
+
Lens::Worker.start({})
|
14
|
+
expect(Lens::Worker.instance).to be_truthy
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when started twice' do
|
18
|
+
it 'creates thread' do
|
19
|
+
Lens::Worker.stop
|
20
|
+
expect(Lens::Worker.instance).to be nil
|
21
|
+
|
22
|
+
Lens::Worker.start({})
|
23
|
+
first_instance = Lens::Worker.instance
|
24
|
+
Lens::Worker.start({})
|
25
|
+
expect(Lens::Worker.instance).to eq first_instance
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.stop' do
|
31
|
+
before { Lens::Worker.start({}) }
|
32
|
+
|
33
|
+
it 'sets running? to false' do
|
34
|
+
Lens::Worker.stop(force: true)
|
35
|
+
expect(Lens::Worker.running?).to be false
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when forced' do
|
39
|
+
it 'calls forced stop' do
|
40
|
+
expect_any_instance_of(Lens::Worker).to receive :shutdown!
|
41
|
+
Lens::Worker.stop(force: true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when graceful' do
|
46
|
+
it 'calls graceful stop' do
|
47
|
+
expect_any_instance_of(Lens::Worker).to receive :shutdown
|
48
|
+
Lens::Worker.stop
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when stopped twice' do
|
53
|
+
it 'doesnt raise errors' do
|
54
|
+
2.times { Lens::Worker.stop }
|
55
|
+
expect { Lens::Worker }.not_to raise_error
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#process' do
|
61
|
+
let(:sender) { spy }
|
62
|
+
|
63
|
+
before do
|
64
|
+
Lens.sender = sender
|
65
|
+
worker.start
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'sends data to lens' do
|
69
|
+
worker.process({})
|
70
|
+
expect(sender).to have_received :send_to_lens
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#shutdown!' do
|
75
|
+
it 'kills thread thread immediately' do
|
76
|
+
worker.start
|
77
|
+
expect(worker.thread).to be_truthy
|
78
|
+
|
79
|
+
worker.shutdown!
|
80
|
+
expect(worker.thread.stop?).to be true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#shutdown' do
|
85
|
+
it 'kills thread thread' do
|
86
|
+
worker.start
|
87
|
+
expect(worker.thread).to be_truthy
|
88
|
+
|
89
|
+
worker.shutdown
|
90
|
+
expect(worker.thread.stop?).to be true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '.push' do
|
95
|
+
let(:sender) { spy }
|
96
|
+
subject { described_class.instance.queue.length }
|
97
|
+
|
98
|
+
before do
|
99
|
+
Lens.sender = sender
|
100
|
+
worker.start
|
101
|
+
2.times { described_class.instance.push({}) }
|
102
|
+
end
|
103
|
+
|
104
|
+
it { is_expected.to eq 2 }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe Lens::Worker::Queue do
|
109
|
+
let(:queue) { described_class.new(max_size: 1) }
|
110
|
+
|
111
|
+
describe '#push' do
|
112
|
+
context 'when queue is full' do
|
113
|
+
before { 2.times { queue.push({}) } }
|
114
|
+
subject { queue.length }
|
115
|
+
|
116
|
+
it { is_expected.to eq 1 }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
|
+
if ENV['COVERAGE']
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
end
|
5
|
+
|
6
|
+
if ENV['CI']
|
7
|
+
require 'codeclimate-test-reporter'
|
8
|
+
CodeClimate::TestReporter.start
|
9
|
+
end
|
10
|
+
|
1
11
|
require 'rspec'
|
12
|
+
require 'rails'
|
2
13
|
require 'lens'
|
3
14
|
|
4
|
-
Dir[File.expand_path('../../spec/support/**/*.rb', __FILE__)].each {|f| require f}
|
15
|
+
Dir[File.expand_path('../../spec/support/**/*.rb', __FILE__)].each { |f| require f }
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.after :each do
|
19
|
+
Lens.stop
|
20
|
+
Lens.configuration = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
config.mock_with :rspec
|
24
|
+
config.color = true
|
25
|
+
config.run_all_when_everything_filtered = true
|
5
26
|
|
6
|
-
|
7
|
-
c.mock_with :rspec
|
8
|
-
c.color = true
|
9
|
-
c.run_all_when_everything_filtered = true
|
27
|
+
config.include Helpers
|
10
28
|
|
11
|
-
|
29
|
+
config.profile_examples = 3
|
30
|
+
config.order = :random
|
31
|
+
Kernel.srand config.seed
|
12
32
|
end
|
data/spec/support/helpers.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Helpers
|
2
2
|
def stub_http(options = {})
|
3
3
|
response = options[:response] || Net::HTTPSuccess.new('1.2', '200', 'OK')
|
4
|
-
response.
|
4
|
+
allow(response).to receive(:body).with(options[:body] || '{"id":"1234"}')
|
5
5
|
http = double(
|
6
6
|
:post => response,
|
7
7
|
:read_timeout= => nil,
|
@@ -10,15 +10,7 @@ module Helpers
|
|
10
10
|
:verify_mode= => nil,
|
11
11
|
:use_ssl= => nil
|
12
12
|
)
|
13
|
-
Net::HTTP.
|
13
|
+
allow(Net::HTTP).to receive(:new).and_return(http)
|
14
14
|
http
|
15
15
|
end
|
16
|
-
|
17
|
-
def reset_config
|
18
|
-
Lens.configuration = nil
|
19
|
-
Lens.configure do |config|
|
20
|
-
config.app_key = 'app_key_123'
|
21
|
-
config.secret = 'abc123'
|
22
|
-
end
|
23
|
-
end
|
24
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kgorin
|
@@ -10,76 +10,90 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '1.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.6'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rails
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '3.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '3.0'
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: rake
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
32
46
|
requirements:
|
33
|
-
- -
|
47
|
+
- - ~>
|
34
48
|
- !ruby/object:Gem::Version
|
35
49
|
version: '0'
|
36
50
|
type: :development
|
37
51
|
prerelease: false
|
38
52
|
version_requirements: !ruby/object:Gem::Requirement
|
39
53
|
requirements:
|
40
|
-
- -
|
54
|
+
- - ~>
|
41
55
|
- !ruby/object:Gem::Version
|
42
56
|
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rspec
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
46
60
|
requirements:
|
47
|
-
- -
|
61
|
+
- - ~>
|
48
62
|
- !ruby/object:Gem::Version
|
49
63
|
version: '3.2'
|
50
64
|
type: :development
|
51
65
|
prerelease: false
|
52
66
|
version_requirements: !ruby/object:Gem::Requirement
|
53
67
|
requirements:
|
54
|
-
- -
|
68
|
+
- - ~>
|
55
69
|
- !ruby/object:Gem::Version
|
56
70
|
version: '3.2'
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
72
|
name: pry
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
60
74
|
requirements:
|
61
|
-
- -
|
75
|
+
- - ~>
|
62
76
|
- !ruby/object:Gem::Version
|
63
77
|
version: '0.10'
|
64
78
|
type: :development
|
65
79
|
prerelease: false
|
66
80
|
version_requirements: !ruby/object:Gem::Requirement
|
67
81
|
requirements:
|
68
|
-
- -
|
82
|
+
- - ~>
|
69
83
|
- !ruby/object:Gem::Version
|
70
84
|
version: '0.10'
|
71
85
|
- !ruby/object:Gem::Dependency
|
72
86
|
name: pry-nav
|
73
87
|
requirement: !ruby/object:Gem::Requirement
|
74
88
|
requirements:
|
75
|
-
- -
|
89
|
+
- - ~>
|
76
90
|
- !ruby/object:Gem::Version
|
77
91
|
version: '0'
|
78
92
|
type: :development
|
79
93
|
prerelease: false
|
80
94
|
version_requirements: !ruby/object:Gem::Requirement
|
81
95
|
requirements:
|
82
|
-
- -
|
96
|
+
- - ~>
|
83
97
|
- !ruby/object:Gem::Version
|
84
98
|
version: '0'
|
85
99
|
description:
|
@@ -91,23 +105,35 @@ executables: []
|
|
91
105
|
extensions: []
|
92
106
|
extra_rdoc_files: []
|
93
107
|
files:
|
94
|
-
-
|
108
|
+
- .gitignore
|
109
|
+
- .hound.yml
|
110
|
+
- .rubocop.yml
|
111
|
+
- .travis.yml
|
95
112
|
- Gemfile
|
96
|
-
- Gemfile.lock
|
97
113
|
- LICENSE.txt
|
98
114
|
- README.md
|
99
115
|
- Rakefile
|
100
116
|
- lens.gemspec
|
101
117
|
- lib/lens.rb
|
118
|
+
- lib/lens/allocations_data.rb
|
119
|
+
- lib/lens/compression.rb
|
102
120
|
- lib/lens/configuration.rb
|
103
121
|
- lib/lens/core.rb
|
122
|
+
- lib/lens/event.rb
|
104
123
|
- lib/lens/event_formatter.rb
|
124
|
+
- lib/lens/exceptions.rb
|
125
|
+
- lib/lens/gc.rb
|
126
|
+
- lib/lens/gzip_util.rb
|
105
127
|
- lib/lens/railtie.rb
|
106
128
|
- lib/lens/sender.rb
|
107
129
|
- lib/lens/trace.rb
|
108
130
|
- lib/lens/version.rb
|
131
|
+
- lib/lens/worker.rb
|
109
132
|
- spec/lens/event_formatter_spec.rb
|
133
|
+
- spec/lens/lens_spec.rb
|
110
134
|
- spec/lens/sender_spec.rb
|
135
|
+
- spec/lens/trace_spec.rb
|
136
|
+
- spec/lens/worker_spec.rb
|
111
137
|
- spec/spec_helper.rb
|
112
138
|
- spec/support/helpers.rb
|
113
139
|
homepage: https://github.com/lenshq/lens_client
|
@@ -120,22 +146,26 @@ require_paths:
|
|
120
146
|
- lib
|
121
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
148
|
requirements:
|
123
|
-
- -
|
149
|
+
- - '>='
|
124
150
|
- !ruby/object:Gem::Version
|
125
151
|
version: '0'
|
126
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
153
|
requirements:
|
128
|
-
- -
|
154
|
+
- - '>='
|
129
155
|
- !ruby/object:Gem::Version
|
130
156
|
version: '0'
|
131
157
|
requirements: []
|
132
158
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.0.14
|
134
160
|
signing_key:
|
135
161
|
specification_version: 4
|
136
162
|
summary: Gem to send Rails request stats
|
137
163
|
test_files:
|
138
164
|
- spec/lens/event_formatter_spec.rb
|
165
|
+
- spec/lens/lens_spec.rb
|
139
166
|
- spec/lens/sender_spec.rb
|
167
|
+
- spec/lens/trace_spec.rb
|
168
|
+
- spec/lens/worker_spec.rb
|
140
169
|
- spec/spec_helper.rb
|
141
170
|
- spec/support/helpers.rb
|
171
|
+
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
lens (0.0.5)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
actionmailer (4.0.3)
|
10
|
-
actionpack (= 4.0.3)
|
11
|
-
mail (~> 2.5.4)
|
12
|
-
actionpack (4.0.3)
|
13
|
-
activesupport (= 4.0.3)
|
14
|
-
builder (~> 3.1.0)
|
15
|
-
erubis (~> 2.7.0)
|
16
|
-
rack (~> 1.5.2)
|
17
|
-
rack-test (~> 0.6.2)
|
18
|
-
activemodel (4.0.3)
|
19
|
-
activesupport (= 4.0.3)
|
20
|
-
builder (~> 3.1.0)
|
21
|
-
activerecord (4.0.3)
|
22
|
-
activemodel (= 4.0.3)
|
23
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
24
|
-
activesupport (= 4.0.3)
|
25
|
-
arel (~> 4.0.0)
|
26
|
-
activerecord-deprecated_finders (1.0.3)
|
27
|
-
activesupport (4.0.3)
|
28
|
-
i18n (~> 0.6, >= 0.6.4)
|
29
|
-
minitest (~> 4.2)
|
30
|
-
multi_json (~> 1.3)
|
31
|
-
thread_safe (~> 0.1)
|
32
|
-
tzinfo (~> 0.3.37)
|
33
|
-
arel (4.0.2)
|
34
|
-
builder (3.1.4)
|
35
|
-
coderay (1.1.0)
|
36
|
-
diff-lcs (1.2.5)
|
37
|
-
erubis (2.7.0)
|
38
|
-
hike (1.2.3)
|
39
|
-
i18n (0.6.11)
|
40
|
-
mail (2.5.4)
|
41
|
-
mime-types (~> 1.16)
|
42
|
-
treetop (~> 1.4.8)
|
43
|
-
method_source (0.8.2)
|
44
|
-
mime-types (1.25.1)
|
45
|
-
minitest (4.7.5)
|
46
|
-
multi_json (1.11.0)
|
47
|
-
polyglot (0.3.5)
|
48
|
-
pry (0.10.1)
|
49
|
-
coderay (~> 1.1.0)
|
50
|
-
method_source (~> 0.8.1)
|
51
|
-
slop (~> 3.4)
|
52
|
-
pry-nav (0.2.4)
|
53
|
-
pry (>= 0.9.10, < 0.11.0)
|
54
|
-
rack (1.5.2)
|
55
|
-
rack-test (0.6.2)
|
56
|
-
rack (>= 1.0)
|
57
|
-
rails (4.0.3)
|
58
|
-
actionmailer (= 4.0.3)
|
59
|
-
actionpack (= 4.0.3)
|
60
|
-
activerecord (= 4.0.3)
|
61
|
-
activesupport (= 4.0.3)
|
62
|
-
bundler (>= 1.3.0, < 2.0)
|
63
|
-
railties (= 4.0.3)
|
64
|
-
sprockets-rails (~> 2.0.0)
|
65
|
-
railties (4.0.3)
|
66
|
-
actionpack (= 4.0.3)
|
67
|
-
activesupport (= 4.0.3)
|
68
|
-
rake (>= 0.8.7)
|
69
|
-
thor (>= 0.18.1, < 2.0)
|
70
|
-
rake (0.9.6)
|
71
|
-
rspec (3.2.0)
|
72
|
-
rspec-core (~> 3.2.0)
|
73
|
-
rspec-expectations (~> 3.2.0)
|
74
|
-
rspec-mocks (~> 3.2.0)
|
75
|
-
rspec-core (3.2.3)
|
76
|
-
rspec-support (~> 3.2.0)
|
77
|
-
rspec-expectations (3.2.1)
|
78
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
-
rspec-support (~> 3.2.0)
|
80
|
-
rspec-mocks (3.2.1)
|
81
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
-
rspec-support (~> 3.2.0)
|
83
|
-
rspec-support (3.2.2)
|
84
|
-
slop (3.6.0)
|
85
|
-
sprockets (2.11.0)
|
86
|
-
hike (~> 1.2)
|
87
|
-
multi_json (~> 1.0)
|
88
|
-
rack (~> 1.0)
|
89
|
-
tilt (~> 1.1, != 1.3.0)
|
90
|
-
sprockets-rails (2.0.1)
|
91
|
-
actionpack (>= 3.0)
|
92
|
-
activesupport (>= 3.0)
|
93
|
-
sprockets (~> 2.8)
|
94
|
-
thor (0.19.1)
|
95
|
-
thread_safe (0.3.4)
|
96
|
-
tilt (1.4.1)
|
97
|
-
treetop (1.4.15)
|
98
|
-
polyglot
|
99
|
-
polyglot (>= 0.3.1)
|
100
|
-
tzinfo (0.3.42)
|
101
|
-
|
102
|
-
PLATFORMS
|
103
|
-
ruby
|
104
|
-
|
105
|
-
DEPENDENCIES
|
106
|
-
bundler (~> 1.6)
|
107
|
-
lens!
|
108
|
-
pry (~> 0.10)
|
109
|
-
pry-nav (~> 0)
|
110
|
-
rails (>= 3.0)
|
111
|
-
rake (~> 0)
|
112
|
-
rspec (~> 3.2)
|