metrician 0.0.4 → 0.0.5

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: a191afe161c4357de6c30940adf1dd405419aed1
4
- data.tar.gz: a1154276f6c09cc3c4ca9bdffbcdfcf00044309a
3
+ metadata.gz: 723f0b86a48f4c5105357ce4df6c792e53824849
4
+ data.tar.gz: df432f573bc722606600b382ec4762ced6a19fc7
5
5
  SHA512:
6
- metadata.gz: e3dde17cb1da6670d88fa0bf88d7833b28fdf979519e107b1ccb24b9986a359aa6b8b00e1cb62e4dd91e15052a3be8bbc53ab65313c036d7cb31e7a880c957a5
7
- data.tar.gz: 95c30e45864e10cd236739eb5b1f5d1aaa74dc2e592db616cf5f803fe9ba3b2a0bc10f8ee16730ee5db4daf8b81d4f12b12d17717c30babd774d0c4420c484c0
6
+ metadata.gz: 728a482d9a7a8a7e95db8b6c429fc418051fcef77cf9bf67b51b449f1d9f8e1ccc1a7df0faf4c9910f83183ee7f5e1cab32031d38e810ef7f78950b5d39305ad
7
+ data.tar.gz: 4f683f3998d632daff059f965fd7f383cff9d817b45a5d35dd29aad75b1db5497bda39264467369fca6edfb56ea42b43474026414a23f114de65e6d76e838f4b
@@ -1,3 +1,6 @@
1
+ ### 0.0.5 [July 25, 2017]
2
+ * Automate Resque integration
3
+
1
4
  ### 0.0.4 [July 24, 2017]
2
5
  * Handle exceptions in other middlewares for response size tracking
3
6
 
data/README.md CHANGED
@@ -75,3 +75,22 @@ run YOUR_APP::Application.routes
75
75
 
76
76
  Your exception tracking middleware may try to get in first (hey, Honeybadger), so you will have to change the load order in an initializer, because we want to track that as middleware time, too.
77
77
 
78
+
79
+ ## Release Process
80
+
81
+ 1. Pull latest master
82
+ 2. Merge feature branch(es) into master
83
+ 3. `script/test`
84
+ 4. Increment version in:
85
+ - `lib/metrician/version.rb`
86
+ 5. Run `rake matrix:install` to generate new gem lockfiles
87
+ 6. Update [CHANGELOG.md](CHANGELOG.md)
88
+ 7. Commit "Release vX.Y.Z"
89
+ 8. Push to GitHub
90
+ 9. Release packages: `rake release`
91
+ 10. Verify package release at https://rubygems.org/gems/metrician
92
+
93
+
94
+ ## Version Policy
95
+
96
+ This library follows [Semantic Versioning 2.0.0](http://semver.org).
@@ -1,4 +1,4 @@
1
- # A configuration for Metrician that controls the features of our
1
+ # A configuration for Metrician that controls the features of its
2
2
  # automated metric reporting
3
3
 
4
4
  ---
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.4)
4
+ metrician (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.4)
4
+ metrician (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -78,4 +78,12 @@ module Metrician
78
78
  def self.configuration
79
79
  @configuration ||= Metrician::Configuration.load
80
80
  end
81
+
82
+ def self.reset
83
+ %i[@agent @configuration].each do |memo_ivar|
84
+ if Metrician.instance_variable_defined?(memo_ivar)
85
+ Metrician.remove_instance_variable(memo_ivar)
86
+ end
87
+ end
88
+ end
81
89
  end
@@ -5,6 +5,8 @@ module Metrician
5
5
  FileMissing = Class.new(StandardError)
6
6
 
7
7
  def self.load
8
+ reset_dependents
9
+
8
10
  if env_location
9
11
  # this should never raise unless a bad ENV setting has been set
10
12
  raise(FileMissing.new(env_location)) unless File.exist?(env_location)
@@ -29,5 +31,10 @@ module Metrician
29
31
  def self.gem_location
30
32
  File.expand_path("../../../config/metrician.yaml", __FILE__)
31
33
  end
34
+
35
+ def self.reset_dependents
36
+ Metrician::Jobs.reset
37
+ Metrician::Middleware.reset
38
+ end
32
39
  end
33
40
  end
@@ -28,5 +28,13 @@ module Metrician
28
28
  job_name.gsub(/[^\w]+/, ".").gsub(/\.+$/, "")
29
29
  end
30
30
 
31
+ def self.reset
32
+ %i[@configuration @enabled @run @error @job_specific].each do |memo_ivar|
33
+ if instance_variable_defined?(memo_ivar)
34
+ remove_instance_variable(memo_ivar)
35
+ end
36
+ end
37
+ end
38
+
31
39
  end
32
40
  end
@@ -3,34 +3,50 @@
3
3
  module Metrician
4
4
  module Jobs
5
5
  module ResquePlugin
6
-
7
- def around_perform_with_metrician(*_args)
8
- start = Time.now
9
- yield
10
- ensure
11
- if Jobs.run?
12
- duration = Time.now - start
13
- Metrician.gauge(Jobs::RUN_METRIC, duration)
14
- if Jobs.job_specific?
15
- Metrician.gauge("#{Jobs::RUN_METRIC}.job.#{Jobs.instrumentation_name(self.to_s)}", duration)
6
+ module Extension
7
+ def around_perform_with_metrician(*_args)
8
+ start = Time.now
9
+ yield
10
+ ensure
11
+ if Jobs.run?
12
+ duration = Time.now - start
13
+ Metrician.gauge(Jobs::RUN_METRIC, duration)
14
+ if Jobs.job_specific?
15
+ Metrician.gauge("#{Jobs::RUN_METRIC}.job.#{Jobs.instrumentation_name(self.to_s)}", duration)
16
+ end
17
+ Metrician.agent.cleanup
16
18
  end
17
- Metrician.agent.cleanup
18
19
  end
19
- end
20
20
 
21
- def on_failure_with_metrician(_e, *_args)
22
- if Jobs.error?
23
- Metrician.increment(Jobs::ERROR_METRIC)
24
- if Jobs.job_specific?
25
- Metrician.increment("#{Jobs::ERROR_METRIC}.job.#{Jobs.instrumentation_name(self.to_s)}")
21
+ def on_failure_with_metrician(_e, *_args)
22
+ if Jobs.error?
23
+ Metrician.increment(Jobs::ERROR_METRIC)
24
+ if Jobs.job_specific?
25
+ Metrician.increment("#{Jobs::ERROR_METRIC}.job.#{Jobs.instrumentation_name(self.to_s)}")
26
+ end
27
+ Metrician.agent.cleanup
26
28
  end
27
- Metrician.agent.cleanup
28
29
  end
30
+
31
+ ::Resque.before_fork = proc { Metrician.agent.cleanup }
29
32
  end
30
33
 
31
- ::Resque.before_fork = proc { Metrician.agent.cleanup }
34
+ module Installer
35
+ def self.included(base)
36
+ base.send(:alias_method, :payload_class_without_metrician, :payload_class)
37
+ base.send(:alias_method, :payload_class, :payload_class_with_metrician)
38
+ end
32
39
 
40
+ def payload_class_with_metrician
41
+ payload_class_without_metrician.tap do |klass|
42
+ unless klass.respond_to?(:around_perform_with_metrician)
43
+ klass.instance_eval do
44
+ extend(::Metrician::Jobs::ResquePlugin::Extension)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
33
50
  end
34
-
35
51
  end
36
52
  end
@@ -60,5 +60,14 @@ module Metrician
60
60
  def self.apdex?
61
61
  @apdex ||= configuration[:apdex][:enabled]
62
62
  end
63
+
64
+ def self.reset
65
+ %w[@configuration @enabled @request @error @idle @response_size @middleware @queue_time @route_tracking @apdex].each do |memo_ivar|
66
+ if instance_variable_defined?(memo_ivar)
67
+ remove_instance_variable(memo_ivar)
68
+ end
69
+ end
70
+ end
71
+
63
72
  end
64
73
  end
@@ -37,11 +37,11 @@ module Metrician
37
37
  config = Metrician.configuration[:database]
38
38
  metrics = []
39
39
  metrics << "database.query" if config[:query][:enabled]
40
- if config[:command] || config[:table]
40
+ if config[:command][:enabled] || config[:table][:enabled]
41
41
  command, table = parse_sql(sql)
42
- metrics << "database.#{command}" if config[:command] && command
43
- metrics << "database.#{table}" if config[:table] && table
44
- metrics << "database.#{command}.#{table}" if config[:command] && config[:table] && command && table
42
+ metrics << "database.#{command}" if config[:command][:enabled] && command
43
+ metrics << "database.#{table}" if config[:table][:enabled] && table
44
+ metrics << "database.#{command}.#{table}" if config[:command][:enabled] && config[:table] && command && table
45
45
  end
46
46
  begin
47
47
  log_without_metrician(*args, &block)
@@ -8,8 +8,8 @@ module Metrician
8
8
 
9
9
  def instrument
10
10
  require "metrician/jobs/resque_plugin"
11
- unless ::Resque::Job.respond_to?(:around_perform_with_metrician)
12
- ::Resque::Job.send(:extend, Metrician::Jobs::ResquePlugin)
11
+ unless ::Resque::Job.method_defined?(:payload_class_with_metrician)
12
+ ::Resque::Job.send(:include, Metrician::Jobs::ResquePlugin::Installer)
13
13
  end
14
14
  end
15
15
 
@@ -1,5 +1,5 @@
1
1
  module Metrician
2
2
 
3
- VERSION = "0.0.4".freeze
3
+ VERSION = "0.0.5".freeze
4
4
 
5
5
  end
@@ -8,8 +8,8 @@ module Metrician
8
8
  end
9
9
 
10
10
  RSpec.describe Metrician do
11
- before do
12
- Metrician.instance_variable_set("@agent", nil)
11
+ before(:each) do
12
+ Metrician.reset
13
13
  end
14
14
 
15
15
  it "has a version number" do
@@ -62,7 +62,7 @@ RSpec.describe Metrician do
62
62
  end
63
63
 
64
64
  specify "per table instrumentation" do
65
- Metrician.configuration[:database][:table] = true
65
+ Metrician.configuration[:database][:table][:enabled] = true
66
66
  @agent.stub(:gauge)
67
67
  @agent.should_receive(:gauge).with("database.users", anything)
68
68
 
@@ -70,8 +70,8 @@ RSpec.describe Metrician do
70
70
  end
71
71
 
72
72
  specify "per command and table instrumentation" do
73
- Metrician.configuration[:database][:command] = true
74
- Metrician.configuration[:database][:table] = true
73
+ Metrician.configuration[:database][:command][:enabled] = true
74
+ Metrician.configuration[:database][:table][:enabled] = true
75
75
  @agent.stub(:gauge)
76
76
  @agent.should_receive(:gauge).with("database.select.users", anything)
77
77
 
@@ -127,22 +127,14 @@ RSpec.describe Metrician do
127
127
  @agent.stub(:gauge)
128
128
  @agent.should_receive(:gauge).with("jobs.run", anything)
129
129
 
130
- # typically Metrician would be loaded in an initalizer
131
- # and this _extend_ could be done inside the job itself, but here
132
- # we are in a weird situation.
133
- TestResqueJob.send(:extend, Metrician::Jobs::ResquePlugin)
134
- Resque.enqueue(TestResqueJob, { "success" => true })
130
+ Resque::Job.create(:default, TestResqueJob, { "success" => true })
135
131
  end
136
132
 
137
133
  specify "job errors are instrumented" do
138
134
  @agent.stub(:increment)
139
135
  @agent.should_receive(:increment).with("jobs.error", 1)
140
136
 
141
- # typically Metrician would be loaded in an initalizer
142
- # and this _extend_ could be done inside the job itself, but here
143
- # we are in a weird situation.
144
- TestResqueJob.send(:extend, Metrician::Jobs::ResquePlugin)
145
- lambda { Resque.enqueue(TestResqueJob, { "error" => true }) }.should raise_error(StandardError)
137
+ lambda { Resque::Job.create(:default, TestResqueJob, { "error" => true }) }.should raise_error(StandardError)
146
138
  end
147
139
  end
148
140
 
@@ -5,7 +5,7 @@ Bundler.require(:default)
5
5
  require "metrician"
6
6
  require "gemika"
7
7
  require "byebug"
8
-
8
+ require "pp"
9
9
 
10
10
  Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each {|f| require f}
11
11
 
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.4
4
+ version: 0.0.5
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-07-24 00:00:00.000000000 Z
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: instrumental_agent