newrelic_moped 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Rakefile +9 -2
- data/lib/newrelic_moped/instrumentation.rb +36 -18
- data/lib/newrelic_moped/version.rb +1 -1
- data/newrelic_moped.gemspec +4 -0
- data/test/instrumentation_test.rb +36 -5
- data/test/moped_command_fake.rb +27 -0
- metadata +55 -3
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -13,28 +13,46 @@ DependencyDetection.defer do
|
|
13
13
|
|
14
14
|
executes do
|
15
15
|
Moped::Node.class_eval do
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
include NewRelic::Moped::Instrumentation
|
17
|
+
alias_method :logging_without_newrelic_trace, :logging
|
18
|
+
alias_method :logging, :logging_with_newrelic_trace
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
23
|
+
module NewRelic
|
24
|
+
module Moped
|
25
|
+
module Instrumentation
|
26
|
+
def logging_with_newrelic_trace(operations, &blk)
|
27
|
+
operation_name, collection = determine_operation_and_collection(operations.first)
|
28
|
+
log_statement = operations.first.log_inspect
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
nil, elapsed_time)
|
31
|
-
end
|
32
|
-
end
|
30
|
+
self.class.trace_execution_scoped("Database/#{collection}/#{operation_name}") do
|
31
|
+
t0 = Time.now
|
32
|
+
res = logging_without_newrelic_trace(operations, &blk)
|
33
|
+
elapsed_time = (Time.now - t0).to_f
|
34
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(log_statement, nil, elapsed_time)
|
35
|
+
NewRelic::Agent.instance.sql_sampler.notice_sql(log_statement, nil, nil, elapsed_time)
|
36
|
+
res
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
36
|
-
|
37
|
-
|
40
|
+
def determine_operation_and_collection(operation)
|
41
|
+
log_statement = operation.log_inspect
|
42
|
+
collection = "Unknown"
|
43
|
+
if operation.respond_to?(:collection)
|
44
|
+
collection = operation.collection
|
45
|
+
end
|
46
|
+
operation_name = log_statement.split[0]
|
47
|
+
if operation_name == 'COMMAND' && log_statement.include?(":mapreduce")
|
48
|
+
operation_name = 'MAPREDUCE'
|
49
|
+
collection = log_statement[/:mapreduce=>"([^"]+)/,1]
|
50
|
+
elsif operation_name == 'COMMAND' && log_statement.include?(":count")
|
51
|
+
operation_name = 'COUNT'
|
52
|
+
collection = log_statement[/:count=>"([^"]+)/,1]
|
53
|
+
end
|
54
|
+
return operation_name, collection
|
55
|
+
end
|
38
56
|
end
|
39
57
|
end
|
40
|
-
end
|
58
|
+
end
|
data/newrelic_moped.gemspec
CHANGED
@@ -14,4 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.name = "newrelic_moped"
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = NewrelicMoped::VERSION
|
17
|
+
gem.add_dependency 'newrelic_rpm', '~> 3.5.3.25'
|
18
|
+
gem.add_dependency 'moped'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
17
21
|
end
|
@@ -3,6 +3,7 @@ require 'test/unit'
|
|
3
3
|
require 'moped'
|
4
4
|
|
5
5
|
require File.expand_path(File.dirname(__FILE__) + '/../lib/newrelic_moped/instrumentation')
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + '/moped_command_fake')
|
6
7
|
|
7
8
|
class FakeOpWithCollection < Struct.new(:collection, :log_inspect)
|
8
9
|
end
|
@@ -14,18 +15,16 @@ class TestInstrumentation < Test::Unit::TestCase
|
|
14
15
|
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
15
16
|
|
16
17
|
def setup
|
17
|
-
DependencyDetection.detect!
|
18
18
|
NewRelic::Agent.manual_start
|
19
19
|
@engine = NewRelic::Agent.instance.stats_engine
|
20
20
|
@engine.clear_stats
|
21
21
|
|
22
22
|
@sampler = NewRelic::Agent.instance.transaction_sampler
|
23
|
-
@sampler.enable
|
24
23
|
@sampler.reset!
|
25
24
|
@sampler.start_builder
|
26
25
|
|
27
26
|
Moped::Node.class_eval do
|
28
|
-
def
|
27
|
+
def logging_with_newrelic_trace(operations, &callback)
|
29
28
|
# do nothing
|
30
29
|
end
|
31
30
|
end
|
@@ -41,7 +40,7 @@ class TestInstrumentation < Test::Unit::TestCase
|
|
41
40
|
fake_op = FakeOpWithCollection.new([], "Fake")
|
42
41
|
|
43
42
|
assert_nothing_raised do
|
44
|
-
@node.
|
43
|
+
@node.logging_with_newrelic_trace(fake_op)
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
@@ -49,7 +48,39 @@ class TestInstrumentation < Test::Unit::TestCase
|
|
49
48
|
fake_op = FakeOpWithoutCollection.new("Fake")
|
50
49
|
|
51
50
|
assert_nothing_raised do
|
52
|
-
@node.
|
51
|
+
@node.logging_with_newrelic_trace(fake_op)
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
55
|
+
|
56
|
+
class NewRelicMopedInstrumentationTest < Test::Unit::TestCase
|
57
|
+
include NewRelic::Moped::Instrumentation
|
58
|
+
|
59
|
+
def test_when_command_is_mapreduce
|
60
|
+
command = MopedCommandWithCollectionFake.new("COMMAND database=my_database command={:mapreduce=>\"users\", :query=>{}}", "other_collection")
|
61
|
+
operation, collection = determine_operation_and_collection(command)
|
62
|
+
assert_equal("MAPREDUCE", operation)
|
63
|
+
assert_equal("users", collection, "it should parse collection from statement")
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_query_when_operation_responds_to_collection
|
67
|
+
command = MopedCommandWithCollectionFake.new("QUERY database=my_database collection=xyz", "users")
|
68
|
+
operation, collection = determine_operation_and_collection(command)
|
69
|
+
assert_equal("QUERY", operation)
|
70
|
+
assert_equal("users", collection, "it should use collection from operation")
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_when_command_is_count
|
74
|
+
command = MopedCommandWithCollectionFake.new("COMMAND database=my_database command={:count=>\"users\", query=>{}}", "other_collection")
|
75
|
+
operation, collection = determine_operation_and_collection(command)
|
76
|
+
assert_equal("COUNT", operation)
|
77
|
+
assert_equal("users", collection, "it should parse collection from statement")
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_command_when_operation_does_not_respond_to_collection
|
81
|
+
command = MopedCommandFake.new("COMMAND database=admin command={:ismaster=>1}")
|
82
|
+
operation, collection = determine_operation_and_collection(command)
|
83
|
+
assert_equal("COMMAND", operation)
|
84
|
+
assert_equal("Unknown", collection, "it should set collection name to Unknown")
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
class MopedCommandFake
|
3
|
+
|
4
|
+
def initialize(log_statement)
|
5
|
+
@log_statement = log_statement
|
6
|
+
end
|
7
|
+
|
8
|
+
def log_inspect
|
9
|
+
@log_statement
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class MopedCommandWithCollectionFake
|
14
|
+
|
15
|
+
def initialize(log_statement, collection)
|
16
|
+
@log_statement = log_statement
|
17
|
+
@collection = collection
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_inspect
|
21
|
+
@log_statement
|
22
|
+
end
|
23
|
+
|
24
|
+
def collection
|
25
|
+
@collection
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newrelic_moped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,56 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-12-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: newrelic_rpm
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.5.3.25
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.5.3.25
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: moped
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
14
62
|
description: New Relic Instrumentation for Moped & Mongoid 3
|
15
63
|
email:
|
16
64
|
- stephenbartholomew@gmail.com
|
@@ -19,6 +67,7 @@ extensions: []
|
|
19
67
|
extra_rdoc_files: []
|
20
68
|
files:
|
21
69
|
- .gitignore
|
70
|
+
- Gemfile
|
22
71
|
- LICENSE
|
23
72
|
- README.md
|
24
73
|
- Rakefile
|
@@ -27,6 +76,7 @@ files:
|
|
27
76
|
- lib/newrelic_moped/version.rb
|
28
77
|
- newrelic_moped.gemspec
|
29
78
|
- test/instrumentation_test.rb
|
79
|
+
- test/moped_command_fake.rb
|
30
80
|
homepage: ''
|
31
81
|
licenses: []
|
32
82
|
post_install_message:
|
@@ -53,3 +103,5 @@ specification_version: 3
|
|
53
103
|
summary: New Relic Instrumentation for Moped & Mongoid 3
|
54
104
|
test_files:
|
55
105
|
- test/instrumentation_test.rb
|
106
|
+
- test/moped_command_fake.rb
|
107
|
+
has_rdoc:
|