rorvswild 0.2.0 → 0.2.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 +4 -4
- data/lib/rorvswild/version.rb +1 -1
- data/lib/rorvswild.rb +42 -29
- data/test/ror_vs_wild_test.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c255c25e5829f312cb6e04c42eb8bb0c4d0b247b
|
4
|
+
data.tar.gz: 0581376548672b9c4e168bdf5b2bf0c02a1b044d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f702cf9cb1ab6f629130bb5fcc543821181d8e8a4b7b45bf56a7c8277a19f4e6401cb7e3c29911e1f81dc9a9dc0fd6157e2db5f9a786a003887e75517722e7eb
|
7
|
+
data.tar.gz: 0851c9573066fe3ca8b9581d10cc09c61c6f3e4da1c44fbc1c358bbae1fba47b4fdf66c9c796e2b501870ada44977af4209de3bf3a79a200cb2f6d21ccf85940
|
data/lib/rorvswild/version.rb
CHANGED
data/lib/rorvswild.rb
CHANGED
@@ -43,7 +43,7 @@ module RorVsWild
|
|
43
43
|
}
|
44
44
|
end
|
45
45
|
|
46
|
-
attr_reader :api_url, :api_key, :app_id, :
|
46
|
+
attr_reader :api_url, :api_key, :app_id, :explain_sql_threshold, :log_sql_threshold
|
47
47
|
|
48
48
|
def initialize(config)
|
49
49
|
config = self.class.default_config.merge(config)
|
@@ -52,6 +52,7 @@ module RorVsWild
|
|
52
52
|
@api_url = config[:api_url]
|
53
53
|
@api_key = config[:api_key]
|
54
54
|
@app_id = config[:app_id]
|
55
|
+
@data = {}
|
55
56
|
setup_callbacks
|
56
57
|
RorVsWild.register_default_client(self)
|
57
58
|
end
|
@@ -70,19 +71,15 @@ module RorVsWild
|
|
70
71
|
end
|
71
72
|
|
72
73
|
def before_http_request(name, start, finish, id, payload)
|
73
|
-
|
74
|
-
@queries = []
|
75
|
-
@views = {}
|
76
|
-
@error = nil
|
74
|
+
request.merge!(controller: payload[:controller], action: payload[:action], path: payload[:path])
|
77
75
|
end
|
78
76
|
|
79
77
|
def after_http_request(name, start, finish, id, payload)
|
80
78
|
request[:db_runtime] = (payload[:db_runtime] || 0).round
|
81
79
|
request[:view_runtime] = (payload[:view_runtime] || 0).round
|
82
80
|
request[:other_runtime] = compute_duration(start, finish) - request[:db_runtime] - request[:view_runtime]
|
83
|
-
error[:parameters] = filter_sensitive_data(payload[:params]) if error
|
84
|
-
|
85
|
-
Thread.new { post_request(attributes) }
|
81
|
+
request[:error][:parameters] = filter_sensitive_data(payload[:params]) if request[:error]
|
82
|
+
post_request
|
86
83
|
rescue => exception
|
87
84
|
log_error(exception)
|
88
85
|
end
|
@@ -114,7 +111,7 @@ module RorVsWild
|
|
114
111
|
def after_exception(exception, controller)
|
115
112
|
if !exception.is_a?(ActionController::RoutingError)
|
116
113
|
file, line = exception.backtrace.first.split(":")
|
117
|
-
|
114
|
+
request[:error] = exception_to_hash(exception).merge(
|
118
115
|
session: controller.session.to_hash,
|
119
116
|
environment_variables: filter_sensitive_data(filter_environment_variables(controller.request.env))
|
120
117
|
)
|
@@ -136,8 +133,7 @@ module RorVsWild
|
|
136
133
|
end
|
137
134
|
|
138
135
|
def measure_block(name, &block)
|
139
|
-
|
140
|
-
@job = {name: name}
|
136
|
+
job[:name] = name
|
141
137
|
started_at = Time.now
|
142
138
|
cpu_time_offset = cpu_time
|
143
139
|
block.call
|
@@ -175,15 +171,27 @@ module RorVsWild
|
|
175
171
|
private
|
176
172
|
|
177
173
|
def queries
|
178
|
-
|
174
|
+
data[:queries] ||= []
|
179
175
|
end
|
180
176
|
|
181
177
|
def views
|
182
|
-
|
178
|
+
data[:views] ||= {}
|
183
179
|
end
|
184
180
|
|
185
181
|
def job
|
186
|
-
|
182
|
+
data
|
183
|
+
end
|
184
|
+
|
185
|
+
def request
|
186
|
+
data
|
187
|
+
end
|
188
|
+
|
189
|
+
def data
|
190
|
+
@data[Thread.current.object_id] ||= {}
|
191
|
+
end
|
192
|
+
|
193
|
+
def cleanup_data
|
194
|
+
@data.delete(Thread.current.object_id)
|
187
195
|
end
|
188
196
|
|
189
197
|
def push_query(query)
|
@@ -213,20 +221,23 @@ module RorVsWild
|
|
213
221
|
ActiveRecord::Base.connection.explain(sql, binds) if (sql =~ SELECT_REGEX) == 0
|
214
222
|
end
|
215
223
|
|
216
|
-
def post_request
|
217
|
-
|
218
|
-
|
219
|
-
|
224
|
+
def post_request
|
225
|
+
attributes = request.merge(queries: slowest_queries, views: slowest_views)
|
226
|
+
Thread.new { post("/requests".freeze, request: attributes) }
|
227
|
+
ensure
|
228
|
+
cleanup_data
|
220
229
|
end
|
221
230
|
|
222
231
|
def post_job
|
223
|
-
post("/jobs", job: job.merge(queries: slowest_queries))
|
232
|
+
post("/jobs".freeze, job: job.merge(queries: slowest_queries))
|
224
233
|
rescue => exception
|
225
234
|
log_error(exception)
|
235
|
+
ensure
|
236
|
+
cleanup_data
|
226
237
|
end
|
227
238
|
|
228
239
|
def post_error(hash)
|
229
|
-
post("/errors", error: hash)
|
240
|
+
post("/errors".freeze, error: hash)
|
230
241
|
end
|
231
242
|
|
232
243
|
def extract_query_location(stack)
|
@@ -241,15 +252,15 @@ module RorVsWild
|
|
241
252
|
|
242
253
|
def split_file_location(location)
|
243
254
|
file, line, method = location.split(":")
|
244
|
-
method = cleanup_method_name(method)
|
255
|
+
method = cleanup_method_name(method) if method
|
245
256
|
[file, line, method]
|
246
257
|
end
|
247
258
|
|
248
259
|
def cleanup_method_name(method)
|
249
|
-
method.sub!("block in ", "")
|
250
|
-
method.sub!("in `", "")
|
251
|
-
method.sub!("'", "")
|
252
|
-
method.index("_app_views_") == 0 ? nil : method
|
260
|
+
method.sub!("block in ".freeze, "".freeze)
|
261
|
+
method.sub!("in `".freeze, "".freeze)
|
262
|
+
method.sub!("'".freeze, "".freeze)
|
263
|
+
method.index("_app_views_".freeze) == 0 ? nil : method
|
253
264
|
end
|
254
265
|
|
255
266
|
def compute_duration(start, finish)
|
@@ -257,7 +268,7 @@ module RorVsWild
|
|
257
268
|
end
|
258
269
|
|
259
270
|
def relative_path(path)
|
260
|
-
path.sub(Rails.root.to_s, "")
|
271
|
+
path.sub(Rails.root.to_s, "".freeze)
|
261
272
|
end
|
262
273
|
|
263
274
|
def exception_to_hash(exception, extra_details = nil)
|
@@ -277,7 +288,7 @@ module RorVsWild
|
|
277
288
|
uri = URI(api_url + path)
|
278
289
|
Net::HTTP.start(uri.host, uri.port) do |http|
|
279
290
|
post = Net::HTTP::Post.new(uri.path)
|
280
|
-
post.content_type = "application/json"
|
291
|
+
post.content_type = "application/json".freeze
|
281
292
|
post.basic_auth(app_id, api_key)
|
282
293
|
post.body = data.to_json
|
283
294
|
http.request(post)
|
@@ -303,15 +314,17 @@ module RorVsWild
|
|
303
314
|
end
|
304
315
|
end
|
305
316
|
|
317
|
+
DASH_PERFORM = "#perform".freeze
|
318
|
+
|
306
319
|
module ResquePlugin
|
307
320
|
def around_perform_rorvswild(*args, &block)
|
308
|
-
RorVsWild.measure_block(to_s +
|
321
|
+
RorVsWild.measure_block(to_s + DASH_PERFORM, &block)
|
309
322
|
end
|
310
323
|
end
|
311
324
|
|
312
325
|
class SidekiqPlugin
|
313
326
|
def call(worker, item, queue, &block)
|
314
|
-
RorVsWild.measure_block(item["class"] +
|
327
|
+
RorVsWild.measure_block(item["class".freeze] + DASH_PERFORM, &block)
|
315
328
|
end
|
316
329
|
end
|
317
330
|
end
|
data/test/ror_vs_wild_test.rb
CHANGED
@@ -70,6 +70,10 @@ class RorVsWildTest < MiniTest::Unit::TestCase
|
|
70
70
|
assert_equal(%w[/ruby/gems/lib/sql.rb 1 method1], client.send(:extract_error_location, callstack))
|
71
71
|
end
|
72
72
|
|
73
|
+
def test_extract_error_location_when_there_is_no_method_name
|
74
|
+
assert_equal(["/foo/bar.rb", "123", nil], client.send(:extract_error_location, ["/foo/bar.rb:123"]))
|
75
|
+
end
|
76
|
+
|
73
77
|
private
|
74
78
|
|
75
79
|
def client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rorvswild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Bernard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|