marginalia 1.7.0 → 1.10.1
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 +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +18 -0
- data/README.md +13 -1
- data/lib/marginalia.rb +33 -13
- data/lib/marginalia/comment.rb +10 -5
- data/marginalia.gemspec +2 -2
- data/test/query_comments_test.rb +38 -1
- metadata +6 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8dba7f58a767008578f36af3a2bedc77139f11b62025e1dcd022c1ebd3658c3c
|
4
|
+
data.tar.gz: 9d4728cbc7b673514cce7076a60c28592646fbc68ac59d8310c7ebe3aa71eac6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35dfdc97e0745484719266a9c616c257072dfbdf0ee8ff6b4c7055d051510a562bf12d863eae670c382f14eda7ba895f4a988baa031ea43904fd9a2a31fd7c0e
|
7
|
+
data.tar.gz: 3fbfdeacc57e3a8e78490e991527610a3249c0b3e748de7410a427e9e085e6b420a12d916b0c15d87a7240743a81e9be14727508743d25d7cc82d850924ad126
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.6
|
data/.travis.yml
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
|
4
|
+
services:
|
5
|
+
- mysql
|
6
|
+
- postgresql
|
7
|
+
|
4
8
|
rvm:
|
5
9
|
- 2.2
|
6
10
|
- 2.3
|
7
11
|
- 2.4
|
12
|
+
- 2.5
|
13
|
+
- 2.6
|
14
|
+
- 2.7
|
15
|
+
|
16
|
+
services:
|
17
|
+
- mysql
|
18
|
+
- postgresql
|
8
19
|
|
9
20
|
script: "bundle exec rake db:reset test:all"
|
10
21
|
|
@@ -14,3 +25,10 @@ gemfile:
|
|
14
25
|
- gemfiles/5.0.gemfile
|
15
26
|
- gemfiles/5.1.gemfile
|
16
27
|
- gemfiles/5.2.gemfile
|
28
|
+
|
29
|
+
matrix:
|
30
|
+
exclude:
|
31
|
+
- rvm: 2.7
|
32
|
+
gemfile: gemfiles/4.2.gemfile
|
33
|
+
- rvm: 2.7
|
34
|
+
gemfile: gemfiles/4.2.api.gemfile
|
data/README.md
CHANGED
@@ -56,6 +56,8 @@ Optionally, you can set the application name shown in the log like so in an init
|
|
56
56
|
For Rails 3 applications, the name will default to your Rails application name.
|
57
57
|
For Rails 2 applications, "rails" is used as the default application name.
|
58
58
|
|
59
|
+
#### Components
|
60
|
+
|
59
61
|
You can also configure the components of the comment that will be appended,
|
60
62
|
by setting `Marginalia::Comment.components`. By default, this is set to:
|
61
63
|
|
@@ -100,7 +102,17 @@ With ActiveRecord >= 3.2.19:
|
|
100
102
|
|
101
103
|
Pull requests for other included comment components are welcome.
|
102
104
|
|
103
|
-
|
105
|
+
#### Prepend comments
|
106
|
+
|
107
|
+
By default marginalia appends the comments at the end of the query. Certain databases, such as MySQL will truncate
|
108
|
+
the query text. This is the case for slow query logs and the results of querying some InnoDB internal tables where the
|
109
|
+
length of the query is more than 1024 bytes.
|
110
|
+
|
111
|
+
In order to not lose the marginalia comments from your logs, you can prepend the comments using this option:
|
112
|
+
|
113
|
+
Marginalia::Comment.prepend_comment = true
|
114
|
+
|
115
|
+
#### Inline query annotations
|
104
116
|
|
105
117
|
In addition to the request or job-level component-based annotations,
|
106
118
|
Marginalia may be used to add inline annotations to specific queries using a
|
data/lib/marginalia.rb
CHANGED
@@ -49,41 +49,61 @@ module Marginalia
|
|
49
49
|
Marginalia::Comment.update_adapter!(self)
|
50
50
|
comment = Marginalia::Comment.construct_comment
|
51
51
|
if comment.present? && !sql.include?(comment)
|
52
|
-
sql =
|
52
|
+
sql = if Marginalia::Comment.prepend_comment
|
53
|
+
"/*#{comment}*/ #{sql}"
|
54
|
+
else
|
55
|
+
"#{sql} /*#{comment}*/"
|
56
|
+
end
|
53
57
|
end
|
54
58
|
inline_comment = Marginalia::Comment.construct_inline_comment
|
55
|
-
if inline_comment.present?
|
56
|
-
sql =
|
59
|
+
if inline_comment.present? && !sql.include?(inline_comment)
|
60
|
+
sql = if Marginalia::Comment.prepend_comment
|
61
|
+
"/*#{inline_comment}*/ #{sql}"
|
62
|
+
else
|
63
|
+
"#{sql} /*#{inline_comment}*/"
|
64
|
+
end
|
57
65
|
end
|
66
|
+
|
58
67
|
sql
|
59
68
|
end
|
60
69
|
|
61
|
-
def execute_with_marginalia(sql,
|
62
|
-
execute_without_marginalia(annotate_sql(sql),
|
70
|
+
def execute_with_marginalia(sql, *args)
|
71
|
+
execute_without_marginalia(annotate_sql(sql), *args)
|
63
72
|
end
|
73
|
+
ruby2_keywords :execute_with_marginalia if respond_to?(:ruby2_keywords, true)
|
64
74
|
|
65
|
-
def exec_query_with_marginalia(sql,
|
66
|
-
exec_query_without_marginalia(annotate_sql(sql),
|
75
|
+
def exec_query_with_marginalia(sql, *args)
|
76
|
+
exec_query_without_marginalia(annotate_sql(sql), *args)
|
67
77
|
end
|
78
|
+
ruby2_keywords :exec_query_with_marginalia if respond_to?(:ruby2_keywords, true)
|
68
79
|
|
69
80
|
if ActiveRecord::VERSION::MAJOR >= 5
|
70
|
-
def exec_query_with_marginalia(sql,
|
81
|
+
def exec_query_with_marginalia(sql, *args, **options)
|
71
82
|
options[:prepare] ||= false
|
72
|
-
exec_query_without_marginalia(annotate_sql(sql),
|
83
|
+
exec_query_without_marginalia(annotate_sql(sql), *args, **options)
|
73
84
|
end
|
74
85
|
end
|
75
86
|
|
76
|
-
def exec_delete_with_marginalia(sql,
|
77
|
-
exec_delete_without_marginalia(annotate_sql(sql),
|
87
|
+
def exec_delete_with_marginalia(sql, *args)
|
88
|
+
exec_delete_without_marginalia(annotate_sql(sql), *args)
|
78
89
|
end
|
90
|
+
ruby2_keywords :exec_delete_with_marginalia if respond_to?(:ruby2_keywords, true)
|
79
91
|
|
80
|
-
def exec_update_with_marginalia(sql,
|
81
|
-
exec_update_without_marginalia(annotate_sql(sql),
|
92
|
+
def exec_update_with_marginalia(sql, *args)
|
93
|
+
exec_update_without_marginalia(annotate_sql(sql), *args)
|
82
94
|
end
|
95
|
+
ruby2_keywords :exec_update_with_marginalia if respond_to?(:ruby2_keywords, true)
|
83
96
|
|
97
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
84
98
|
def execute_and_clear_with_marginalia(sql, *args, &block)
|
85
99
|
execute_and_clear_without_marginalia(annotate_sql(sql), *args, &block)
|
86
100
|
end
|
101
|
+
ruby2_keywords :execute_and_clear_with_marginalia if respond_to?(:ruby2_keywords, true)
|
102
|
+
else
|
103
|
+
def execute_and_clear_with_marginalia(sql, *args, &block)
|
104
|
+
execute_and_clear_without_marginalia(annotate_sql(sql), *args, &block)
|
105
|
+
end
|
106
|
+
end
|
87
107
|
end
|
88
108
|
|
89
109
|
module ActionControllerInstrumentation
|
data/lib/marginalia/comment.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'socket'
|
2
4
|
|
3
5
|
module Marginalia
|
4
6
|
module Comment
|
5
|
-
mattr_accessor :components, :lines_to_ignore
|
7
|
+
mattr_accessor :components, :lines_to_ignore, :prepend_comment
|
6
8
|
Marginalia::Comment.components ||= [:application, :controller, :action]
|
7
9
|
|
8
10
|
def self.update!(controller = nil)
|
@@ -18,11 +20,11 @@ module Marginalia
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.construct_comment
|
21
|
-
ret =
|
23
|
+
ret = String.new
|
22
24
|
self.components.each do |c|
|
23
25
|
component_value = self.send(c)
|
24
26
|
if component_value.present?
|
25
|
-
ret << "#{c
|
27
|
+
ret << "#{c}:#{component_value},"
|
26
28
|
end
|
27
29
|
end
|
28
30
|
ret.chop!
|
@@ -102,11 +104,14 @@ module Marginalia
|
|
102
104
|
end
|
103
105
|
|
104
106
|
def self.sidekiq_job
|
105
|
-
marginalia_job["class"] if marginalia_job
|
107
|
+
marginalia_job["class"] if marginalia_job && marginalia_job.respond_to?(:[])
|
106
108
|
end
|
107
109
|
|
110
|
+
DEFAULT_LINES_TO_IGNORE_REGEX = %r{\.rvm|/ruby/gems/|vendor/|marginalia|rbenv|monitor\.rb.*mon_synchronize}
|
111
|
+
|
108
112
|
def self.line
|
109
|
-
Marginalia::Comment.lines_to_ignore ||=
|
113
|
+
Marginalia::Comment.lines_to_ignore ||= DEFAULT_LINES_TO_IGNORE_REGEX
|
114
|
+
|
110
115
|
last_line = caller.detect do |line|
|
111
116
|
line !~ Marginalia::Comment.lines_to_ignore
|
112
117
|
end
|
data/marginalia.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.authors = ["Noah Lorang", "Nick Quaranto", "Taylor Weibley"]
|
3
|
-
gem.email = ["
|
3
|
+
gem.email = ["arthurnn@github.com"]
|
4
4
|
gem.homepage = "https://github.com/basecamp/marginalia"
|
5
5
|
|
6
6
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -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.10.1"
|
12
12
|
gem.license = "MIT"
|
13
13
|
|
14
14
|
gem.add_runtime_dependency "actionpack", ">= 2.3"
|
data/test/query_comments_test.rb
CHANGED
@@ -121,6 +121,7 @@ class MarginaliaTest < MiniTest::Test
|
|
121
121
|
@queries << args.last[:sql]
|
122
122
|
end
|
123
123
|
@env = Rack::MockRequest.env_for('/')
|
124
|
+
ActiveJob::Base.queue_adapter = :inline
|
124
125
|
end
|
125
126
|
|
126
127
|
def test_double_annotate
|
@@ -215,6 +216,16 @@ class MarginaliaTest < MiniTest::Test
|
|
215
216
|
assert_match %r{/\*line:.*lib/marginalia/comment.rb:[0-9]+}, @queries.first
|
216
217
|
end
|
217
218
|
|
219
|
+
def test_default_lines_to_ignore_regex
|
220
|
+
line = "/gems/a_gem/lib/a_gem.rb:1:in `some_method'"
|
221
|
+
call_stack = [line] + caller
|
222
|
+
|
223
|
+
assert_match(
|
224
|
+
call_stack.detect { |line| line !~ Marginalia::Comment::DEFAULT_LINES_TO_IGNORE_REGEX },
|
225
|
+
line
|
226
|
+
)
|
227
|
+
end
|
228
|
+
|
218
229
|
def test_hostname_and_pid
|
219
230
|
Marginalia::Comment.components = [:hostname, :pid]
|
220
231
|
PostsController.action(:driver_only).call(@env)
|
@@ -282,6 +293,15 @@ class MarginaliaTest < MiniTest::Test
|
|
282
293
|
Post.first
|
283
294
|
refute_match %{job:PostsJob}, @queries.last
|
284
295
|
end
|
296
|
+
|
297
|
+
def test_active_job_with_sidekiq
|
298
|
+
Marginalia::Comment.components = [:job, :sidekiq_job]
|
299
|
+
PostsJob.perform_later
|
300
|
+
assert_match %{job:PostsJob}, @queries.first
|
301
|
+
|
302
|
+
Post.first
|
303
|
+
refute_match %{job:PostsJob}, @queries.last
|
304
|
+
end
|
285
305
|
end
|
286
306
|
|
287
307
|
def test_sidekiq_job
|
@@ -290,13 +310,14 @@ class MarginaliaTest < MiniTest::Test
|
|
290
310
|
|
291
311
|
# Test harness does not run Sidekiq middlewares by default so include testing middleware.
|
292
312
|
Sidekiq::Testing.server_middleware do |chain|
|
293
|
-
|
313
|
+
chain.add Marginalia::SidekiqInstrumentation::Middleware
|
294
314
|
end
|
295
315
|
|
296
316
|
Sidekiq::Testing.fake!
|
297
317
|
PostsSidekiqJob.perform_async
|
298
318
|
PostsSidekiqJob.drain
|
299
319
|
assert_match %{sidekiq_job:PostsSidekiqJob}, @queries.first
|
320
|
+
|
300
321
|
Post.first
|
301
322
|
refute_match %{sidekiq_job:PostsSidekiqJob}, @queries.last
|
302
323
|
end
|
@@ -341,6 +362,22 @@ class MarginaliaTest < MiniTest::Test
|
|
341
362
|
assert_match %r{/\*; DROP TABLE USERS;\*/$}, @queries.last
|
342
363
|
end
|
343
364
|
|
365
|
+
def test_inline_annotations_are_deduped
|
366
|
+
Marginalia.with_annotation("foo") do
|
367
|
+
ActiveRecord::Base.connection.execute "select id from posts /*foo*/"
|
368
|
+
end
|
369
|
+
assert_match %r{select id from posts /\*foo\*/ /\*application:rails\*/$}, @queries.first
|
370
|
+
end
|
371
|
+
|
372
|
+
def test_add_comments_to_beginning_of_query
|
373
|
+
Marginalia::Comment.prepend_comment = true
|
374
|
+
|
375
|
+
ActiveRecord::Base.connection.execute "select id from posts"
|
376
|
+
assert_match %r{/\*application:rails\*/ select id from posts$}, @queries.first
|
377
|
+
ensure
|
378
|
+
Marginalia::Comment.prepend_comment = nil
|
379
|
+
end
|
380
|
+
|
344
381
|
def teardown
|
345
382
|
Marginalia.application_name = nil
|
346
383
|
Marginalia::Comment.lines_to_ignore = nil
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marginalia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Lorang
|
8
8
|
- Nick Quaranto
|
9
9
|
- Taylor Weibley
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-02-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -140,7 +140,6 @@ dependencies:
|
|
140
140
|
version: '0'
|
141
141
|
description: Attach comments to your ActiveRecord queries.
|
142
142
|
email:
|
143
|
-
- noah@37signals.com
|
144
143
|
- arthurnn@github.com
|
145
144
|
executables: []
|
146
145
|
extensions: []
|
@@ -169,7 +168,7 @@ homepage: https://github.com/basecamp/marginalia
|
|
169
168
|
licenses:
|
170
169
|
- MIT
|
171
170
|
metadata: {}
|
172
|
-
post_install_message:
|
171
|
+
post_install_message:
|
173
172
|
rdoc_options: []
|
174
173
|
require_paths:
|
175
174
|
- lib
|
@@ -184,9 +183,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
183
|
- !ruby/object:Gem::Version
|
185
184
|
version: '0'
|
186
185
|
requirements: []
|
187
|
-
|
188
|
-
|
189
|
-
signing_key:
|
186
|
+
rubygems_version: 3.0.3
|
187
|
+
signing_key:
|
190
188
|
specification_version: 4
|
191
189
|
summary: Attach comments to your ActiveRecord queries.
|
192
190
|
test_files: []
|