marginalia 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of marginalia might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +5 -0
- data/lib/marginalia.rb +30 -20
- data/lib/marginalia/comment.rb +37 -0
- data/marginalia.gemspec +1 -1
- data/test/query_comments_test.rb +34 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d1334e6fae088b614c33883053c675e8ce3208
|
4
|
+
data.tar.gz: ea48070a0ad0b210045ff6cc8eb485d9db115e3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06d3dc8986bdfc70351ece60860aa79e4822f83e0cbcc0cb8211c9197dbf4fa8320f1017f15cbfa9aac40c296ae6a37f8054aa566fac832fe2f02d628d65d073
|
7
|
+
data.tar.gz: fdee2ee3f3e0bec89b52e54c22056811d7bd4e4cd167d6ef38e00446f25c16cc03f3cd730f4e8456a32ba67ff66b39046a2adb289acb0c9d4a8fc149b75957ba
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -93,6 +93,11 @@ default. In addition, implementation is provided for:
|
|
93
93
|
* `:hostname` to include ```Socket.gethostname```.
|
94
94
|
* `:pid` to include current process id.
|
95
95
|
|
96
|
+
With ActiveRecord >= 3.2.19:
|
97
|
+
* `:db_host` to include the configured database hostname.
|
98
|
+
* `:socket` to include the configured database socket.
|
99
|
+
* `:database` to include the configured database name.
|
100
|
+
|
96
101
|
Pull requests for other included comment components are welcome.
|
97
102
|
|
98
103
|
## Contributing
|
data/lib/marginalia.rb
CHANGED
@@ -12,34 +12,40 @@ module Marginalia
|
|
12
12
|
alias_method :execute, :execute_with_marginalia
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
if instrumented_class.private_method_defined?(:execute_and_clear)
|
16
|
+
alias_method :execute_and_clear_without_marginalia, :execute_and_clear
|
17
|
+
alias_method :execute_and_clear, :execute_and_clear_with_marginalia
|
18
|
+
else
|
19
|
+
is_mysql2 = defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) &&
|
20
|
+
ActiveRecord::ConnectionAdapters::Mysql2Adapter == instrumented_class
|
21
|
+
# Dont instrument exec_query on mysql2 and AR 3.2+, as it calls execute internally
|
22
|
+
unless is_mysql2 && ActiveRecord::VERSION::STRING > "3.1"
|
23
|
+
if instrumented_class.method_defined?(:exec_query)
|
24
|
+
alias_method :exec_query_without_marginalia, :exec_query
|
25
|
+
alias_method :exec_query, :exec_query_with_marginalia
|
26
|
+
end
|
22
27
|
end
|
23
|
-
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
is_postgres = defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) &&
|
30
|
+
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter == instrumented_class
|
31
|
+
# Instrument exec_delete and exec_update on AR 3.2+, since they don't
|
32
|
+
# call execute internally
|
33
|
+
if is_postgres && ActiveRecord::VERSION::STRING > "3.1"
|
34
|
+
if instrumented_class.method_defined?(:exec_delete)
|
35
|
+
alias_method :exec_delete_without_marginalia, :exec_delete
|
36
|
+
alias_method :exec_delete, :exec_delete_with_marginalia
|
37
|
+
end
|
38
|
+
if instrumented_class.method_defined?(:exec_update)
|
39
|
+
alias_method :exec_update_without_marginalia, :exec_update
|
40
|
+
alias_method :exec_update, :exec_update_with_marginalia
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
42
47
|
def annotate_sql(sql)
|
48
|
+
Marginalia::Comment.update_adapter!(self)
|
43
49
|
comment = Marginalia::Comment.construct_comment
|
44
50
|
if comment.present? && !sql.include?(comment)
|
45
51
|
"#{sql} /*#{comment}*/"
|
@@ -70,6 +76,10 @@ module Marginalia
|
|
70
76
|
def exec_update_with_marginalia(sql, name = 'SQL', binds = [])
|
71
77
|
exec_update_without_marginalia(annotate_sql(sql), name, binds)
|
72
78
|
end
|
79
|
+
|
80
|
+
def execute_and_clear_with_marginalia(sql, *args, &block)
|
81
|
+
execute_and_clear_without_marginalia(annotate_sql(sql), *args, &block)
|
82
|
+
end
|
73
83
|
end
|
74
84
|
|
75
85
|
module ActionControllerInstrumentation
|
data/lib/marginalia/comment.rb
CHANGED
@@ -13,6 +13,10 @@ module Marginalia
|
|
13
13
|
self.marginalia_job = job
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.update_adapter!(adapter)
|
17
|
+
self.marginalia_adapter = adapter
|
18
|
+
end
|
19
|
+
|
16
20
|
def self.construct_comment
|
17
21
|
ret = ''
|
18
22
|
self.components.each do |c|
|
@@ -50,6 +54,14 @@ module Marginalia
|
|
50
54
|
Thread.current[:marginalia_job]
|
51
55
|
end
|
52
56
|
|
57
|
+
def self.marginalia_adapter=(adapter)
|
58
|
+
Thread.current[:marginalia_adapter] = adapter
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.marginalia_adapter
|
62
|
+
Thread.current[:marginalia_adapter]
|
63
|
+
end
|
64
|
+
|
53
65
|
def self.application
|
54
66
|
if defined?(Rails.application)
|
55
67
|
Marginalia.application_name ||= Rails.application.class.name.split("::").first
|
@@ -109,6 +121,31 @@ module Marginalia
|
|
109
121
|
marginalia_controller.request.uuid
|
110
122
|
end
|
111
123
|
end
|
124
|
+
|
125
|
+
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('3.2.19')
|
126
|
+
def self.socket
|
127
|
+
if self.connection_config.present?
|
128
|
+
self.connection_config[:socket]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.db_host
|
133
|
+
if self.connection_config.present?
|
134
|
+
self.connection_config[:host]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.database
|
139
|
+
if self.connection_config.present?
|
140
|
+
self.connection_config[:database]
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.connection_config
|
145
|
+
return if marginalia_adapter.pool.nil?
|
146
|
+
marginalia_adapter.pool.spec.config
|
147
|
+
end
|
148
|
+
end
|
112
149
|
end
|
113
150
|
|
114
151
|
end
|
data/marginalia.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.test_files = `git ls-files -- {test}/*`.split("\n")
|
9
9
|
gem.name = "marginalia"
|
10
10
|
gem.require_paths = ["lib"]
|
11
|
-
gem.version = "1.
|
11
|
+
gem.version = "1.5.0"
|
12
12
|
gem.license = "MIT"
|
13
13
|
|
14
14
|
gem.add_runtime_dependency "actionpack", ">= 2.3"
|
data/test/query_comments_test.rb
CHANGED
@@ -13,6 +13,10 @@ def active_job_available?
|
|
13
13
|
Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('4.2')
|
14
14
|
end
|
15
15
|
|
16
|
+
def adapter_pool_available?
|
17
|
+
Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('3.2.19')
|
18
|
+
end
|
19
|
+
|
16
20
|
require "minitest/autorun"
|
17
21
|
require 'mocha/test_unit'
|
18
22
|
require 'logger'
|
@@ -114,6 +118,12 @@ class MarginaliaTest < MiniTest::Test
|
|
114
118
|
ActiveRecord::Base.connection.unstub(:annotate_sql)
|
115
119
|
end
|
116
120
|
|
121
|
+
def test_exists
|
122
|
+
skip if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new('3.2')
|
123
|
+
Post.exists?
|
124
|
+
assert_match %r{/\*application:rails\*/$}, @queries.last
|
125
|
+
end
|
126
|
+
|
117
127
|
def test_query_commenting_on_mysql_driver_with_no_action
|
118
128
|
ActiveRecord::Base.connection.execute "select id from posts"
|
119
129
|
assert_match %r{select id from posts /\*application:rails\*/$}, @queries.first
|
@@ -205,6 +215,30 @@ class MarginaliaTest < MiniTest::Test
|
|
205
215
|
assert_match %r{/\*controller_with_namespace:API::V1::PostsController}, @queries.first
|
206
216
|
end
|
207
217
|
|
218
|
+
if adapter_pool_available?
|
219
|
+
def test_db_host
|
220
|
+
Marginalia::Comment.components = [:db_host]
|
221
|
+
API::V1::PostsController.action(:driver_only).call(@env)
|
222
|
+
assert_match %r{/\*db_host:localhost}, @queries.first
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_database
|
226
|
+
Marginalia::Comment.components = [:database]
|
227
|
+
API::V1::PostsController.action(:driver_only).call(@env)
|
228
|
+
assert_match %r{/\*database:marginalia_test}, @queries.first
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_socket
|
232
|
+
# setting socket in configuration would break some connections - mock it instead
|
233
|
+
pool = ActiveRecord::Base.connection_pool
|
234
|
+
pool.spec.stubs(:config).returns({:socket => "marginalia_socket"})
|
235
|
+
Marginalia::Comment.components = [:socket]
|
236
|
+
API::V1::PostsController.action(:driver_only).call(@env)
|
237
|
+
assert_match %r{/\*socket:marginalia_socket}, @queries.first
|
238
|
+
pool.spec.unstub(:config)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
208
242
|
if request_id_available?
|
209
243
|
def test_request_id
|
210
244
|
@env["action_dispatch.request_id"] = "some-uuid"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marginalia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Lorang
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-09-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
requirements: []
|
181
181
|
rubyforge_project:
|
182
|
-
rubygems_version: 2.6.
|
182
|
+
rubygems_version: 2.6.11
|
183
183
|
signing_key:
|
184
184
|
specification_version: 4
|
185
185
|
summary: Attach comments to your ActiveRecord queries.
|