lens 0.0.8 → 0.0.8.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f53e7ccbbdcf3542df1c431b9b2828a0b0cddf0f
4
- data.tar.gz: 4db30bce59f39de4ec90c001a1fd5d2daa440600
3
+ metadata.gz: ffe1d6b48785a27208d3177a2f133181419c0033
4
+ data.tar.gz: 0f0126706efa0927f5db3acc5965c7cf8d8d1f90
5
5
  SHA512:
6
- metadata.gz: 3d976fb595a8841b07e831ec104f6996e6a2bba697e8c5eb35f776b2b4df0f6519110235313d6283a4c8496e16a37509f45b8f2868c853505043b21a97d233ad
7
- data.tar.gz: 16e632fe26c3bff34d85bb0bfd03722e1e4a38c8aef76e931fef8a4ea6ef48d2cf2054ffd9894cbe06e712caeecf5b2769fc38a0a1b648a1077562062666c1b7
6
+ metadata.gz: d314b6a59368d6d861ce8af3b2d4077a278d785c4226ec147e7855057c2996a2a438d00501da0fcd796b011135ca7fa4abd07e02a2a21d844adb49685ae4c9d7
7
+ data.tar.gz: 4feebcf5fa63e742c8b3db2996baf7f47b8ad8c5cb8b3cd82b5ebef074440ed8f52b82fbc23134cd1a783cf6e7eac6bd52369c637cf6f6105bd07ca4694dac29
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  Add to your Gemfile
10
10
 
11
11
  ```ruby
12
- gem 'lens', '~> 0.0.7'
12
+ gem 'lens', '~> 0.0.8'
13
13
  ```
14
14
 
15
15
  or, if you want bleeding edge,
@@ -25,6 +25,14 @@ gem 'lens', github: 'lenshq/lens_client'
25
25
  * Configure Lens client (sample config below)
26
26
  * Start sending your data to Lens =]
27
27
 
28
+ ```ruby
29
+ # config/initializers/lens.rb
30
+ Lens.configure do |config|
31
+ config.app_key = 'super_secret_key'
32
+ end
33
+ ```
34
+
35
+ if you want to use Lens server at your instance
28
36
  ```ruby
29
37
  # config/initializers/lens.rb
30
38
  Lens.configure do |config|
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+
3
+ dir_config('lens_memprof')
4
+ create_makefile('lens_memprof')
@@ -0,0 +1,75 @@
1
+ #include "ruby.h"
2
+ #include "ruby/intern.h"
3
+
4
+ /*
5
+ * Debugger for VALUE
6
+ *
7
+ static void d(VALUE v) {
8
+ ID sym_puts = rb_intern("puts");
9
+ ID sym_inspect = rb_intern("inspect");
10
+ rb_funcall(rb_mKernel, sym_puts, 1, rb_funcall(v, sym_inspect, 0));
11
+ }
12
+ */
13
+
14
+ /*
15
+ * Count of RUBY_INTERNAL_EVENT_NEWOBJ events
16
+ * */
17
+ typedef struct lens_allocations_struct {
18
+ uint64_t count;
19
+ } lens_allocations_t;
20
+
21
+ /*
22
+ * Use TLS for storing allocations info
23
+ * More info: https://gcc.gnu.org/onlinedocs/gcc-3.4.1/gcc/Thread-Local.html
24
+ * */
25
+ static __thread lens_allocations_t lens_allocations;
26
+
27
+ static inline lens_allocations_t* allocations() { return &lens_allocations; }
28
+
29
+ void lens_memory_increment(rb_event_flag_t flag, VALUE node, VALUE self, ID mid, VALUE klass) {
30
+ (void)(flag); (void)(node); (void)(self); (void)(mid); (void)(klass);
31
+ allocations()->count++;
32
+ }
33
+
34
+ void lens_activate_memprof() {
35
+ rb_add_event_hook(lens_memory_increment, RUBY_INTERNAL_EVENT_NEWOBJ, Qnil);
36
+ }
37
+
38
+ void lens_deactivate_memprof() {
39
+ rb_remove_event_hook(lens_memory_increment);
40
+ }
41
+
42
+ static VALUE start() {
43
+ lens_activate_memprof();
44
+ return Qnil;
45
+ }
46
+
47
+ static VALUE stop() {
48
+ lens_deactivate_memprof();
49
+ return Qnil;
50
+ }
51
+
52
+ static VALUE reset() {
53
+ allocations()->count = 0;
54
+ return Qnil;
55
+ }
56
+
57
+ /*
58
+ * Initialize on require
59
+ * */
60
+ void Init_lens_memprof();
61
+ VALUE get_allocations_count(VALUE self);
62
+
63
+ void Init_lens_memprof()
64
+ {
65
+ VALUE CMemProf = rb_define_module("LensCMemprof");
66
+ rb_define_method(CMemProf, "allocations", get_allocations_count, 0);
67
+ rb_define_method(CMemProf, "start", start, 0);
68
+ rb_define_method(CMemProf, "reset", reset, 0);
69
+ rb_define_method(CMemProf, "stop", stop, 0);
70
+ }
71
+
72
+ VALUE get_allocations_count(VALUE self)
73
+ {
74
+ return UINT2NUM(allocations()->count);
75
+ }
data/lib/lens/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lens
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.8.2"
3
3
  end
data/lib/lens.rb CHANGED
@@ -4,6 +4,7 @@ raise 'WTF!?!?! Where is Rails man? ❨╯°□°❩╯︵┻━┻' unless defi
4
4
 
5
5
  require 'lens/core'
6
6
  require 'lens/railtie'
7
+ require 'lens_memprof'
7
8
 
8
9
  module Lens
9
10
  class << self
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.8.2
5
5
  platform: ruby
6
6
  authors:
7
+ - zzet
7
8
  - kgorin
8
9
  - artygus
9
- - zzet
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-19 00:00:00.000000000 Z
13
+ date: 2015-12-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: lz4-ruby
@@ -110,24 +110,33 @@ dependencies:
110
110
  - - ~>
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rake-compiler
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
113
127
  description:
114
128
  email:
129
+ - me@zzet.org
115
130
  - me@kgor.in
116
131
  - artygus@engineeram.net
117
- - me@zzet.org
118
132
  executables: []
119
- extensions: []
133
+ extensions:
134
+ - ext/lens_memprof/extconf.rb
120
135
  extra_rdoc_files: []
121
136
  files:
122
- - .gitignore
123
- - .hound.yml
124
- - .rubocop.yml
125
- - .travis.yml
126
- - Gemfile
127
- - LICENSE.txt
128
137
  - README.md
129
- - Rakefile
130
- - lens.gemspec
138
+ - ext/lens_memprof/extconf.rb
139
+ - ext/lens_memprof/lens_memprof.c
131
140
  - lib/lens.rb
132
141
  - lib/lens/allocations_data.rb
133
142
  - lib/lens/compression.rb
@@ -143,13 +152,6 @@ files:
143
152
  - lib/lens/trace.rb
144
153
  - lib/lens/version.rb
145
154
  - lib/lens/worker.rb
146
- - spec/lens/event_formatter_spec.rb
147
- - spec/lens/lens_spec.rb
148
- - spec/lens/sender_spec.rb
149
- - spec/lens/trace_spec.rb
150
- - spec/lens/worker_spec.rb
151
- - spec/spec_helper.rb
152
- - spec/support/helpers.rb
153
155
  homepage: https://github.com/lenshq/lens_client
154
156
  licenses:
155
157
  - MIT
@@ -174,12 +176,5 @@ rubygems_version: 2.0.14
174
176
  signing_key:
175
177
  specification_version: 4
176
178
  summary: Gem to send Rails request stats
177
- test_files:
178
- - spec/lens/event_formatter_spec.rb
179
- - spec/lens/lens_spec.rb
180
- - spec/lens/sender_spec.rb
181
- - spec/lens/trace_spec.rb
182
- - spec/lens/worker_spec.rb
183
- - spec/spec_helper.rb
184
- - spec/support/helpers.rb
179
+ test_files: []
185
180
  has_rdoc:
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- *.gem
2
- *.swp
3
- *.swo
4
- coverage
5
- /Gemfile.lock
data/.hound.yml DELETED
@@ -1,2 +0,0 @@
1
- ruby:
2
- config_file: .rubocop.yml
data/.rubocop.yml DELETED
@@ -1,237 +0,0 @@
1
- AllCops:
2
- Exclude:
3
- - "vendor/**/*"
4
- - "db/schema.rb"
5
- - "spec/*_helper.rb"
6
- - "bin/*"
7
- UseCache: false
8
- Style/CollectionMethods:
9
- Description: Preferred collection methods.
10
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
11
- Enabled: true
12
- PreferredMethods:
13
- collect: map
14
- collect!: map!
15
- find: detect
16
- find_all: select
17
- reduce: inject
18
- Style/DotPosition:
19
- Description: Checks the position of the dot in multi-line method calls.
20
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
21
- Enabled: true
22
- EnforcedStyle: leading
23
- SupportedStyles:
24
- - leading
25
- - trailing
26
- Style/FileName:
27
- Description: Use snake_case for source file names.
28
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
29
- Enabled: false
30
- Exclude: []
31
- Style/GuardClause:
32
- Description: Check for conditionals that can be replaced with guard clauses
33
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
34
- Enabled: true
35
- MinBodyLength: 5
36
- Style/IfUnlessModifier:
37
- Description: Favor modifier if/unless usage when you have a single-line body.
38
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
39
- Enabled: true
40
- MaxLineLength: 100
41
- Style/OptionHash:
42
- Description: Don't use option hashes when you can use keyword arguments.
43
- Enabled: false
44
- Style/PercentLiteralDelimiters:
45
- Description: Use `%`-literal delimiters consistently
46
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
47
- Enabled: false
48
- PreferredDelimiters:
49
- "%": "()"
50
- "%i": "()"
51
- "%q": "()"
52
- "%Q": "()"
53
- "%r": "{}"
54
- "%s": "()"
55
- "%w": "()"
56
- "%W": "()"
57
- "%x": "()"
58
- Style/PredicateName:
59
- Description: Check the names of predicate methods.
60
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
61
- Enabled: true
62
- NamePrefix:
63
- - is_
64
- - has_
65
- - have_
66
- NamePrefixBlacklist:
67
- - is_
68
- Exclude:
69
- - spec/**/*
70
- Style/RaiseArgs:
71
- Description: Checks the arguments passed to raise/fail.
72
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
73
- Enabled: false
74
- EnforcedStyle: exploded
75
- SupportedStyles:
76
- - compact
77
- - exploded
78
- Style/SignalException:
79
- Description: Checks for proper usage of fail and raise.
80
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
81
- Enabled: false
82
- EnforcedStyle: semantic
83
- SupportedStyles:
84
- - only_raise
85
- - only_fail
86
- - semantic
87
- Style/SingleLineBlockParams:
88
- Description: Enforces the names of some block params.
89
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
90
- Enabled: false
91
- Methods:
92
- - reduce:
93
- - a
94
- - e
95
- - inject:
96
- - a
97
- - e
98
- Style/SingleLineMethods:
99
- Description: Avoid single-line methods.
100
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
101
- Enabled: true
102
- AllowIfMethodIsEmpty: true
103
- Style/StringLiterals:
104
- Description: Checks if uses of quotes match the configured preference.
105
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
106
- Enabled: true
107
- EnforcedStyle: single_quotes
108
- SupportedStyles:
109
- - single_quotes
110
- - double_quotes
111
- Style/StringLiteralsInInterpolation:
112
- Description: Checks if uses of quotes inside expressions in interpolated strings
113
- match the configured preference.
114
- Enabled: true
115
- EnforcedStyle: single_quotes
116
- SupportedStyles:
117
- - single_quotes
118
- - double_quotes
119
- Style/TrailingComma:
120
- Description: Checks for trailing comma in parameter lists and literals.
121
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
122
- Enabled: true
123
- EnforcedStyleForMultiline: no_comma
124
- SupportedStyles:
125
- - comma
126
- - no_comma
127
- Metrics/LineLength:
128
- Max: 100
129
- Metrics/AbcSize:
130
- Description: A calculated magnitude based on number of assignments, branches, and
131
- conditions.
132
- Enabled: false
133
- Max: 15
134
- Metrics/ClassLength:
135
- Description: Avoid classes longer than 100 lines of code.
136
- Enabled: false
137
- CountComments: false
138
- Max: 100
139
- Metrics/ModuleLength:
140
- CountComments: false
141
- Max: 100
142
- Description: Avoid modules longer than 100 lines of code.
143
- Enabled: false
144
- Metrics/CyclomaticComplexity:
145
- Description: A complexity metric that is strongly correlated to the number of test
146
- cases needed to validate a method.
147
- Enabled: false
148
- Max: 6
149
- Metrics/MethodLength:
150
- Description: Avoid methods longer than 10 lines of code.
151
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
152
- Enabled: true
153
- CountComments: false
154
- Max: 20
155
- Metrics/ParameterLists:
156
- Description: Avoid parameter lists longer than three or four parameters.
157
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
158
- Enabled: true
159
- Max: 5
160
- CountKeywordArgs: true
161
- Metrics/PerceivedComplexity:
162
- Description: A complexity metric geared towards measuring complexity for a human
163
- reader.
164
- Enabled: false
165
- Max: 7
166
- Lint/AssignmentInCondition:
167
- Description: Don't use assignment in conditions.
168
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
169
- Enabled: false
170
- AllowSafeAssignment: true
171
- Style/InlineComment:
172
- Description: Avoid inline comments.
173
- Enabled: false
174
- Style/AccessorMethodName:
175
- Description: Check the naming of accessor methods for get_/set_.
176
- Enabled: true
177
- Style/Alias:
178
- Description: Use alias_method instead of alias.
179
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
180
- Enabled: false
181
- Style/Documentation:
182
- Description: Document classes and non-namespace modules.
183
- Enabled: false
184
- Style/DoubleNegation:
185
- Description: Checks for uses of double negation (!!).
186
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
187
- Enabled: false
188
- Style/EachWithObject:
189
- Description: Prefer `each_with_object` over `inject` or `reduce`.
190
- Enabled: false
191
- Style/EmptyLiteral:
192
- Description: Prefer literals to Array.new/Hash.new/String.new.
193
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
194
- Enabled: false
195
- Style/ModuleFunction:
196
- Description: Checks for usage of `extend self` in modules.
197
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
198
- Enabled: false
199
- Style/OneLineConditional:
200
- Description: Favor the ternary operator(?:) over if/then/else/end constructs.
201
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
202
- Enabled: false
203
- Style/PerlBackrefs:
204
- Description: Avoid Perl-style regex back references.
205
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
206
- Enabled: false
207
- Style/Send:
208
- Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
209
- may overlap with existing methods.
210
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
211
- Enabled: false
212
- Style/SpecialGlobalVars:
213
- Description: Avoid Perl-style global variables.
214
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
215
- Enabled: false
216
- Style/VariableInterpolation:
217
- Description: Don't interpolate global, instance and class variables directly in
218
- strings.
219
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
220
- Enabled: false
221
- Style/WhenThen:
222
- Description: Use when x then ... for one-line cases.
223
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
224
- Enabled: false
225
- Lint/EachWithObjectArgument:
226
- Description: Check for immutable argument given to each_with_object.
227
- Enabled: true
228
- Lint/HandleExceptions:
229
- Description: Don't suppress exception.
230
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
231
- Enabled: true
232
- Lint/LiteralInCondition:
233
- Description: Checks of literals used in conditions.
234
- Enabled: false
235
- Lint/LiteralInInterpolation:
236
- Description: Checks for literals used in interpolation.
237
- Enabled: false
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- sudo: false
4
- rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
8
- - 2.2.2
9
- - 2.2.3
10
- - ruby-head
11
- - jruby-19mode
12
- - jruby-head
13
- - rbx-2
14
- env:
15
- global:
16
- - JRUBY_OPTS="-J-Xmx1024M --debug"
17
- matrix:
18
- allow_failures:
19
- - rvm: jruby-19mode
20
- - rvm: jruby-head
21
- - rvm: rbx-2
22
- script: bundle exec rspec spec
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :test do
6
- gem 'simplecov', require: false
7
- gem 'codeclimate-test-reporter', require: false
8
- end
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2015 kgorin
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
data/lens.gemspec DELETED
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'lens/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'lens'
8
- spec.version = Lens::VERSION
9
- spec.authors = ['kgorin', 'artygus', 'zzet']
10
- spec.email = ['me@kgor.in', 'artygus@engineeram.net', 'me@zzet.org']
11
- spec.summary = %q{Gem to send Rails request stats}
12
- spec.homepage = 'https://github.com/lenshq/lens_client'
13
- spec.license = 'MIT'
14
-
15
- spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ['lib']
19
-
20
- spec.add_runtime_dependency 'lz4-ruby'
21
-
22
- spec.add_development_dependency 'bundler', '~> 1.6'
23
- spec.add_development_dependency 'rails', '>= 3.0'
24
- spec.add_development_dependency 'rake', '~> 0'
25
- spec.add_development_dependency 'rspec', '~> 3.2'
26
- spec.add_development_dependency 'pry', '~> 0.10'
27
- spec.add_development_dependency 'pry-nav', '~> 0'
28
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lens::EventFormatter do
4
- let(:event) { double(
5
- payload: {},
6
- duration: 2.33,
7
- time: Time.now - 2.seconds,
8
- end: Time.now,
9
- name: 'dummy.name')
10
- }
11
- let(:records) { [] }
12
- let(:formatter) { Lens::EventFormatter.new(event, records) }
13
-
14
- describe "#formatted" do
15
- subject { formatter.formatted }
16
-
17
- it "returns hash" do
18
- expect(subject).to be_a(Hash)
19
- end
20
-
21
- it "has data key" do
22
- expect(subject).to have_key(:data)
23
- end
24
-
25
- it "data key is not empty" do
26
- expect(subject[:data]).to_not be_empty
27
- end
28
-
29
- it "required fields are present" do
30
- required_keys = [:action, :controller, :params, :method, :url, :records, :time, :duration]
31
- expect(required_keys - subject[:data].keys).to be_empty
32
- end
33
- end
34
- end
@@ -1,105 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/helpers'
3
-
4
- describe Lens do
5
- describe '.configure' do
6
- context 'when user params' do
7
- let(:params) do
8
- {
9
- app_key: 'secret-key',
10
- protocol: 'https',
11
- host: 'example.com',
12
- port: 8080
13
- }
14
- end
15
- before { configure(params) }
16
- subject { described_class.configuration }
17
-
18
- it { expect(subject.app_key).to eq params[:app_key] }
19
- it { expect(subject.protocol).to eq params[:protocol] }
20
- it { expect(subject.host).to eq params[:host] }
21
- it { expect(subject.port).to eq params[:port] }
22
- end
23
-
24
- context 'when default params' do
25
- describe 'compressor' do
26
- subject { described_class.configuration.compressor }
27
-
28
- it { is_expected.to respond_to :compress }
29
- it { is_expected.to be Lens::Compression::LZ4 }
30
- end
31
-
32
- describe 'configuration' do
33
- subject { described_class.configuration }
34
-
35
- it { expect(subject.app_key).to eq nil }
36
- it { expect(subject.protocol).to eq 'http' }
37
- it { expect(subject.host).to eq 'lenshq.io' }
38
- it { expect(subject.port).to eq 80 }
39
- end
40
- end
41
- end
42
-
43
- describe '.start' do
44
- context 'without configuration' do
45
- subject { described_class.start }
46
-
47
- it { expect { subject }.to raise_error Lens::ConfigurationError }
48
- end
49
-
50
- context 'with configuration' do
51
- let(:params) { { app_key: 'some_key' } }
52
-
53
- around(:example) do |example|
54
- configure(params)
55
- described_class.start
56
-
57
- example.run
58
-
59
- described_class.stop
60
- end
61
-
62
- it 'client has been started properly' do
63
- expect(Lens::Worker.running?).to be_truthy
64
- end
65
- end
66
- end
67
-
68
- describe '.stop' do
69
- context 'not running' do
70
- it 'client has been stopped properly' do
71
- expect(Lens::Worker.running?).to be_falsey
72
- described_class.stop
73
- expect(Lens::Worker.running?).to be_falsey
74
- end
75
- end
76
-
77
- context 'running' do
78
- let(:params) { { app_key: 'some_key' } }
79
-
80
- around(:example) do |example|
81
- configure(params)
82
- described_class.start
83
-
84
- example.run
85
-
86
- described_class.stop
87
- end
88
-
89
- it 'client has been stopped properly' do
90
- expect(Lens::Worker.running?).to be_truthy
91
- described_class.stop
92
- expect(Lens::Worker.running?).to be_falsey
93
- end
94
- end
95
- end
96
- end
97
-
98
- def configure(params)
99
- described_class.configure do |config|
100
- config.app_key = params[:app_key] if params[:app_key].present?
101
- config.protocol = params[:protocol] if params[:protocol].present?
102
- config.host = params[:host] if params[:host].present?
103
- config.port = params[:port] if params[:port].present?
104
- end
105
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
- require 'support/helpers'
3
-
4
- describe Lens::Sender do
5
- before { Lens.configure { |config| config.app_key = 'app_key_123' } }
6
- let(:http) { stub_http }
7
-
8
- it "makes a single request when sending notices" do
9
- expect(http).to receive(:post).once
10
- Lens.sender.send_to_lens('abc123')
11
- end
12
- end
@@ -1,50 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Lens::Trace do
4
- describe '.process' do
5
- let(:first_event) { generate_event('start_processing.action_controller') }
6
- let(:last_event) { generate_event('process_action.action_controller') }
7
-
8
- context 'when first message' do
9
- before { described_class.process(first_event) }
10
-
11
- it 'creates new thread' do
12
- expect(described_class.present?).to be true
13
- end
14
- end
15
-
16
- context 'when last message' do
17
- before do
18
- Lens::Worker.start({})
19
- allow_any_instance_of(Lens::Worker).to receive :push
20
- end
21
-
22
- it 'kills thread' do
23
- described_class.process(first_event)
24
- expect(described_class.present?).to be true
25
-
26
- described_class.process(last_event)
27
- expect(described_class.present?).to be false
28
- end
29
-
30
- it 'pushes data to lens server' do
31
- expect_any_instance_of(Lens::Worker).to receive :push
32
- described_class.process(first_event)
33
- described_class.process(last_event)
34
- end
35
- end
36
- end
37
- end
38
-
39
- def generate_event(name = 'event_name')
40
- Lens::Event.new(
41
- name: name,
42
- started: Time.current,
43
- finished: Time.current,
44
- transaction_id: 1,
45
- payload: {
46
- controller: 'controller',
47
- action: 'action'
48
- }
49
- )
50
- end
@@ -1,119 +0,0 @@
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 DELETED
@@ -1,32 +0,0 @@
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
-
11
- require 'rspec'
12
- require 'rails'
13
- require 'lens'
14
-
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
26
-
27
- config.include Helpers
28
-
29
- config.profile_examples = 3
30
- config.order = :random
31
- Kernel.srand config.seed
32
- end
@@ -1,16 +0,0 @@
1
- module Helpers
2
- def stub_http(options = {})
3
- response = options[:response] || Net::HTTPSuccess.new('1.2', '200', 'OK')
4
- allow(response).to receive(:body).with(options[:body] || '{"id":"1234"}')
5
- http = double(
6
- :post => response,
7
- :read_timeout= => nil,
8
- :open_timeout= => nil,
9
- :ca_file= => nil,
10
- :verify_mode= => nil,
11
- :use_ssl= => nil
12
- )
13
- allow(Net::HTTP).to receive(:new).and_return(http)
14
- http
15
- end
16
- end