strumbar 0.1.0 → 0.2.0
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.
- data/LICENSE +1 -1
- data/README.md +2 -0
- data/lib/strumbar/client.rb +1 -1
- data/lib/strumbar/instrumentation/action_controller.rb +3 -1
- data/lib/strumbar/instrumentation/mongoid/controller_runtime.rb +46 -0
- data/lib/strumbar/instrumentation/mongoid/runtime_tracker.rb +34 -0
- data/lib/strumbar/instrumentation/mongoid.rb +42 -0
- data/lib/strumbar/instrumentation.rb +3 -1
- data/lib/strumbar/version.rb +1 -1
- data/spec/instrumentation/mongoid/controller_runtime_spec.rb +54 -0
- data/spec/instrumentation/mongoid/runtime_tracker_spec.rb +35 -0
- data/spec/spec_helper.rb +7 -0
- data/strumbar.gemspec +1 -1
- metadata +41 -14
data/LICENSE
CHANGED
data/README.md
CHANGED
data/lib/strumbar/client.rb
CHANGED
@@ -3,13 +3,15 @@ module Strumbar
|
|
3
3
|
module ActionController
|
4
4
|
def self.load(options={})
|
5
5
|
options[:rate] ||= Strumbar.default_rate
|
6
|
+
using_mongoid = options.fetch(:mongoid, false)
|
6
7
|
|
7
8
|
Strumbar.subscribe /process_action.action_controller/ do |client, event|
|
8
9
|
key = "#{event.payload[:controller]}.#{event.payload[:action]}"
|
10
|
+
db_runtime_key = using_mongoid ? :mongo_runtime : :db_runtime
|
9
11
|
|
10
12
|
client.timing "#{key}.total_time", event.duration, options[:rate]
|
11
13
|
client.timing "#{key}.view_time", event.payload[:view_runtime], options[:rate]
|
12
|
-
client.timing "#{key}.db_time", event.payload[
|
14
|
+
client.timing "#{key}.db_time", event.payload[db_runtime_key], options[:rate]
|
13
15
|
|
14
16
|
client.increment "#{key}.status.#{event.payload[:status]}", options[:rate]
|
15
17
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Strumbar
|
2
|
+
module Instrumentation
|
3
|
+
module Mongoid
|
4
|
+
# Seems a little out of scope for Strumbar, but honestly you're probably going to want
|
5
|
+
# this if you want to get anything out of instrumenting Mongoid.
|
6
|
+
module ControllerRuntime
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
attr_internal :mongo_runtime
|
12
|
+
|
13
|
+
def time_tracker
|
14
|
+
Strumbar::Instrumentation::Mongoid::RuntimeTracker
|
15
|
+
end
|
16
|
+
|
17
|
+
def process_action action, *args
|
18
|
+
time_tracker.reset
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def cleanup_view_runtime
|
23
|
+
mongo_rt_before_render = time_tracker.reset
|
24
|
+
runtime = super
|
25
|
+
mongo_rt_after_render = time_tracker.reset
|
26
|
+
self.mongo_runtime = mongo_rt_before_render + mongo_rt_after_render
|
27
|
+
|
28
|
+
runtime - mongo_rt_after_render
|
29
|
+
end
|
30
|
+
|
31
|
+
def append_info_to_payload payload
|
32
|
+
super
|
33
|
+
payload[:mongo_runtime] = mongo_runtime
|
34
|
+
end
|
35
|
+
|
36
|
+
module ClassMethods
|
37
|
+
def log_process_action payload
|
38
|
+
messages, mongo_runtime = super, payload[:mongo_runtime]
|
39
|
+
messages << ("Mongo: %.1fms" % mongo_runtime.to_f) if mongo_runtime
|
40
|
+
messages
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Strumbar
|
2
|
+
module Instrumentation
|
3
|
+
module Mongoid
|
4
|
+
# This is basically how ActiveRecord instruments this, although they use a LogSubscriber,
|
5
|
+
# for no adequately explained reason. I'm not sure if we should include the controller mixin
|
6
|
+
# in Strumbar or not? Seems simultaneously in and out of scope.
|
7
|
+
class RuntimeTracker
|
8
|
+
RUNTIME_KEY = 'Mongoid::RuntimeTracker#runtime'
|
9
|
+
COUNT_KEY = 'Mongoid::RuntimeTracker#count'
|
10
|
+
|
11
|
+
def self.runtime= value
|
12
|
+
Thread.current[RUNTIME_KEY] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.runtime
|
16
|
+
Thread.current[RUNTIME_KEY] ||= 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.count= value
|
20
|
+
Thread.current[COUNT_KEY] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.count
|
24
|
+
Thread.current[COUNT_KEY] ||= 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.reset
|
28
|
+
time, self.runtime, self.count = runtime, 0, 0
|
29
|
+
time
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'strumbar/instrumentation/mongoid/runtime_tracker'
|
2
|
+
require 'strumbar/instrumentation/mongoid/controller_runtime'
|
3
|
+
|
4
|
+
module Strumbar
|
5
|
+
module Instrumentation
|
6
|
+
module Mongoid
|
7
|
+
CALLS_TO_BE_INSTRUMENTED = [ :read, :write ]
|
8
|
+
|
9
|
+
def self.load(options={})
|
10
|
+
options[:rate] ||= Strumbar.default_rate
|
11
|
+
|
12
|
+
Strumbar.subscribe 'mongo.mongoid' do |client, event|
|
13
|
+
RuntimeTracker.runtime += event.duration
|
14
|
+
RuntimeTracker.count += 1
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined?(::ActionController)
|
18
|
+
ActiveSupport.on_load(:action_controller) do
|
19
|
+
include ControllerRuntime
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
unless ::Moped::Connection.instance_methods.include? :read_with_instrumentation
|
24
|
+
::Moped::Connection.module_eval do
|
25
|
+
CALLS_TO_BE_INSTRUMENTED.each do |method|
|
26
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
27
|
+
def #{method}_with_instrumentation(*args, &block)
|
28
|
+
Strumbar.strum 'mongo.mongoid', name: "#{method}" do
|
29
|
+
#{method}_without_instrumentation(*args, &block)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
CODE
|
33
|
+
|
34
|
+
alias_method_chain method, :instrumentation
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end # of self.load
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Strumbar
|
2
2
|
module Instrumentation
|
3
|
-
autoload :Redis, 'strumbar/instrumentation/redis'
|
4
3
|
autoload :ActionController, 'strumbar/instrumentation/action_controller'
|
5
4
|
autoload :ActiveRecord, 'strumbar/instrumentation/active_record'
|
5
|
+
autoload :Mongoid, 'strumbar/instrumentation/mongoid'
|
6
|
+
autoload :Redis, 'strumbar/instrumentation/redis'
|
6
7
|
|
7
8
|
def self.load
|
8
9
|
custom_load = Strumbar.configuration.custom_load
|
@@ -12,6 +13,7 @@ module Strumbar
|
|
12
13
|
else
|
13
14
|
Strumbar::Instrumentation::ActionController.load if defined?(::ActionController)
|
14
15
|
Strumbar::Instrumentation::ActiveRecord.load if defined?(::ActiveRecord)
|
16
|
+
Strumbar::Instrumentation::Mongoid.load if defined?(::Mongoid)
|
15
17
|
Strumbar::Instrumentation::Redis.load if defined?(::Redis)
|
16
18
|
end
|
17
19
|
end
|
data/lib/strumbar/version.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class AbstractHarness
|
4
|
+
def process_action action, *args
|
5
|
+
"Processed."
|
6
|
+
end
|
7
|
+
|
8
|
+
def append_info_to_payload payload
|
9
|
+
payload
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.log_process_action payload
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Strumbar
|
18
|
+
module Instrumentation
|
19
|
+
module Mongoid
|
20
|
+
describe ControllerRuntime do
|
21
|
+
let(:test_harness) {
|
22
|
+
Class.new(AbstractHarness) do
|
23
|
+
include ControllerRuntime
|
24
|
+
|
25
|
+
public :time_tracker, :process_action, :append_info_to_payload
|
26
|
+
end
|
27
|
+
}
|
28
|
+
|
29
|
+
describe "#time_tracker" do
|
30
|
+
it "is a convenient way access the RuntimeTracker class" do
|
31
|
+
test_harness.new.time_tracker.should == RuntimeTracker
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#process_action" do
|
36
|
+
it "resets the tracker" do
|
37
|
+
test_harness.new.time_tracker.runtime = 1000
|
38
|
+
|
39
|
+
test_harness.new.process_action :my_action
|
40
|
+
test_harness.new.time_tracker.runtime.should == 0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe ".log_process_action" do
|
45
|
+
it "adds the Mongo runtime to the list of messages to be logged" do
|
46
|
+
messages = test_harness.log_process_action({ mongo_runtime: 1000 })
|
47
|
+
messages.should == ["Mongo: 1000.0ms"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Strumbar
|
4
|
+
module Instrumentation
|
5
|
+
module Mongoid
|
6
|
+
describe RuntimeTracker do
|
7
|
+
%w(runtime count).each do |attribute|
|
8
|
+
describe ".#{attribute}" do
|
9
|
+
it "is a class attribute" do
|
10
|
+
RuntimeTracker.send("#{attribute}=", 100)
|
11
|
+
RuntimeTracker.send(attribute).should == 100
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".reset" do
|
18
|
+
it "returns the current runtime" do
|
19
|
+
RuntimeTracker.runtime = 1500
|
20
|
+
|
21
|
+
RuntimeTracker.reset.should == 1500
|
22
|
+
end
|
23
|
+
|
24
|
+
it "resets the count and runtime attributes" do
|
25
|
+
RuntimeTracker.runtime = 1000
|
26
|
+
RuntimeTracker.count = 2
|
27
|
+
|
28
|
+
RuntimeTracker.reset
|
29
|
+
RuntimeTracker.runtime.should == 0
|
30
|
+
RuntimeTracker.count.should == 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/strumbar.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = Strumbar::VERSION
|
17
17
|
|
18
18
|
gem.add_dependency 'activesupport'
|
19
|
-
gem.add_dependency 'statsd'
|
19
|
+
gem.add_dependency 'statsd-ruby'
|
20
20
|
|
21
21
|
gem.add_development_dependency 'rspec'
|
22
22
|
gem.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strumbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,15 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
|
-
name: statsd
|
28
|
-
requirement:
|
32
|
+
name: statsd-ruby
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
36
|
- - ! '>='
|
@@ -33,10 +38,15 @@ dependencies:
|
|
33
38
|
version: '0'
|
34
39
|
type: :runtime
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
37
47
|
- !ruby/object:Gem::Dependency
|
38
48
|
name: rspec
|
39
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
none: false
|
41
51
|
requirements:
|
42
52
|
- - ! '>='
|
@@ -44,10 +54,15 @@ dependencies:
|
|
44
54
|
version: '0'
|
45
55
|
type: :development
|
46
56
|
prerelease: false
|
47
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
48
63
|
- !ruby/object:Gem::Dependency
|
49
64
|
name: rake
|
50
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
51
66
|
none: false
|
52
67
|
requirements:
|
53
68
|
- - ! '>='
|
@@ -55,7 +70,12 @@ dependencies:
|
|
55
70
|
version: '0'
|
56
71
|
type: :development
|
57
72
|
prerelease: false
|
58
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
59
79
|
description: An instrumentation utility.
|
60
80
|
email:
|
61
81
|
- anordman@majorleaguegaming.com
|
@@ -76,8 +96,13 @@ files:
|
|
76
96
|
- lib/strumbar/instrumentation.rb
|
77
97
|
- lib/strumbar/instrumentation/action_controller.rb
|
78
98
|
- lib/strumbar/instrumentation/active_record.rb
|
99
|
+
- lib/strumbar/instrumentation/mongoid.rb
|
100
|
+
- lib/strumbar/instrumentation/mongoid/controller_runtime.rb
|
101
|
+
- lib/strumbar/instrumentation/mongoid/runtime_tracker.rb
|
79
102
|
- lib/strumbar/instrumentation/redis.rb
|
80
103
|
- lib/strumbar/version.rb
|
104
|
+
- spec/instrumentation/mongoid/controller_runtime_spec.rb
|
105
|
+
- spec/instrumentation/mongoid/runtime_tracker_spec.rb
|
81
106
|
- spec/instrumentation/redis_spec.rb
|
82
107
|
- spec/instrumentation_spec.rb
|
83
108
|
- spec/spec_helper.rb
|
@@ -97,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
122
|
version: '0'
|
98
123
|
segments:
|
99
124
|
- 0
|
100
|
-
hash:
|
125
|
+
hash: 4031522421417010496
|
101
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
127
|
none: false
|
103
128
|
requirements:
|
@@ -106,14 +131,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
131
|
version: '0'
|
107
132
|
segments:
|
108
133
|
- 0
|
109
|
-
hash:
|
134
|
+
hash: 4031522421417010496
|
110
135
|
requirements: []
|
111
136
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.8.
|
137
|
+
rubygems_version: 1.8.24
|
113
138
|
signing_key:
|
114
139
|
specification_version: 3
|
115
140
|
summary: Helper library to strum along in your application.
|
116
141
|
test_files:
|
142
|
+
- spec/instrumentation/mongoid/controller_runtime_spec.rb
|
143
|
+
- spec/instrumentation/mongoid/runtime_tracker_spec.rb
|
117
144
|
- spec/instrumentation/redis_spec.rb
|
118
145
|
- spec/instrumentation_spec.rb
|
119
146
|
- spec/spec_helper.rb
|