metrician 0.0.11 → 0.1.0

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: 4ea4543ca702d54b9c5b3b98da80914d17c4804e
4
- data.tar.gz: 923cd68e6fd20feb0b1a786c83b53dec87e629a7
3
+ metadata.gz: 0061f0ebb86e501bc59c0b0ec001bcc7371b725c
4
+ data.tar.gz: 17fe4bb8fd8faa906a197dc95f15d518ae2af77c
5
5
  SHA512:
6
- metadata.gz: 8c3ef47ea845363d1c5d581435de855b4c115397523aa71d4632489a70dbed294e51779d05582a3d2119ad88800037760348f8acfb4ad1d469753c5df325c454
7
- data.tar.gz: f29e315bffa5fa8ccd9dd86d0f39782f174eab18278f4c98ed09e5d898ca6597c4dbcd87efcf97c39ca91a08d62114a833bbbcde1052821d62545f10b13788be
6
+ metadata.gz: d3060f34b98a589e141a0dd337291f9f016ab4186595cec5db7681abb0095e25a09a6490c76efeafefd31a4442db30a0faf74f3ffcd83eecaec4c6c74acb8ea9
7
+ data.tar.gz: b17b46f886d8351c54a5001835106c46eae4d59b3a6badb5f6f8765f8252f644ed32a0d7c36e15fac154286cae782d528a702b6bd83108eab1b9aec7f3fa90cc
@@ -1,3 +1,6 @@
1
+ ### 0.1.0 [September 5, 2017]
2
+ * **BREAKING** Rename Method Tracing -> Method Timing to reflect reality better. Metrics go from `tracer.<stuff>` to `timer.<stuff>`.
3
+
1
4
  ### 0.0.11 [August 18, 2017]
2
5
  * Remove dependence on ActiveSupport
3
6
 
data/README.md CHANGED
@@ -26,7 +26,7 @@ Request Metrics:
26
26
  * content length
27
27
  * web server queue time (for servers that set HTTP_X_QUEUE_START like nginx)
28
28
 
29
- And also you can do generic method tracing.
29
+ And also you can report generic method timing.
30
30
 
31
31
  ## Installation
32
32
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.11)
4
+ metrician (0.1.0)
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.11)
4
+ metrician (0.1.0)
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.11)
4
+ metrician (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -180,4 +180,4 @@ DEPENDENCIES
180
180
  simplecov
181
181
 
182
182
  BUNDLED WITH
183
- 1.14.2
183
+ 1.14.6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- metrician (0.0.11)
4
+ metrician (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -45,4 +45,4 @@ DEPENDENCIES
45
45
  simplecov
46
46
 
47
47
  BUNDLED WITH
48
- 1.14.2
48
+ 1.14.6
@@ -33,7 +33,7 @@ require "metrician/reporters/active_record"
33
33
  require "metrician/reporters/delayed_job"
34
34
  require "metrician/reporters/honeybadger"
35
35
  require "metrician/reporters/memcache"
36
- require "metrician/reporters/method_tracer"
36
+ require "metrician/reporters/method_timer"
37
37
  require "metrician/reporters/middleware"
38
38
  require "metrician/reporters/net_http"
39
39
  require "metrician/reporters/redis"
@@ -31,22 +31,22 @@ module Metrician
31
31
  end
32
32
 
33
33
  def instrument_class(client_class)
34
- return if client_class.method_defined?(:get_with_metrician_trace)
34
+ return if client_class.method_defined?(:get_with_metrician_time)
35
35
  METHODS.each do |method_name|
36
36
  next unless client_class.method_defined?(method_name)
37
37
  client_class.class_eval <<-RUBY
38
- def #{method_name}_with_metrician_trace(*args, &blk)
38
+ def #{method_name}_with_metrician_time(*args, &blk)
39
39
  start_time = Time.now
40
40
  begin
41
- #{method_name}_without_metrician_trace(*args, &blk)
41
+ #{method_name}_without_metrician_time(*args, &blk)
42
42
  ensure
43
43
  duration = (Time.now - start_time).to_f
44
44
  Metrician.gauge(::Metrician::Memcache::CACHE_METRIC, duration) if Metrician.configuration[:cache][:command][:enabled]
45
45
  Metrician.gauge("#{::Metrician::Memcache::CACHE_METRIC}.#{method_name}", duration) if Metrician.configuration[:cache][:command_specific][:enabled]
46
46
  end
47
47
  end
48
- alias #{method_name}_without_metrician_trace #{method_name}
49
- alias #{method_name} #{method_name}_with_metrician_trace
48
+ alias #{method_name}_without_metrician_time #{method_name}
49
+ alias #{method_name} #{method_name}_with_metrician_time
50
50
  RUBY
51
51
  end
52
52
  end
@@ -0,0 +1,70 @@
1
+ module Metrician
2
+
3
+ class MethodTimer < Reporter
4
+
5
+ def self.enabled?
6
+ Metrician.configuration[:method_timer][:enabled]
7
+ end
8
+
9
+ def instrument
10
+ Module.send(:include, TimingMethodInterceptor)
11
+ end
12
+
13
+ end
14
+
15
+ module TimingMethodInterceptor
16
+
17
+ def self.default_metric_name(klass, is_klass_method, method_name)
18
+ name = klass.name.underscore
19
+ name = "#{name}.self" if is_klass_method
20
+ "timer.#{name}.#{method_name}".downcase.tr_s("^a-zA-Z0-9.", "_")
21
+ end
22
+
23
+ def self.timeable_method?(klass, method_name)
24
+ klass.method_defined?(method_name) ||
25
+ klass.private_method_defined?(method_name) ||
26
+ klass.methods.include?(method_name)
27
+ end
28
+
29
+ def self.already_timed_method?(klass, is_klass_method, timed_name)
30
+ is_klass_method ?
31
+ klass.methods.include?(timed_name) :
32
+ klass.method_defined?(timed_name)
33
+ end
34
+
35
+ def self.code_to_eval(is_klass_method, method_name, timed_name, untimed_name, metric_name)
36
+ <<-EOD
37
+ #{'class << self' if is_klass_method}
38
+ def #{timed_name}(*args, &block)
39
+ start_time = Time.now
40
+ begin
41
+ #{untimed_name}(*args, &block)
42
+ ensure
43
+ Metrician.gauge("#{metric_name}", (Time.now - start_time).to_f)
44
+ end
45
+ end
46
+ alias :#{untimed_name} :#{method_name}
47
+ alias :#{method_name} :#{timed_name}
48
+ #{'end' if is_klass_method}
49
+ EOD
50
+ end
51
+
52
+ def add_metrician_method_timer(method_name, metric_name = nil)
53
+ return false unless TimingMethodInterceptor.timeable_method?(self, method_name)
54
+
55
+ is_klass_method = methods.include?(method_name)
56
+ timed_name = "with_metrician_time_#{method_name}"
57
+ return false if TimingMethodInterceptor.already_timed_method?(self, is_klass_method, timed_name)
58
+
59
+ metric_name ||= TimingMethodInterceptor.default_metric_name(self, is_klass_method, method_name)
60
+ untimed_name = "without_metrician_time_#{method_name}"
61
+
62
+ timed_method_code =
63
+ TimingMethodInterceptor.code_to_eval(is_klass_method, method_name, timed_name,
64
+ untimed_name, metric_name)
65
+ class_eval(timed_method_code, __FILE__, __LINE__)
66
+ end
67
+
68
+ end
69
+
70
+ end
@@ -11,18 +11,18 @@ module Metrician
11
11
  end
12
12
 
13
13
  def instrument
14
- return if ::Net::HTTP.method_defined?(:request_with_metrician_trace)
14
+ return if ::Net::HTTP.method_defined?(:request_with_metrician_time)
15
15
  ::Net::HTTP.class_eval do
16
- def request_with_metrician_trace(req, body = nil, &block)
16
+ def request_with_metrician_time(req, body = nil, &block)
17
17
  start_time = Time.now
18
18
  begin
19
- request_without_metrician_trace(req, body, &block)
19
+ request_without_metrician_time(req, body, &block)
20
20
  ensure
21
21
  Metrician.gauge(REQUEST_METRIC, (Time.now - start_time).to_f) if Metrician.configuration[:external_service][:request][:enabled]
22
22
  end
23
23
  end
24
- alias_method :request_without_metrician_trace, :request
25
- alias_method :request, :request_with_metrician_trace
24
+ alias_method :request_without_metrician_time, :request
25
+ alias_method :request, :request_with_metrician_time
26
26
  end
27
27
  end
28
28
 
@@ -9,12 +9,12 @@ module Metrician
9
9
  end
10
10
 
11
11
  def instrument
12
- return if ::Redis::Client.method_defined?(:call_with_metrician_trace)
12
+ return if ::Redis::Client.method_defined?(:call_with_metrician_time)
13
13
  ::Redis::Client.class_eval do
14
- def call_with_metrician_trace(*args, &blk)
14
+ def call_with_metrician_time(*args, &blk)
15
15
  start_time = Time.now
16
16
  begin
17
- call_without_metrician_trace(*args, &blk)
17
+ call_without_metrician_time(*args, &blk)
18
18
  ensure
19
19
  duration = (Time.now - start_time).to_f
20
20
  Metrician.gauge(CACHE_METRIC, duration) if Metrician.configuration[:cache][:command][:enabled]
@@ -24,8 +24,8 @@ module Metrician
24
24
  end
25
25
  end
26
26
  end
27
- alias_method :call_without_metrician_trace, :call
28
- alias_method :call, :call_with_metrician_trace
27
+ alias_method :call_without_metrician_time, :call
28
+ alias_method :call, :call_with_metrician_time
29
29
  end
30
30
  end
31
31
 
@@ -1,5 +1,5 @@
1
1
  module Metrician
2
2
 
3
- VERSION = "0.0.11".freeze
3
+ VERSION = "0.1.0".freeze
4
4
 
5
5
  end
@@ -131,10 +131,10 @@
131
131
  :exception_specific:
132
132
  :enabled: false
133
133
 
134
- # "method_tracing" settings control hooking into Module and allowing
134
+ # "method_timer" settings control hooking into Module and allowing
135
135
  # ruby methods to be timed
136
- :method_tracer:
136
+ :method_timer:
137
137
 
138
- # hook into Module with add_metrician_method_tracer added as a base
138
+ # hook into Module with add_metrician_method_timer added as a base
139
139
  # feature of every ruby object
140
140
  :enabled: false
@@ -127,10 +127,10 @@
127
127
  # :exception_specific:
128
128
  # :enabled: false
129
129
 
130
- # # "method_tracing" settings control hooking into Module and allowing
130
+ # # "method_timer" settings control hooking into Module and allowing
131
131
  # # ruby methods to be timed
132
- :method_tracer:
132
+ :method_timer:
133
133
 
134
- # # hook into Module with add_metrician_method_tracer added as a base
134
+ # # hook into Module with add_metrician_method_timer added as a base
135
135
  # # feature of every ruby object
136
136
  # :enabled: true
@@ -67,6 +67,33 @@ RSpec.describe Metrician do
67
67
  end
68
68
  end
69
69
 
70
+ describe "method timing" do
71
+ before do
72
+ Metrician.configuration[:method_timer][:enabled] = true
73
+ @agent = Metrician.null_agent
74
+ Metrician.activate(@agent)
75
+ end
76
+
77
+ let(:test_instance) do
78
+ class TestClass
79
+ def instance_it; end
80
+ add_metrician_method_timer :instance_it
81
+
82
+ def self.class_it; end
83
+ add_metrician_method_timer :class_it
84
+ end
85
+ TestClass.new
86
+ end
87
+
88
+ specify "instance method timings are reported" do
89
+ @agent.stub(:gauge)
90
+ @agent.should_receive(:gauge).with("app.timer.test_class.instance_it", anything)
91
+ test_instance.instance_it
92
+ @agent.should_receive(:gauge).with("app.timer.test_class.self.class_it", anything)
93
+ test_instance.class.class_it
94
+ end
95
+ end
96
+
70
97
  describe "exception tracking" do
71
98
  before do
72
99
  Metrician.configuration[:exception][:enabled] = true
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.11
4
+ version: 0.1.0
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-18 00:00:00.000000000 Z
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: instrumental_agent
@@ -150,7 +150,7 @@ files:
150
150
  - lib/metrician/reporters/delayed_job.rb
151
151
  - lib/metrician/reporters/honeybadger.rb
152
152
  - lib/metrician/reporters/memcache.rb
153
- - lib/metrician/reporters/method_tracer.rb
153
+ - lib/metrician/reporters/method_timer.rb
154
154
  - lib/metrician/reporters/middleware.rb
155
155
  - lib/metrician/reporters/net_http.rb
156
156
  - lib/metrician/reporters/redis.rb
@@ -1,70 +0,0 @@
1
- module Metrician
2
-
3
- class MethodTracer < Reporter
4
-
5
- def self.enabled?
6
- Metrician.configuration[:method_tracer][:enabled]
7
- end
8
-
9
- def instrument
10
- Module.send(:include, TracingMethodInterceptor)
11
- end
12
-
13
- end
14
-
15
- module TracingMethodInterceptor
16
-
17
- def self.default_metric_name(klass, is_klass_method, method_name)
18
- name = klass.name.underscore
19
- name = "#{name}.self" if is_klass_method
20
- "tracer.#{name}.#{method_name}".downcase.tr_s("^a-zA-Z0-9.", "_")
21
- end
22
-
23
- def self.traceable_method?(klass, method_name)
24
- klass.method_defined?(method_name) ||
25
- klass.private_method_defined?(method_name) ||
26
- klass.methods.include?(method_name.to_s)
27
- end
28
-
29
- def self.already_traced_method?(klass, is_klass_method, traced_name)
30
- is_klass_method ?
31
- klass.methods.include?(traced_name) :
32
- klass.method_defined?(traced_name)
33
- end
34
-
35
- def self.code_to_eval(is_klass_method, method_name, traced_name, untraced_name, metric_name)
36
- <<-EOD
37
- #{'class << self' if is_klass_method}
38
- def #{traced_name}(*args, &block)
39
- start_time = Time.now
40
- begin
41
- #{untraced_name}(*args, &block)
42
- ensure
43
- Metrician.gauge("#{metric_name}", (Time.now - start_time).to_f)
44
- end
45
- end
46
- alias :#{untraced_name} :#{method_name}
47
- alias :#{method_name} :#{traced_name}
48
- #{'end' if is_klass_method}
49
- EOD
50
- end
51
-
52
- def add_metrician_method_tracer(method_name, metric_name = nil)
53
- return false unless TracingMethodInterceptor.traceable_method?(self, method_name)
54
-
55
- is_klass_method = methods.include?(method_name.to_s)
56
- traced_name = "with_metrician_trace_#{method_name}"
57
- return false if TracingMethodInterceptor.already_traced_method?(self, is_klass_method, traced_name)
58
-
59
- metric_name ||= TracingMethodInterceptor.default_metric_name(self, is_klass_method, method_name)
60
- untraced_name = "without_metrician_trace_#{method_name}"
61
-
62
- traced_method_code =
63
- TracingMethodInterceptor.code_to_eval(is_klass_method, method_name, traced_name,
64
- untraced_name, metric_name)
65
- class_eval(traced_method_code, __FILE__, __LINE__)
66
- end
67
-
68
- end
69
-
70
- end