newrelic_moped 0.0.4.1 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/newrelic_moped/instrumentation.rb +35 -13
- data/lib/newrelic_moped/version.rb +1 -1
- metadata +8 -16
- data/.gitignore +0 -18
- data/Gemfile +0 -4
- data/Rakefile +0 -9
- data/newrelic_moped.gemspec +0 -21
- data/test/instrumentation_test.rb +0 -86
- data/test/moped_command_fake.rb +0 -27
@@ -4,11 +4,11 @@ DependencyDetection.defer do
|
|
4
4
|
@name = :moped
|
5
5
|
|
6
6
|
depends_on do
|
7
|
-
defined?(::Moped)
|
7
|
+
defined?(::Moped) && !NewRelic::Control.instance['disable_moped']
|
8
8
|
end
|
9
9
|
|
10
10
|
executes do
|
11
|
-
NewRelic::Agent.logger.
|
11
|
+
NewRelic::Agent.logger.info 'Installing Moped instrumentation'
|
12
12
|
end
|
13
13
|
|
14
14
|
executes do
|
@@ -25,20 +25,42 @@ module NewRelic
|
|
25
25
|
module Instrumentation
|
26
26
|
def logging_with_newrelic_trace(operations, &blk)
|
27
27
|
operation_name, collection = determine_operation_and_collection(operations.first)
|
28
|
-
log_statement = operations.first.log_inspect
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
log_statement = operations.first.log_inspect.encode("UTF-8")
|
29
|
+
|
30
|
+
metric = case operation_name
|
31
|
+
when 'INSERT', 'UPDATE', 'CREATE' then 'save'
|
32
|
+
when 'QUERY' then 'find'
|
33
|
+
when 'DELETE' then 'destroy'
|
34
|
+
else
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
command = Proc.new { logging_without_newrelic_trace(operations, &blk) }
|
39
|
+
res = nil
|
40
|
+
|
41
|
+
if metric
|
42
|
+
metrics = ["ActiveRecord/all", "ActiveRecord/#{collection}/#{metric}"]
|
43
|
+
|
44
|
+
self.class.trace_execution_scoped(metrics) do
|
45
|
+
t0 = Time.now
|
46
|
+
begin
|
47
|
+
res = command.call
|
48
|
+
ensure
|
49
|
+
elapsed_time = (Time.now - t0).to_f
|
50
|
+
|
51
|
+
NewRelic::Agent.instance.transaction_sampler.notice_sql(log_statement, nil, elapsed_time)
|
52
|
+
NewRelic::Agent.instance.sql_sampler.notice_sql(log_statement, metric, nil, elapsed_time)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
res = command.call
|
37
57
|
end
|
58
|
+
|
59
|
+
res
|
38
60
|
end
|
39
61
|
|
40
62
|
def determine_operation_and_collection(operation)
|
41
|
-
log_statement = operation.log_inspect
|
63
|
+
log_statement = operation.log_inspect.encode("UTF-8")
|
42
64
|
collection = "Unknown"
|
43
65
|
if operation.respond_to?(:collection)
|
44
66
|
collection = operation.collection
|
@@ -55,4 +77,4 @@ module NewRelic
|
|
55
77
|
end
|
56
78
|
end
|
57
79
|
end
|
58
|
-
end
|
80
|
+
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.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: newrelic_rpm
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.
|
21
|
+
version: 3.6.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 3.
|
29
|
+
version: 3.6.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: moped
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,17 +66,11 @@ executables: []
|
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
|
-
- .gitignore
|
70
|
-
- Gemfile
|
71
|
-
- LICENSE
|
72
|
-
- README.md
|
73
|
-
- Rakefile
|
74
|
-
- lib/newrelic_moped.rb
|
75
69
|
- lib/newrelic_moped/instrumentation.rb
|
76
70
|
- lib/newrelic_moped/version.rb
|
77
|
-
- newrelic_moped.
|
78
|
-
-
|
79
|
-
-
|
71
|
+
- lib/newrelic_moped.rb
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
80
74
|
homepage: ''
|
81
75
|
licenses: []
|
82
76
|
post_install_message:
|
@@ -101,7 +95,5 @@ rubygems_version: 1.8.23
|
|
101
95
|
signing_key:
|
102
96
|
specification_version: 3
|
103
97
|
summary: New Relic Instrumentation for Moped & Mongoid 3
|
104
|
-
test_files:
|
105
|
-
- test/instrumentation_test.rb
|
106
|
-
- test/moped_command_fake.rb
|
98
|
+
test_files: []
|
107
99
|
has_rdoc:
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/newrelic_moped.gemspec
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/newrelic_moped/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Stephen Bartholomew"]
|
6
|
-
gem.email = ["stephenbartholomew@gmail.com"]
|
7
|
-
gem.description = %q{New Relic Instrumentation for Moped & Mongoid 3}
|
8
|
-
gem.summary = %q{New Relic Instrumentation for Moped & Mongoid 3}
|
9
|
-
gem.homepage = ""
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "newrelic_moped"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = NewrelicMoped::VERSION
|
17
|
-
gem.add_dependency 'newrelic_rpm', '~> 3.5.1'
|
18
|
-
gem.add_dependency 'moped'
|
19
|
-
|
20
|
-
gem.add_development_dependency 'rake'
|
21
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'moped'
|
4
|
-
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/newrelic_moped/instrumentation')
|
6
|
-
require File.expand_path(File.dirname(__FILE__) + '/moped_command_fake')
|
7
|
-
|
8
|
-
class FakeOpWithCollection < Struct.new(:collection, :log_inspect)
|
9
|
-
end
|
10
|
-
|
11
|
-
class FakeOpWithoutCollection < Struct.new(:log_inspect)
|
12
|
-
end
|
13
|
-
|
14
|
-
class TestInstrumentation < Test::Unit::TestCase
|
15
|
-
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
16
|
-
|
17
|
-
def setup
|
18
|
-
NewRelic::Agent.manual_start
|
19
|
-
@engine = NewRelic::Agent.instance.stats_engine
|
20
|
-
@engine.clear_stats
|
21
|
-
|
22
|
-
@sampler = NewRelic::Agent.instance.transaction_sampler
|
23
|
-
@sampler.reset!
|
24
|
-
@sampler.start_builder
|
25
|
-
|
26
|
-
Moped::Node.class_eval do
|
27
|
-
def logging_with_newrelic_trace(operations, &callback)
|
28
|
-
# do nothing
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
@node = Moped::Node.new("127.0.0.1:27017")
|
33
|
-
end
|
34
|
-
|
35
|
-
def teardown
|
36
|
-
@sampler.clear_builder
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_handles_operations_with_collections
|
40
|
-
fake_op = FakeOpWithCollection.new([], "Fake")
|
41
|
-
|
42
|
-
assert_nothing_raised do
|
43
|
-
@node.logging_with_newrelic_trace(fake_op)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_ignores_operations_without_collection
|
48
|
-
fake_op = FakeOpWithoutCollection.new("Fake")
|
49
|
-
|
50
|
-
assert_nothing_raised do
|
51
|
-
@node.logging_with_newrelic_trace(fake_op)
|
52
|
-
end
|
53
|
-
end
|
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
|
data/test/moped_command_fake.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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
|