peek-mongo 1.1.0 → 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 48895e9d990e1d81676d587e2db0fb0ffd8c6361
4
+ data.tar.gz: 7201cbea459ce896e9b0973820588f7ca1e688a8
5
+ SHA512:
6
+ metadata.gz: 715ea029257f778a2babe33153ca986d36fd604cc0f6d0a733f1014ce5f9f236c04a651ad7e39fbf96f1fae6ecd8259b0af7d03f1c13e2324edc3e654f822a55
7
+ data.tar.gz: a9a0d0460cafd74a504bbfaba3d590ec3de3b7451019dc8df96a26c1594ec1a35698436605c80d4a0a5fe1ea516fccd783ba242ab0b1091f9e043e5fff19113d
data/CHANGELOG.md CHANGED
@@ -9,3 +9,7 @@
9
9
  # 1.1.0
10
10
 
11
11
  - Query count and Query time are now threadsafe.
12
+
13
+ # 1.2.0
14
+
15
+ - Use `Module#prepend` over `alias_method_chain` - #4 @NJ-Scioly
@@ -1,5 +1,5 @@
1
1
  module Peek
2
2
  module Mongo
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -1,57 +1,83 @@
1
1
  require 'mongo'
2
- require 'atomic'
2
+ require 'concurrent'
3
3
 
4
- # At the deepest of all commands in mongo go to Mongo::Connection
5
- # and the following methods:
6
- #
7
- # - :send_message
8
- # - :send_message_with_gle
9
- # - :receive_message
4
+ module Peek
5
+ # Query times are logged by timing the Socket class of the Mongo Ruby Driver
6
+ module MongoSocketInstrumented
7
+ def read(*args, &block)
8
+ start = Time.now
9
+ super(*args, &block)
10
+ ensure
11
+ duration = (Time.now - start)
12
+ ::Mongo::Socket.query_time.update { |value| value + duration }
13
+ end
10
14
 
11
- # Instrument Mongo time
12
- class Mongo::Connection
13
- class << self
14
- attr_accessor :command_time, :command_count
15
+ def write(*args, &block)
16
+ start = Time.now
17
+ super(*args, &block)
18
+ ensure
19
+ duration = (Time.now - start)
20
+ ::Mongo::Socket.query_time.update { |value| value + duration }
21
+ end
15
22
  end
16
- self.command_count = Atomic.new(0)
17
- self.command_time = Atomic.new(0)
18
-
19
- def send_message_with_timing(*args)
20
- start = Time.now
21
- send_message_without_timing(*args)
22
- ensure
23
- duration = (Time.now - start)
24
- Mongo::Connection.command_time.update { |value| value + duration }
25
- Mongo::Connection.command_count.update { |value| value + 1 }
23
+
24
+ # Query counts are logged to the Socket class by monitoring payload generation
25
+ module MongoProtocolInstrumented
26
+ def payload
27
+ super
28
+ ensure
29
+ ::Mongo::Protocol::Message.query_count.update { |value| value + 1 }
30
+ end
26
31
  end
27
- alias_method_chain :send_message, :timing
28
-
29
- def send_message_with_gle_with_timing(*args)
30
- start = Time.now
31
- send_message_with_gle_without_timing(*args)
32
- ensure
33
- duration = (Time.now - start)
34
- Mongo::Connection.command_time.update { |value| value + duration }
35
- Mongo::Connection.command_count.update { |value| value + 1 }
32
+ end
33
+
34
+ # The Socket class will keep track of timing
35
+ # The MongoSocketInstrumented class overrides the read and write methods, rerporting the total count as the attribute :query_count
36
+ class Mongo::Socket
37
+ prepend Peek::MongoSocketInstrumented
38
+ class << self
39
+ attr_accessor :query_time
36
40
  end
37
- alias_method_chain :send_message_with_gle, :timing
38
-
39
- def receive_message_with_timing(*args)
40
- start = Time.now
41
- receive_message_without_timing(*args)
42
- ensure
43
- duration = (Time.now - start)
44
- Mongo::Connection.command_time.update { |value| value + duration }
45
- Mongo::Connection.command_count.update { |value| value + 1 }
41
+ self.query_time = Concurrent::AtomicFixnum.new(0)
42
+ end
43
+
44
+ # The Message class will keep track of count
45
+ # Nothing is overridden here, only an attribute for counting is added
46
+ class Mongo::Protocol::Message
47
+ class << self
48
+ attr_accessor :query_count
46
49
  end
47
- alias_method_chain :receive_message, :timing
50
+ self.query_count = Concurrent::AtomicFixnum.new(0)
51
+ end
52
+
53
+ ## Following classes all override the various Mongo command classes in Protocol to add counting
54
+ # The actual counting for each class is stored in Mongo::Protocol::Message
55
+
56
+ class Mongo::Protocol::Query
57
+ prepend Peek::MongoProtocolInstrumented
58
+ end
59
+
60
+ class Mongo::Protocol::Insert
61
+ prepend Peek::MongoProtocolInstrumented
62
+ end
63
+
64
+ class Mongo::Protocol::Update
65
+ prepend Peek::MongoProtocolInstrumented
66
+ end
67
+
68
+ class Mongo::Protocol::GetMore
69
+ prepend Peek::MongoProtocolInstrumented
70
+ end
71
+
72
+ class Mongo::Protocol::Delete
73
+ prepend Peek::MongoProtocolInstrumented
48
74
  end
49
75
 
50
76
  module Peek
51
77
  module Views
52
78
  class Mongo < View
53
79
  def duration
54
- ::Mongo::Connection.command_time.value
80
+ ::Mongo::Socket.query_time.value
55
81
  end
56
82
 
57
83
  def formatted_duration
@@ -64,7 +90,7 @@ module Peek
64
90
  end
65
91
 
66
92
  def calls
67
- ::Mongo::Connection.command_count.value
93
+ ::Mongo::Protocol::Message.query_count.value
68
94
  end
69
95
 
70
96
  def results
@@ -75,9 +101,9 @@ module Peek
75
101
 
76
102
  def setup_subscribers
77
103
  # Reset each counter when a new request starts
78
- before_request do
79
- ::Mongo::Connection.command_time.value = 0
80
- ::Mongo::Connection.command_count.value = 0
104
+ subscribe 'start_processing.action_controller' do
105
+ ::Mongo::Socket.query_time.value = 0
106
+ ::Mongo::Protocol::Message.query_count.value = 0
81
107
  end
82
108
  end
83
109
  end
data/peek-mongo.gemspec CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ['lib']
19
19
 
20
20
  gem.add_dependency 'peek'
21
- gem.add_dependency 'mongo', '>= 1.8'
22
- gem.add_dependency 'atomic', '>= 1.0.0'
21
+ gem.add_dependency 'mongo', '>= 2.4.1'
22
+ gem.add_dependency 'concurrent-ruby', '>= 1.0.4'
23
23
  end
metadata CHANGED
@@ -1,64 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peek-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Garrett Bjerkhoel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-28 00:00:00.000000000 Z
11
+ date: 2017-05-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: peek
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: mongo
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
- version: '1.8'
33
+ version: 2.4.1
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
- version: '1.8'
40
+ version: 2.4.1
46
41
  - !ruby/object:Gem::Dependency
47
- name: atomic
42
+ name: concurrent-ruby
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: 1.0.0
47
+ version: 1.0.4
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
- version: 1.0.0
54
+ version: 1.0.4
62
55
  description: Take a peek into the Mongo commands made within your Rails application.
63
56
  email:
64
57
  - me@garrettbjerkhoel.com
@@ -66,7 +59,7 @@ executables: []
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - .gitignore
62
+ - ".gitignore"
70
63
  - CHANGELOG.md
71
64
  - Gemfile
72
65
  - LICENSE.txt
@@ -80,26 +73,26 @@ files:
80
73
  - peek-mongo.gemspec
81
74
  homepage: https://github.com/peek/peek-mongo
82
75
  licenses: []
76
+ metadata: {}
83
77
  post_install_message:
84
78
  rdoc_options: []
85
79
  require_paths:
86
80
  - lib
87
81
  required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
82
  requirements:
90
- - - ! '>='
83
+ - - ">="
91
84
  - !ruby/object:Gem::Version
92
85
  version: '0'
93
86
  required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
87
  requirements:
96
- - - ! '>='
88
+ - - ">="
97
89
  - !ruby/object:Gem::Version
98
90
  version: '0'
99
91
  requirements: []
100
92
  rubyforge_project:
101
- rubygems_version: 1.8.23
93
+ rubygems_version: 2.5.1
102
94
  signing_key:
103
- specification_version: 3
95
+ specification_version: 4
104
96
  summary: Take a peek into the Mongo commands made within your Rails application.
105
97
  test_files: []
98
+ has_rdoc: