sqreen 1.20.1 → 1.20.2
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/sqreen/attack_detected.html +1 -2
- data/lib/sqreen/deferred_logger.rb +4 -0
- data/lib/sqreen/graft/call.rb +32 -19
- data/lib/sqreen/graft/callback.rb +1 -1
- data/lib/sqreen/graft/hook.rb +97 -116
- data/lib/sqreen/graft/hook_point.rb +1 -1
- data/lib/sqreen/legacy/instrumentation.rb +10 -10
- data/lib/sqreen/log/loggable.rb +1 -0
- data/lib/sqreen/logger.rb +4 -0
- data/lib/sqreen/version.rb +1 -1
- data/lib/sqreen/weave/legacy/instrumentation.rb +52 -49
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20f83c83a19022c3bfba53af705716e2d4b4d791912bf32c6e7e2853496a4b05
|
|
4
|
+
data.tar.gz: 6592f5a6c88895016924c4a342d6c1f48f885527c18fc0b182495d2905cef926
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 349fecb7524cb1740965162e596708fede99c5ab12bd5ed0a009c324e360585a15f2237c78614b666e77d5bbbf5b044a9a1ee7be8d3ce791b377cbc1ecbe15aa
|
|
7
|
+
data.tar.gz: ad4b8725a6531e80a4e47aac8c820f88284391a8f674ae59e8908846714c8b1c76be7fd95034cdf4885588f39e413308f39cc5688f6ed207558b48d0b14def5f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<!-- Sorry, you’ve been blocked --><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>You've been blocked</title><style>a,body,div,h1,html,span{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}body{background:-webkit-radial-gradient(26% 19%,circle,#fff,#f4f7f9);background:radial-gradient(circle at 26% 19%,#fff,#f4f7f9);display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-ms-flex-line-pack:center;align-content:center;width:100%;min-height:100vh;line-height:1;flex-direction:column}h1,p,svg{display:block}svg{margin:0 auto 4vh}main{text-align:center;flex:1;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-ms-flex-line-pack:center;align-content:center;flex-direction:column}h1{font-family:sans-serif;font-weight:600;font-size:34px;color:#1e0936;line-height:1.2}p{font-size:18px;line-height:normal;color:#646464;font-family:sans-serif;font-weight:400}a{color:#4842b7}footer{width:100%;text-align:center}footer p{font-size:16px}</style></head><body><main><svg width="170px" height="193px" viewBox="0 0 170 193" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true"><g id="exports" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="Artboard" transform="translate(-186.000000, -189.000000)"><g id="logo-cmyk-indigo" transform="translate(186.000000, 189.000000)"><g id="nest-cmyk-indigo"><ellipse id="sqreen" fill="#B0ACFF" cx="85" cy="96.5" rx="45.7692308" ry="45.7966102"></ellipse><path d="M78.4615385,175.749389 L78.4615385,102.2092 L13.1398162,64.4731256 L13.1398162,129.181112 L36.352167,115.771438 C37.9764468,119.873152 40.1038639,123.720553 42.6582364,127.237412 L18.5723996,141.151695 L78.4615385,175.749389 Z M91.5384615,175.749389 L151.4276,141.151695 L127.341764,127.237412 C129.896136,123.720553 132.023553,119.873152 133.647833,115.771438 L156.860184,129.181112 L156.860184,64.4731256 L91.5384615,102.2092 L91.5384615,175.749389 Z M18.0061522,52.1754237 L85,90.8774777 L151.993848,52.1754237 L91.5384615,17.2506105 L91.5384615,44.565949 C89.3964992,44.2986903 87.2143177,44.1610169 85,44.1610169 C82.7856823,44.1610169 80.6035008,44.2986903 78.4615385,44.565949 L78.4615385,17.2506105 L18.0061522,52.1754237 Z M90.8846156,1.76392358 L164.052491,44.0326866 C167.693904,46.1363149 169.937107,50.0239804 169.937107,54.231237 L169.937107,138.768763 C169.937107,142.97602 167.693904,146.863685 164.052491,148.967313 L90.8846156,191.236076 C87.2432028,193.339705 82.7567972,193.339705 79.1153844,191.236076 L5.94750871,148.967313 C2.30609589,146.863685 0.0628930904,142.97602 0.0628930904,138.768763 L0.0628930904,54.231237 C0.0628930904,50.0239804 2.30609589,46.1363149 5.94750871,44.0326866 L79.1153844,1.76392358 C82.7567972,-0.339704735 87.2432028,-0.339704735 90.8846156,1.76392358 Z" id="app" fill="#4842B7"></path></g></g></g></g></svg><h1>Sorry, you've been blocked</h1><p>Contact the website owner</p></main><footer><p>Security provided by <a href="https://www.sqreen.com/?utm_medium=block_page" target="_blank">Sqreen</a></p></footer></body></html>
|
data/lib/sqreen/graft/call.rb
CHANGED
|
@@ -98,53 +98,66 @@ module Sqreen
|
|
|
98
98
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
99
99
|
end
|
|
100
100
|
|
|
101
|
-
attr_reader :tag
|
|
101
|
+
attr_reader :tag, :size, :duration
|
|
102
102
|
|
|
103
103
|
def initialize(tag, &block)
|
|
104
104
|
@tag = tag
|
|
105
|
-
@blips = []
|
|
106
105
|
@block = block
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def duration
|
|
110
|
-
@blips.each_with_index.reduce(0) { |a, (e, i)| i.even? ? a - e : a + e }
|
|
106
|
+
@duration = 0
|
|
107
|
+
@size = 0
|
|
111
108
|
end
|
|
112
109
|
|
|
113
110
|
def elapsed
|
|
114
|
-
@
|
|
111
|
+
@duration + Timer.read
|
|
115
112
|
end
|
|
116
113
|
|
|
117
114
|
def ignore
|
|
118
|
-
@
|
|
115
|
+
@size += 1
|
|
116
|
+
@duration += Timer.read
|
|
119
117
|
yield(self)
|
|
120
118
|
ensure
|
|
121
|
-
@
|
|
119
|
+
@size += 1
|
|
120
|
+
@duration -= Timer.read
|
|
122
121
|
end
|
|
123
122
|
|
|
124
|
-
def measure
|
|
125
|
-
|
|
123
|
+
def measure(opts = nil)
|
|
124
|
+
now = Timer.read
|
|
125
|
+
ignore = opts[:ignore] if opts
|
|
126
|
+
if ignore
|
|
127
|
+
ignore.size += 1
|
|
128
|
+
ignore.duration += now
|
|
129
|
+
end
|
|
130
|
+
@size += 1
|
|
131
|
+
@duration -= now
|
|
126
132
|
yield(self)
|
|
127
133
|
ensure
|
|
128
|
-
|
|
134
|
+
now = Timer.read
|
|
135
|
+
if ignore
|
|
136
|
+
ignore.size += 1
|
|
137
|
+
ignore.duration -= now
|
|
138
|
+
end
|
|
139
|
+
@size += 1
|
|
140
|
+
@duration += now
|
|
129
141
|
@block.call(self) if @block
|
|
130
|
-
Sqreen::Graft.logger.debug { "#{@tag}: time=%.03fus" % (duration * 1_000_000) }
|
|
131
142
|
end
|
|
132
143
|
|
|
133
144
|
def start
|
|
134
|
-
@
|
|
145
|
+
@size += 1
|
|
146
|
+
@duration -= Timer.read
|
|
135
147
|
end
|
|
136
148
|
|
|
137
149
|
def stop
|
|
138
|
-
@
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
def size
|
|
142
|
-
@blips.size
|
|
150
|
+
@size += 1
|
|
151
|
+
@duration += Timer.read
|
|
143
152
|
end
|
|
144
153
|
|
|
145
154
|
def to_s
|
|
146
155
|
"#{@tag}: time=%.03fus" % (duration * 1_000_000)
|
|
147
156
|
end
|
|
157
|
+
|
|
158
|
+
protected
|
|
159
|
+
|
|
160
|
+
attr_writer :size, :duration
|
|
148
161
|
end
|
|
149
162
|
end
|
|
150
163
|
end
|
|
@@ -21,7 +21,7 @@ module Sqreen
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def call(*args, &block)
|
|
24
|
-
Sqreen::Graft.logger.debug { "[#{Process.pid}] Callback #{@name} disabled:#{disabled?}" }
|
|
24
|
+
# Sqreen::Graft.logger.debug { "[#{Process.pid}] Callback #{@name} disabled:#{disabled?}" } if Sqreen::Graft.logger.debug?
|
|
25
25
|
return if @disabled
|
|
26
26
|
@block.call(*args, &block)
|
|
27
27
|
end
|
data/lib/sqreen/graft/hook.rb
CHANGED
|
@@ -46,27 +46,31 @@ module Sqreen
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def before(tag = nil, opts = {}, &block)
|
|
49
|
-
return @before
|
|
49
|
+
return @before if block.nil?
|
|
50
50
|
|
|
51
51
|
@before << Callback.new(callback_name(:before, tag), opts, &block)
|
|
52
|
+
@before.sort_by!(&:rank)
|
|
52
53
|
end
|
|
53
54
|
|
|
54
55
|
def after(tag = nil, opts = {}, &block)
|
|
55
|
-
return @after
|
|
56
|
+
return @after if block.nil?
|
|
56
57
|
|
|
57
58
|
@after << Callback.new(callback_name(:after, tag), opts, &block)
|
|
59
|
+
@after.sort_by!(&:rank)
|
|
58
60
|
end
|
|
59
61
|
|
|
60
62
|
def raised(tag = nil, opts = {}, &block)
|
|
61
|
-
return @raised
|
|
63
|
+
return @raised if block.nil?
|
|
62
64
|
|
|
63
65
|
@raised << Callback.new(callback_name(:raised, tag), opts, &block)
|
|
66
|
+
@raised.sort_by!(&:rank)
|
|
64
67
|
end
|
|
65
68
|
|
|
66
69
|
def ensured(tag = nil, opts = {}, &block)
|
|
67
|
-
return @ensured
|
|
70
|
+
return @ensured if block.nil?
|
|
68
71
|
|
|
69
72
|
@ensured << Callback.new(callback_name(:ensured, tag), opts, &block)
|
|
73
|
+
@ensured.sort_by!(&:rank)
|
|
70
74
|
end
|
|
71
75
|
|
|
72
76
|
def depends_on(&block)
|
|
@@ -112,6 +116,13 @@ module Sqreen
|
|
|
112
116
|
end
|
|
113
117
|
|
|
114
118
|
def self.wrapper(hook)
|
|
119
|
+
timed_hooks_proc = proc do |t|
|
|
120
|
+
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:timed_hooks] << t
|
|
121
|
+
end
|
|
122
|
+
timed_callbacks_proc = proc do |t|
|
|
123
|
+
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:timed_callbacks] << t
|
|
124
|
+
end
|
|
125
|
+
|
|
115
126
|
Proc.new do |*args, &block|
|
|
116
127
|
if Thread.current[:sqreen_hook_entered] || Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:time_budget_expended]
|
|
117
128
|
if hook.point.super?
|
|
@@ -121,10 +132,12 @@ module Sqreen
|
|
|
121
132
|
end
|
|
122
133
|
end
|
|
123
134
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
hook_point_super = hook.point.super?
|
|
136
|
+
logger = Sqreen::Graft.logger
|
|
137
|
+
logger_debug = Sqreen::Graft.logger.debug?
|
|
138
|
+
|
|
139
|
+
Timer.new(hook.point, &timed_hooks_proc).measure do |chrono|
|
|
140
|
+
logger.debug { "[#{Process.pid}] Hook #{hook.point} disabled:#{hook.disabled?} caller:#{Kernel.caller[2].inspect}" } if logger_debug
|
|
128
141
|
|
|
129
142
|
budget = Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:time_budget]
|
|
130
143
|
timer = Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:timer] if budget
|
|
@@ -143,37 +156,29 @@ module Sqreen
|
|
|
143
156
|
# TODO: TimedHookCall TimedCallbackCall
|
|
144
157
|
# TODO: TimeBoundHookCall TimeBoundCallbackCall TimeBoundFlow?
|
|
145
158
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
unless remaining > 0
|
|
155
|
-
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
156
|
-
next
|
|
157
|
-
end
|
|
159
|
+
hook.before.each do |c|
|
|
160
|
+
next if c.ignore && c.ignore.call
|
|
161
|
+
|
|
162
|
+
if timer && !c.mandatory
|
|
163
|
+
remaining = budget - timer.elapsed
|
|
164
|
+
unless remaining > 0
|
|
165
|
+
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
166
|
+
next
|
|
158
167
|
end
|
|
168
|
+
end
|
|
159
169
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
end.measure do
|
|
164
|
-
before_chrono.ignore do
|
|
165
|
-
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passed), ball)
|
|
166
|
-
end
|
|
167
|
-
end
|
|
170
|
+
flow = catch(Ball.new) do |ball|
|
|
171
|
+
Timer.new(c.name, &timed_callbacks_proc).measure(ignore: chrono) do
|
|
172
|
+
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passed), ball)
|
|
168
173
|
end
|
|
174
|
+
end
|
|
169
175
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
end
|
|
176
|
+
next unless c.flow && flow.is_a?(Flow)
|
|
177
|
+
hooked_call.raise = flow.raise and hooked_call.raising = true if flow.raise?
|
|
178
|
+
hooked_call.args_pass = flow.args and hooked_call.args_passing = true if flow.args?
|
|
179
|
+
hooked_call.return = flow.return and hooked_call.returning = true if flow.return?
|
|
180
|
+
break if flow.break?
|
|
181
|
+
end unless hook.disabled?
|
|
177
182
|
|
|
178
183
|
raise hooked_call.raise if hooked_call.raising
|
|
179
184
|
return hooked_call.return if hooked_call.returning
|
|
@@ -184,7 +189,7 @@ module Sqreen
|
|
|
184
189
|
|
|
185
190
|
begin
|
|
186
191
|
chrono.ignore do
|
|
187
|
-
if
|
|
192
|
+
if hook_point_super
|
|
188
193
|
hooked_call.returned = super(*(hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed), &block)
|
|
189
194
|
else
|
|
190
195
|
hooked_call.returned = hook.point.apply(hooked_call.instance, 'sqreen_hook', *(hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed), &block)
|
|
@@ -195,40 +200,32 @@ module Sqreen
|
|
|
195
200
|
Thread.current[:sqreen_hook_entered] = true
|
|
196
201
|
hooked_call.raised = e
|
|
197
202
|
|
|
198
|
-
|
|
203
|
+
logger.debug { "[#{Process.pid}] Hook #{hook.point} disabled:#{hook.disabled?} exception:#{e}" } if logger_debug
|
|
199
204
|
raise if hook.raised.empty?
|
|
200
205
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
unless remaining > 0
|
|
210
|
-
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
211
|
-
next
|
|
212
|
-
end
|
|
206
|
+
hook.raised.each do |c|
|
|
207
|
+
next if c.ignore && c.ignore.call
|
|
208
|
+
|
|
209
|
+
if timer && !c.mandatory
|
|
210
|
+
remaining = budget - timer.elapsed
|
|
211
|
+
unless remaining > 0
|
|
212
|
+
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
213
|
+
next
|
|
213
214
|
end
|
|
215
|
+
end
|
|
214
216
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
end.measure do
|
|
219
|
-
raised_chrono.ignore do
|
|
220
|
-
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed, hooked_call.raised), ball)
|
|
221
|
-
end
|
|
222
|
-
end
|
|
217
|
+
flow = catch(Ball.new) do |ball|
|
|
218
|
+
Timer.new(c.name, &timed_callbacks_proc).measure(ignore: chrono) do
|
|
219
|
+
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed, hooked_call.raised), ball)
|
|
223
220
|
end
|
|
221
|
+
end
|
|
224
222
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
end
|
|
223
|
+
next unless c.flow && flow.is_a?(Flow)
|
|
224
|
+
hooked_call.raise = flow.raise and hooked_call.raising = true if flow.raise?
|
|
225
|
+
hooked_call.return = flow.return and hooked_call.returning = true if flow.return?
|
|
226
|
+
hooked_call.retrying = true if flow.retry?
|
|
227
|
+
break if flow.break?
|
|
228
|
+
end unless hook.disabled?
|
|
232
229
|
|
|
233
230
|
retry if hooked_call.retrying
|
|
234
231
|
raise hooked_call.raise if hooked_call.raising
|
|
@@ -238,72 +235,56 @@ module Sqreen
|
|
|
238
235
|
timer.start if timer
|
|
239
236
|
Thread.current[:sqreen_hook_entered] = true
|
|
240
237
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
unless remaining > 0
|
|
250
|
-
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
251
|
-
next
|
|
252
|
-
end
|
|
238
|
+
hook.after.each do |c|
|
|
239
|
+
next if c.ignore && c.ignore.call
|
|
240
|
+
|
|
241
|
+
if timer && !c.mandatory
|
|
242
|
+
remaining = budget - timer.elapsed
|
|
243
|
+
unless remaining > 0
|
|
244
|
+
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
245
|
+
next
|
|
253
246
|
end
|
|
247
|
+
end
|
|
254
248
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
end.measure do
|
|
259
|
-
after_chrono.ignore do
|
|
260
|
-
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed, nil, hooked_call.returned), ball)
|
|
261
|
-
end
|
|
262
|
-
end
|
|
249
|
+
flow = catch(Ball.new) do |ball|
|
|
250
|
+
Timer.new(c.name, &timed_callbacks_proc).measure(ignore: chrono) do
|
|
251
|
+
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed, nil, hooked_call.returned), ball)
|
|
263
252
|
end
|
|
253
|
+
end
|
|
264
254
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
end
|
|
255
|
+
next unless c.flow && flow.is_a?(Flow)
|
|
256
|
+
hooked_call.raise = flow.raise and hooked_call.raising = true if flow.raise?
|
|
257
|
+
hooked_call.return = flow.return and hooked_call.returning = true if flow.return?
|
|
258
|
+
break if flow.break?
|
|
259
|
+
end unless hook.disabled?
|
|
271
260
|
|
|
272
261
|
raise hooked_call.raise if hooked_call.raising
|
|
273
262
|
return hooked_call.returning ? hooked_call.return : hooked_call.returned
|
|
274
263
|
ensure
|
|
275
264
|
# TODO: timer.start if someone has thrown?
|
|
276
265
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
unless remaining > 0
|
|
286
|
-
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
287
|
-
next
|
|
288
|
-
end
|
|
266
|
+
hook.ensured.each do |c|
|
|
267
|
+
next if c.ignore && c.ignore.call
|
|
268
|
+
|
|
269
|
+
if timer && !c.mandatory
|
|
270
|
+
remaining = budget - timer.elapsed
|
|
271
|
+
unless remaining > 0
|
|
272
|
+
Thread.current[:sqreen_http_request] && Thread.current[:sqreen_http_request][:skipped_callbacks] << c && Thread.current[:sqreen_http_request][:time_budget_expended] = true
|
|
273
|
+
next
|
|
289
274
|
end
|
|
275
|
+
end
|
|
290
276
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
end.measure do
|
|
295
|
-
ensured_chrono.ignore do
|
|
296
|
-
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed, nil, hooked_call.returned), ball)
|
|
297
|
-
end
|
|
298
|
-
end
|
|
277
|
+
flow = catch(Ball.new) do |ball|
|
|
278
|
+
Timer.new(c.name, &timed_callbacks_proc).measure(ignore: chrono) do
|
|
279
|
+
c.call(CallbackCall.new(c, remaining, hooked_call.instance, hooked_call.args_passing ? hooked_call.args_pass : hooked_call.args_passed, nil, hooked_call.returned), ball)
|
|
299
280
|
end
|
|
281
|
+
end
|
|
300
282
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
end
|
|
283
|
+
next unless c.flow && flow.is_a?(Flow)
|
|
284
|
+
hooked_call.raise = flow.raise and hooked_call.raising = true if flow.raise?
|
|
285
|
+
hooked_call.return = flow.return and hooked_call.returning = true if flow.return?
|
|
286
|
+
break if flow.break?
|
|
287
|
+
end unless hook.disabled?
|
|
307
288
|
|
|
308
289
|
Thread.current[:sqreen_hook_entered] = false
|
|
309
290
|
timer.stop if timer
|
|
@@ -109,7 +109,7 @@ module Legacy
|
|
|
109
109
|
break if res.is_a?(Hash) && res[:skip_rem_cbs]
|
|
110
110
|
rescue StandardError => e
|
|
111
111
|
Sqreen.log.warn { "we catch an exception: #{e.inspect}" }
|
|
112
|
-
Sqreen.log.debug e.backtrace
|
|
112
|
+
Sqreen.log.debug { e.backtrace }
|
|
113
113
|
if cb.respond_to?(:record_exception)
|
|
114
114
|
cb.record_exception(e)
|
|
115
115
|
else
|
|
@@ -162,7 +162,7 @@ module Legacy
|
|
|
162
162
|
returns << res
|
|
163
163
|
rescue StandardError => e
|
|
164
164
|
Sqreen.log.warn { "we catch an exception: #{e.inspect}" }
|
|
165
|
-
Sqreen.log.debug e.backtrace
|
|
165
|
+
Sqreen.log.debug { e.backtrace }
|
|
166
166
|
if cb.respond_to?(:record_exception)
|
|
167
167
|
cb.record_exception(e)
|
|
168
168
|
else
|
|
@@ -603,10 +603,10 @@ module Legacy
|
|
|
603
603
|
|
|
604
604
|
if !already_overriden
|
|
605
605
|
if is_class_method?(klass, method)
|
|
606
|
-
Sqreen.log.debug "overriding class method for #{cb}"
|
|
606
|
+
Sqreen.log.debug { "overriding class method for #{cb}" }
|
|
607
607
|
success = override_class_method(klass, method)
|
|
608
608
|
elsif is_instance_method?(klass, method)
|
|
609
|
-
Sqreen.log.debug "overriding instance method for #{cb}"
|
|
609
|
+
Sqreen.log.debug { "overriding instance method for #{cb}" }
|
|
610
610
|
success = override_instance_method(klass, method)
|
|
611
611
|
else
|
|
612
612
|
# FIXME: Override define_method and other dynamic ways to
|
|
@@ -623,7 +623,7 @@ module Legacy
|
|
|
623
623
|
|
|
624
624
|
@@overriden_methods += [key] if success
|
|
625
625
|
else
|
|
626
|
-
Sqreen.log.debug "#{key} was already overriden"
|
|
626
|
+
Sqreen.log.debug { "#{key} was already overriden" }
|
|
627
627
|
end
|
|
628
628
|
|
|
629
629
|
if klass != Object && klass != Kernel && !Sqreen.features['instrument_all_instances'] && !defined?(::JRUBY_VERSION)
|
|
@@ -638,7 +638,7 @@ module Legacy
|
|
|
638
638
|
end
|
|
639
639
|
end
|
|
640
640
|
|
|
641
|
-
Sqreen.log.debug "Adding callback #{cb} for #{klass} #{method}"
|
|
641
|
+
Sqreen.log.debug { "Adding callback #{cb} for #{klass} #{method}" }
|
|
642
642
|
@@registered_callbacks.add(cb)
|
|
643
643
|
@@unovertimable_hookpoints << key unless cb.overtimeable
|
|
644
644
|
@@instrumented_pid = Process.pid
|
|
@@ -659,7 +659,7 @@ module Legacy
|
|
|
659
659
|
|
|
660
660
|
already_overriden = @@overriden_methods.include? key
|
|
661
661
|
unless already_overriden
|
|
662
|
-
Sqreen.log.debug "#{key} apparently not overridden"
|
|
662
|
+
Sqreen.log.debug { "#{key} apparently not overridden" }
|
|
663
663
|
end
|
|
664
664
|
|
|
665
665
|
defined_cbs = @@registered_callbacks.get(klass, method).flatten
|
|
@@ -667,17 +667,17 @@ module Legacy
|
|
|
667
667
|
nb_removed = 0
|
|
668
668
|
defined_cbs.each do |found_cb|
|
|
669
669
|
if found_cb == cb
|
|
670
|
-
Sqreen.log.debug "Removing callback #{found_cb}"
|
|
670
|
+
Sqreen.log.debug { "Removing callback #{found_cb}" }
|
|
671
671
|
@@registered_callbacks.remove(found_cb)
|
|
672
672
|
nb_removed += 1
|
|
673
673
|
else
|
|
674
|
-
Sqreen.log.debug "Not removing callback #{found_cb} (remains #{defined_cbs.size} cbs)"
|
|
674
|
+
Sqreen.log.debug { "Not removing callback #{found_cb} (remains #{defined_cbs.size} cbs)" }
|
|
675
675
|
end
|
|
676
676
|
end
|
|
677
677
|
|
|
678
678
|
return unless nb_removed == defined_cbs.size
|
|
679
679
|
|
|
680
|
-
Sqreen.log.debug "Removing overriden method #{key}"
|
|
680
|
+
Sqreen.log.debug { "Removing overriden method #{key}" }
|
|
681
681
|
@@overriden_methods.delete(key)
|
|
682
682
|
|
|
683
683
|
if is_class_method?(klass, method)
|
data/lib/sqreen/log/loggable.rb
CHANGED
data/lib/sqreen/logger.rb
CHANGED
data/lib/sqreen/version.rb
CHANGED
|
@@ -60,6 +60,27 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
60
60
|
'options' => opts[:perf_metric_percent] || { 'base' => 1.3, 'factor' => 1.0 },
|
|
61
61
|
)
|
|
62
62
|
|
|
63
|
+
metrics_engine.create_metric(
|
|
64
|
+
'name' => 'req_sq_hook_overhead',
|
|
65
|
+
'period' => 60,
|
|
66
|
+
'kind' => 'Binning',
|
|
67
|
+
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
metrics_engine.create_metric(
|
|
71
|
+
'name' => 'sq.hook.overhead',
|
|
72
|
+
'period' => 60,
|
|
73
|
+
'kind' => 'Binning',
|
|
74
|
+
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
metrics_engine.create_metric(
|
|
78
|
+
'name' => 'sq.shrinkwrap',
|
|
79
|
+
'period' => 60,
|
|
80
|
+
'kind' => 'Binning',
|
|
81
|
+
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
|
82
|
+
)
|
|
83
|
+
|
|
63
84
|
Sqreen.thread_cpu_time? && metrics_engine.create_metric(
|
|
64
85
|
'name' => 'sq_thread_cpu_pct',
|
|
65
86
|
'period' => opts[:period] || 60,
|
|
@@ -113,6 +134,9 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
113
134
|
before('wave,meta,request', rank: -100000, mandatory: true) do |_call|
|
|
114
135
|
next unless Sqreen.instrumentation_ready
|
|
115
136
|
|
|
137
|
+
# shrinkwrap_timer = Sqreen::Graft::Timer.new('weave,shrinkwrap')
|
|
138
|
+
# shrinkwrap_timer.start
|
|
139
|
+
|
|
116
140
|
uuid = SecureRandom.uuid
|
|
117
141
|
now = Sqreen::Graft::Timer.read
|
|
118
142
|
Thread.current[:sqreen_http_request] = {
|
|
@@ -123,14 +147,13 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
123
147
|
timer: Sqreen::Graft::Timer.new("request_#{uuid}"),
|
|
124
148
|
timed_callbacks: [],
|
|
125
149
|
timed_hooks: [],
|
|
126
|
-
timed_hooks_before: [],
|
|
127
|
-
timed_hooks_after: [],
|
|
128
|
-
timed_hooks_raised: [],
|
|
129
|
-
timed_hooks_ensured: [],
|
|
130
150
|
skipped_callbacks: [],
|
|
151
|
+
# timed_shrinkwrap: shrinkwrap_timer,
|
|
131
152
|
}
|
|
132
153
|
|
|
133
154
|
Sqreen::Weave.logger.debug { "request.uuid: #{uuid}" }
|
|
155
|
+
|
|
156
|
+
# shrinkwrap_timer.stop
|
|
134
157
|
end
|
|
135
158
|
|
|
136
159
|
ensured('weave,meta,request', rank: 100000, mandatory: true) do |_call|
|
|
@@ -138,6 +161,9 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
138
161
|
|
|
139
162
|
next if request.nil?
|
|
140
163
|
|
|
164
|
+
# shrinkwrap_timer = request[:timed_shrinkwrap]
|
|
165
|
+
# shrinkwrap_timer.start
|
|
166
|
+
|
|
141
167
|
Thread.current[:sqreen_http_request] = nil
|
|
142
168
|
now = Sqreen::Graft::Timer.read
|
|
143
169
|
utc_now = Time.now.utc
|
|
@@ -167,59 +193,28 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
167
193
|
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
|
168
194
|
end
|
|
169
195
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
metrics_engine.create_metric(
|
|
174
|
-
'name' => metric_name,
|
|
175
|
-
'period' => 60,
|
|
176
|
-
'kind' => 'Binning',
|
|
177
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
|
178
|
-
)
|
|
179
|
-
end
|
|
180
|
-
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
|
181
|
-
|
|
182
|
-
metric_name = 'sq.hooks_post.post'
|
|
183
|
-
duration = request[:timed_hooks_after].sum(&:duration)
|
|
184
|
-
unless metrics_engine.metric?(metric_name)
|
|
185
|
-
metrics_engine.create_metric(
|
|
186
|
-
'name' => metric_name,
|
|
187
|
-
'period' => 60,
|
|
188
|
-
'kind' => 'Binning',
|
|
189
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
|
190
|
-
)
|
|
191
|
-
end
|
|
192
|
-
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
|
193
|
-
|
|
194
|
-
metric_name = 'sq.hooks_failing.failing'
|
|
195
|
-
duration = request[:timed_hooks_raised].sum(&:duration)
|
|
196
|
-
unless metrics_engine.metric?(metric_name)
|
|
197
|
-
metrics_engine.create_metric(
|
|
198
|
-
'name' => metric_name,
|
|
199
|
-
'period' => 60,
|
|
200
|
-
'kind' => 'Binning',
|
|
201
|
-
'options' => { 'base' => 2.0, 'factor' => 0.1 },
|
|
202
|
-
)
|
|
196
|
+
request[:timed_hooks].each do |timer|
|
|
197
|
+
duration = timer.duration
|
|
198
|
+
metrics_engine.update('sq.hook.overhead', now, nil, duration * 1000)
|
|
203
199
|
end
|
|
204
|
-
metrics_engine.update(metric_name, now, nil, duration * 1000)
|
|
205
200
|
|
|
206
201
|
skipped = request[:skipped_callbacks].map(&:name)
|
|
207
|
-
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} callback.skipped.size: #{skipped.count} callback.skipped: [#{skipped.join(', ')}]" }
|
|
202
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} callback.skipped.size: #{skipped.count} callback.skipped: [#{skipped.join(', ')}]" } if Sqreen::Weave.logger.debug?
|
|
208
203
|
timer = request[:timer]
|
|
209
204
|
total = timer.duration
|
|
210
|
-
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} timer.total: #{'%.03fus' % (total * 1_000_000)}
|
|
205
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} timer.total: #{'%.03fus' % (total * 1_000_000)}" } if Sqreen::Weave.logger.debug?
|
|
211
206
|
timings = request[:timed_callbacks].map(&:to_s)
|
|
212
207
|
total = request[:timed_callbacks].sum(&:duration)
|
|
213
|
-
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} callback.total: #{'%.03fus' % (total * 1_000_000)} callback.timings: [#{timings.join(', ')}]" }
|
|
208
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} callback.total: #{'%.03fus' % (total * 1_000_000)} callback.timings: [#{timings.join(', ')}]" } if Sqreen::Weave.logger.debug?
|
|
214
209
|
timings = request[:timed_hooks].map(&:to_s)
|
|
215
210
|
total = request[:timed_hooks].sum(&:duration)
|
|
216
|
-
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} hook.total: #{'%.03fus' % (total * 1_000_000)} hook.timings: [#{timings.join(', ')}]" }
|
|
211
|
+
Sqreen::Weave.logger.debug { "request:#{request[:uuid]} hook.total: #{'%.03fus' % (total * 1_000_000)} hook.timings: [#{timings.join(', ')}]" } if Sqreen::Weave.logger.debug?
|
|
217
212
|
|
|
218
213
|
skipped = request[:skipped_callbacks].map(&:name)
|
|
219
214
|
skipped_rule_name = skipped.first && skipped.first =~ /weave,rule=(.*)$/ && $1
|
|
220
215
|
Sqreen.observations_queue.push(['request_overtime', skipped_rule_name, 1, utc_now]) if skipped_rule_name
|
|
221
216
|
|
|
222
|
-
sqreen_request_duration =
|
|
217
|
+
sqreen_request_duration = request[:timed_hooks].sum(&:duration) + request[:timed_callbacks].sum(&:duration)
|
|
223
218
|
Sqreen.observations_queue.push(['sq', nil, sqreen_request_duration * 1000, utc_now])
|
|
224
219
|
|
|
225
220
|
request_duration = now - request[:start_time]
|
|
@@ -227,6 +222,14 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
227
222
|
|
|
228
223
|
sqreen_request_ratio = (sqreen_request_duration * 100.0) / (request_duration - sqreen_request_duration)
|
|
229
224
|
Sqreen.observations_queue.push(['pct', nil, sqreen_request_ratio, utc_now])
|
|
225
|
+
|
|
226
|
+
duration = request[:timed_hooks].sum(&:duration)
|
|
227
|
+
metrics_engine.update('req_sq_hook_overhead', now, nil, duration * 1000)
|
|
228
|
+
|
|
229
|
+
# shrinkwrap_timer.stop
|
|
230
|
+
|
|
231
|
+
# duration = shrinkwrap_timer.duration
|
|
232
|
+
# metrics_engine.update('sq.shrinkwrap', now, nil, duration * 1000)
|
|
230
233
|
end
|
|
231
234
|
end.install
|
|
232
235
|
|
|
@@ -275,7 +278,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
275
278
|
a = call.args
|
|
276
279
|
r = call.remaining
|
|
277
280
|
|
|
278
|
-
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#pre instance=#{i}" }
|
|
281
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#pre instance=#{i}" } if Sqreen::Weave.logger.debug?
|
|
279
282
|
begin
|
|
280
283
|
ret = callback.pre(i, a, r)
|
|
281
284
|
rescue StandardError => e
|
|
@@ -286,7 +289,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
286
289
|
Sqreen::RemoteException.record(e)
|
|
287
290
|
end
|
|
288
291
|
end
|
|
289
|
-
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#pre instance=#{i} => return=#{ret.inspect}" }
|
|
292
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#pre instance=#{i} => return=#{ret.inspect}" } if Sqreen::Weave.logger.debug?
|
|
290
293
|
|
|
291
294
|
case ret[:status]
|
|
292
295
|
when :skip, 'skip'
|
|
@@ -309,7 +312,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
309
312
|
a = call.args
|
|
310
313
|
r = call.remaining
|
|
311
314
|
|
|
312
|
-
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#post instance=#{i}" }
|
|
315
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#post instance=#{i}" } if Sqreen::Weave.logger.debug?
|
|
313
316
|
begin
|
|
314
317
|
ret = callback.post(v, i, a, r)
|
|
315
318
|
rescue StandardError => e
|
|
@@ -320,7 +323,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
320
323
|
Sqreen::RemoteException.record(e)
|
|
321
324
|
end
|
|
322
325
|
end
|
|
323
|
-
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#post instance=#{i} => return=#{ret.inspect}" }
|
|
326
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#post instance=#{i} => return=#{ret.inspect}" } if Sqreen::Weave.logger.debug?
|
|
324
327
|
|
|
325
328
|
case ret[:status]
|
|
326
329
|
when :override, 'override'
|
|
@@ -341,7 +344,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
341
344
|
a = call.args
|
|
342
345
|
r = call.remaining
|
|
343
346
|
|
|
344
|
-
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#failing instance=#{i}" }
|
|
347
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#failing instance=#{i}" } if Sqreen::Weave.logger.debug?
|
|
345
348
|
begin
|
|
346
349
|
ret = callback.failing(e, i, a, r)
|
|
347
350
|
rescue StandardError => e
|
|
@@ -352,7 +355,7 @@ class Sqreen::Weave::Legacy::Instrumentation
|
|
|
352
355
|
Sqreen::RemoteException.record(e)
|
|
353
356
|
end
|
|
354
357
|
end
|
|
355
|
-
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#failing instance=#{i} => return=#{ret.inspect}" }
|
|
358
|
+
Sqreen::Weave.logger.debug { "#{rule} klass=#{callback.klass} method=#{callback.method} when=#failing instance=#{i} => return=#{ret.inspect}" } if Sqreen::Weave.logger.debug?
|
|
356
359
|
|
|
357
360
|
throw(b, b.raise(e)) if ret.nil? || !ret.is_a?(Hash)
|
|
358
361
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sqreen
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.20.
|
|
4
|
+
version: 1.20.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sqreen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sqreen-backport
|
|
@@ -292,8 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
292
292
|
- !ruby/object:Gem::Version
|
|
293
293
|
version: '0'
|
|
294
294
|
requirements: []
|
|
295
|
-
|
|
296
|
-
rubygems_version: 2.7.7
|
|
295
|
+
rubygems_version: 3.1.2
|
|
297
296
|
signing_key:
|
|
298
297
|
specification_version: 4
|
|
299
298
|
summary: Sqreen Ruby agent
|