metrician 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cf863462aef4c2b2425233de2c527f3b1286bdf
4
- data.tar.gz: 461a4cafdc0255467e2b7cbf9c236c49575a2a6b
3
+ metadata.gz: 52f0bb06f70b89a43c10dfdbbfa5b989c2dfad48
4
+ data.tar.gz: 61bc03ef7baf8a15640ed25e8608fe8c3481a8ce
5
5
  SHA512:
6
- metadata.gz: 8f98d615943e39c4f1257420c7bb7f301c9d3c9ecf25bdea95b6c4c083b9b4c63b85519218385b468240c550790f126b06d8355764d13f912d708d678e91ba37
7
- data.tar.gz: cf46b4c1638fd04ec00d3565e6650b511ea60e37b21edbfa38248ba796b06b9f00c42998903d36bba11928182427c45b823956bb88c9402ee328c20aee0a825f
6
+ metadata.gz: 865aa70211d3d49137d2b8e53b9b7568fea8b74299bed02bda52aa24b8a4ec4b8850e705a12b8ad63b92088d8aa486678eee465c685d55f09381ecc79f5b0809
7
+ data.tar.gz: 0af23a989d74ccbb153fd665d1bdac9c9eec041aafd7420050dcc139efde8712dcaead5b981340f0e36e485a9b4fb5b2d745aa1437642c5af0b6405aa6b81a6a
@@ -1,3 +1,6 @@
1
+ ### 0.0.8 [August 4, 2017]
2
+ * Integrate with memcached and dalli if both are available
3
+
1
4
  ### 0.0.7 [August 3, 2017]
2
5
  * Allow partial config files
3
6
  * Officially require Ruby 2
@@ -17,8 +17,11 @@ gem 'database_cleaner'
17
17
  gem 'delayed_job_active_record'
18
18
  gem 'resque'
19
19
  gem 'redis'
20
- gem 'memcached'
20
+ gem 'dalli', '~>2.6'
21
+ gem 'memcached', '~>1.7'
21
22
  gem 'rack-test'
23
+ gem 'simplecov', :require => false, :group => :test
24
+ gem 'honeybadger'
22
25
 
23
26
  # Gem under test
24
27
  gem 'metrician', :path => '..'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.7)
4
+ metrician (0.0.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -45,6 +45,7 @@ GEM
45
45
  byebug (9.0.6)
46
46
  concurrent-ruby (1.0.5)
47
47
  connection_pool (2.2.1)
48
+ dalli (2.7.6)
48
49
  database_cleaner (1.6.1)
49
50
  delayed_job (4.1.3)
50
51
  activesupport (>= 3.0, < 5.2)
@@ -52,12 +53,15 @@ GEM
52
53
  activerecord (>= 3.0, < 5.2)
53
54
  delayed_job (>= 3.0, < 5)
54
55
  diff-lcs (1.3)
56
+ docile (1.1.5)
55
57
  erubis (2.7.0)
56
58
  gemika (0.3.2)
57
59
  globalid (0.4.0)
58
60
  activesupport (>= 4.2.0)
61
+ honeybadger (3.1.2)
59
62
  i18n (0.8.4)
60
63
  instrumental_agent (1.0.1)
64
+ json (1.8.6)
61
65
  loofah (2.0.3)
62
66
  nokogiri (>= 1.5.9)
63
67
  mail (2.6.6)
@@ -130,6 +134,11 @@ GEM
130
134
  connection_pool (~> 2.2, >= 2.2.0)
131
135
  rack-protection (>= 1.5.0)
132
136
  redis (~> 3.2, >= 3.2.1)
137
+ simplecov (0.14.1)
138
+ docile (~> 1.1.0)
139
+ json (>= 1.8, < 3)
140
+ simplecov-html (~> 0.10.0)
141
+ simplecov-html (0.10.1)
133
142
  sinatra (1.4.8)
134
143
  rack (~> 1.5)
135
144
  rack-protection (~> 1.4)
@@ -154,11 +163,13 @@ PLATFORMS
154
163
 
155
164
  DEPENDENCIES
156
165
  byebug
166
+ dalli (~> 2.6)
157
167
  database_cleaner
158
168
  delayed_job_active_record
159
169
  gemika
170
+ honeybadger
160
171
  instrumental_agent
161
- memcached
172
+ memcached (~> 1.7)
162
173
  metrician!
163
174
  mysql2 (= 0.3.17)
164
175
  rack-test
@@ -168,6 +179,7 @@ DEPENDENCIES
168
179
  resque
169
180
  rspec (~> 3.4)
170
181
  sidekiq (~> 4.0)
182
+ simplecov
171
183
 
172
184
  BUNDLED WITH
173
185
  1.14.6
@@ -18,7 +18,10 @@ gem 'delayed_job_active_record'
18
18
  gem 'resque'
19
19
  gem 'redis'
20
20
  gem 'dalli'
21
+ gem 'memcached'
21
22
  gem 'rack-test'
23
+ gem 'simplecov', :require => false, :group => :test
24
+ gem 'honeybadger'
22
25
 
23
26
  # Gem under test
24
27
  gem 'metrician', :path => '..'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.7)
4
+ metrician (0.0.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -56,16 +56,20 @@ GEM
56
56
  activerecord (>= 3.0, < 5.2)
57
57
  delayed_job (>= 3.0, < 5)
58
58
  diff-lcs (1.3)
59
+ docile (1.1.5)
59
60
  erubis (2.7.0)
60
61
  gemika (0.3.2)
61
62
  globalid (0.4.0)
62
63
  activesupport (>= 4.2.0)
64
+ honeybadger (3.1.2)
63
65
  i18n (0.8.4)
64
66
  instrumental_agent (1.0.1)
67
+ json (1.8.6)
65
68
  loofah (2.0.3)
66
69
  nokogiri (>= 1.5.9)
67
70
  mail (2.6.5)
68
71
  mime-types (>= 1.16, < 4)
72
+ memcached (1.8.0)
69
73
  method_source (0.8.2)
70
74
  mime-types (3.1)
71
75
  mime-types-data (~> 3.2015)
@@ -135,6 +139,11 @@ GEM
135
139
  connection_pool (~> 2.2, >= 2.2.0)
136
140
  rack-protection (>= 1.5.0)
137
141
  redis (~> 3.3, >= 3.3.3)
142
+ simplecov (0.14.1)
143
+ docile (~> 1.1.0)
144
+ json (>= 1.8, < 3)
145
+ simplecov-html (~> 0.10.0)
146
+ simplecov-html (0.10.1)
138
147
  sinatra (2.0.0)
139
148
  mustermann (~> 1.0)
140
149
  rack (~> 2.0)
@@ -167,7 +176,9 @@ DEPENDENCIES
167
176
  database_cleaner
168
177
  delayed_job_active_record
169
178
  gemika
179
+ honeybadger
170
180
  instrumental_agent
181
+ memcached
171
182
  metrician!
172
183
  pg (~> 0.18.4)
173
184
  rack-test
@@ -177,6 +188,7 @@ DEPENDENCIES
177
188
  resque
178
189
  rspec (~> 3.5)
179
190
  sidekiq
191
+ simplecov
180
192
 
181
193
  BUNDLED WITH
182
194
  1.15.1
@@ -7,6 +7,7 @@ module Metrician
7
7
  end
8
8
 
9
9
  def instrument
10
+ return if ::Honeybadger::Agent.method_defined?(:notify_with_metrician)
10
11
  ::Honeybadger::Agent.class_eval do
11
12
  def notify_with_metrician(exception, options = {})
12
13
  # We can differentiate whether or not we live inside a web
@@ -15,6 +16,7 @@ module Metrician
15
16
  notify_without_metrician(exception, options)
16
17
  ensure
17
18
  Metrician.increment("exception.raise") if Metrician.configuration[:exception][:raise][:enabled]
19
+ # TODO: underscore is rails only
18
20
  Metrician.increment("exception.raise.#{Metrician.dotify(exception.class.name.underscore)}") if exception && Metrician.configuration[:exception][:exception_specific][:enabled]
19
21
  end
20
22
  alias_method :notify_without_metrician, :notify
@@ -11,12 +11,11 @@ module Metrician
11
11
  !!defined?(::Dalli) && !!defined?(::Dalli::Client)
12
12
  end
13
13
 
14
- def client_class
15
- if self.class.memcached_gem?
16
- Memcached
17
- elsif self.class.dalli_gem?
18
- Dalli::Client
19
- end
14
+ def client_classes
15
+ [
16
+ self.class.memcached_gem? && Memcached,
17
+ self.class.dalli_gem? && Dalli::Client,
18
+ ].compact
20
19
  end
21
20
 
22
21
  def self.enabled?
@@ -25,10 +24,16 @@ module Metrician
25
24
  end
26
25
 
27
26
  def instrument
27
+ client_classes.each do |client_class|
28
+ instrument_class(client_class)
29
+ end
30
+ end
31
+
32
+ def instrument_class(client_class)
28
33
  return if client_class.method_defined?(:get_with_metrician_trace)
29
34
  METHODS.each do |method_name|
30
35
  next unless client_class.method_defined?(method_name)
31
- client_class.class_eval <<-EOD
36
+ client_class.class_eval <<-RUBY
32
37
  def #{method_name}_with_metrician_trace(*args, &blk)
33
38
  start_time = Time.now
34
39
  begin
@@ -41,7 +46,7 @@ module Metrician
41
46
  end
42
47
  alias #{method_name}_without_metrician_trace #{method_name}
43
48
  alias #{method_name} #{method_name}_with_metrician_trace
44
- EOD
49
+ RUBY
45
50
  end
46
51
  end
47
52
 
@@ -1,5 +1,5 @@
1
1
  module Metrician
2
2
 
3
- VERSION = "0.0.7".freeze
3
+ VERSION = "0.0.8".freeze
4
4
 
5
5
  end
@@ -26,4 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency("rake", "~> 10.0")
27
27
  s.add_development_dependency("rspec", "~> 3.0")
28
28
  s.add_development_dependency("byebug", "~> 0")
29
+ s.add_development_dependency("simplecov", "~> 0")
29
30
  end
@@ -60,6 +60,51 @@ RSpec.describe Metrician do
60
60
  end
61
61
  end
62
62
 
63
+ describe "exception tracking" do
64
+ before do
65
+ Metrician.configuration[:exception][:enabled] = true
66
+ Honeybadger.configure do |config|
67
+ config.disabled = true
68
+ end
69
+ @agent = Metrician.null_agent
70
+ Metrician.activate(@agent)
71
+ end
72
+
73
+ describe "honeybadger" do
74
+ specify "exceptions are instrumented" do
75
+ @agent.stub(:increment)
76
+ @agent.should_receive(:increment).with("exception.raise", 1)
77
+ Honeybadger.notify('Something went wrong.', {
78
+ error_class: 'MyClass',
79
+ context: {my_data: 'value'}
80
+ })
81
+ end
82
+
83
+ specify "exceptions are instrumented (job specific, string)" do
84
+ Metrician.configuration[:exception][:exception_specific][:enabled] = true
85
+ @agent.stub(:increment)
86
+ @agent.should_receive(:increment).with("exception.raise.string", 1)
87
+ Honeybadger.notify('Something went wrong.', {
88
+ error_class: 'MyClass',
89
+ context: {my_data: 'value'}
90
+ })
91
+ end
92
+
93
+ specify "exceptions are instrumented (job specific, exception)" do
94
+ Metrician.configuration[:exception][:exception_specific][:enabled] = true
95
+ @agent.stub(:increment)
96
+ @agent.should_receive(:increment).with("exception.raise.runtime_error", 1)
97
+ begin
98
+ fail 'badgers!'
99
+ rescue => exception
100
+ Honeybadger.notify(exception, context: {
101
+ my_data: 'value'
102
+ })
103
+ end
104
+ end
105
+ end
106
+ end
107
+
63
108
  describe "ActiveRecord" do
64
109
  before do
65
110
  @agent = Metrician.null_agent
@@ -191,6 +236,26 @@ RSpec.describe Metrician do
191
236
  # worker bits at latest possible time
192
237
  lambda { TestSidekiqWorker.perform_async({ "error" => true}) }.should raise_error(StandardError)
193
238
  end
239
+
240
+ specify "per job instrumentation" do
241
+ Metrician.configuration[:jobs][:job_specific][:enabled] = true
242
+ @agent.stub(:gauge)
243
+
244
+ @agent.should_receive(:gauge).with("jobs.run.job.TestSidekiqWorker", anything)
245
+ # avoid load order error of sidekiq here by just including the
246
+ # worker bits at latest possible time
247
+ TestSidekiqWorker.perform_async({ "success" => true})
248
+ end
249
+
250
+ specify "job errors are instrumented per job" do
251
+ Metrician.configuration[:jobs][:job_specific][:enabled] = true
252
+ @agent.stub(:increment)
253
+ @agent.should_receive(:increment).with("jobs.error.job.TestSidekiqWorker", 1)
254
+
255
+ # avoid load order error of sidekiq here by just including the
256
+ # worker bits at latest possible time
257
+ lambda { TestSidekiqWorker.perform_async({ "error" => true}) }.should raise_error(StandardError)
258
+ end
194
259
  end
195
260
  end
196
261
 
@@ -205,10 +270,9 @@ RSpec.describe Metrician do
205
270
  end
206
271
 
207
272
  memcached_clients = [
208
- defined?(::Memcached) && ::Memcached.new("localhost:11211"),
209
- defined?(::Dalli::Client) && ::Dalli::Client.new("localhost:11211"),
210
- ].compact
211
- raise "no memcached client" if memcached_clients.empty?
273
+ ::Memcached.new("localhost:11211"),
274
+ ::Dalli::Client.new("localhost:11211"),
275
+ ]
212
276
 
213
277
  memcached_clients.each do |client|
214
278
  specify "memcached is instrumented (#{client.class.name})" do
@@ -412,5 +476,25 @@ RSpec.describe Metrician do
412
476
  end
413
477
 
414
478
  end
479
+
480
+ describe "rails" do
481
+ def app
482
+ TestRailsApp.instance
483
+ end
484
+
485
+ let(:agent) { Metrician.null_agent }
486
+
487
+ before do
488
+ Metrician.activate(agent)
489
+ end
490
+
491
+ it "hooks into rails automatically" do
492
+ agent.stub(:gauge)
493
+ agent.should_receive(:gauge).with("web.request", anything)
494
+
495
+ get "/"
496
+ last_response.body.should == "foobar response"
497
+ end
498
+ end
415
499
  end
416
500
  end
@@ -1,3 +1,9 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ SimpleCov.command_name "#{RUBY_VERSION}_#{File.basename(ENV["BUNDLE_GEMFILE"])}"
4
+ SimpleCov.minimum_coverage 90
5
+ SimpleCov.refuse_coverage_drop
6
+
1
7
  ENV["RAILS_ENV"] = "test"
2
8
 
3
9
  require "bundler/setup"
@@ -0,0 +1,21 @@
1
+ require "rails/all"
2
+
3
+ class TestRailsApp < Rails::Application
4
+ secrets.secret_token = "secret_token"
5
+ secrets.secret_key_base = "secret_key_base"
6
+
7
+ config.logger = Logger.new($stdout)
8
+ Rails.logger = config.logger
9
+
10
+ routes.draw do
11
+ get "/", to: "foobars#index"
12
+ end
13
+ end
14
+
15
+ class FoobarsController < ActionController::Base
16
+ include Rails.application.routes.url_helpers
17
+
18
+ def index
19
+ render inline: "foobar response"
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrician
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Expected Behavior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: instrumental_agent
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Automatically report the most important metrics about your ruby application,
98
112
  from request timing to job execution.
99
113
  email:
@@ -151,6 +165,7 @@ files:
151
165
  - spec/support/database.travis.yml
152
166
  - spec/support/models.rb
153
167
  - spec/support/test_delayed_job.rb
168
+ - spec/support/test_rails_app.rb
154
169
  - spec/support/test_resque_job.rb
155
170
  - spec/support/test_sidekiq_worker.rb
156
171
  homepage: http://instrumentalapp.com/
@@ -187,5 +202,6 @@ test_files:
187
202
  - spec/support/database.travis.yml
188
203
  - spec/support/models.rb
189
204
  - spec/support/test_delayed_job.rb
205
+ - spec/support/test_rails_app.rb
190
206
  - spec/support/test_resque_job.rb
191
207
  - spec/support/test_sidekiq_worker.rb