rorvswild 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af8c234822923144b958f222e3cd52ccce3d9304
4
- data.tar.gz: f9722694ba63f629530ad5cf3a7be34d7dc7a2b5
3
+ metadata.gz: 8f3058ebf12d59185c06a6e58d0708b768cbbd5e
4
+ data.tar.gz: 180c22cf8f25b526509164cd053fad4ddda35376
5
5
  SHA512:
6
- metadata.gz: 6df568fff50b1acc8c56315da929978c1d057dca8375f8a20a47a9a230a886a59511a0af3a4c061545332c351e39f69228eb1df6f83ea91bb9807760a76fef92
7
- data.tar.gz: b6087bcbd33ed5364b94d1f587157756b4ae15161debcb61b5f87044d964d1ef5a1dd5bcd352f1f7b16532d1c87ce28981121b87819203685bc42b2de113ab98
6
+ metadata.gz: 4c7a6ba4143a8a1c1060a2bbd5b2ebaac29d3f29eb8a44d54aba7e170008903c9ff8b9dae020b2236864ed8fa3a24ce76222aab4c99251929fd1765e001e22d2
7
+ data.tar.gz: e4daa2f6ed71388c9a935ea3d6757a426e25e93206c688887f5cb02d90355329e354c47306a62dff887ad3b942fd71cd9b9790bd67bafdbab1a4a3c26448ced1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RorVsWild
2
2
 
3
- Simple Ruby on Rails application monitoring for hardcore developers with no time to waste: http://www.rorvswild.com.
3
+ All-in-one monitoring for Ruby on Rails applications.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,13 +14,15 @@ module RorVsWild
14
14
  return if !defined?(Rails)
15
15
  Rails::Railtie.initializer "rorvswild.detect_config_file" do
16
16
  if !RorVsWild.default_client && (path = Rails.root.join("config/rorvswild.yml")).exist?
17
- RorVsWild.load_config_file(path, Rails.env)
17
+ if config = RorVsWild.load_config_file(path)[Rails.env]
18
+ RorVsWild::Client.new(config.symbolize_keys)
19
+ end
18
20
  end
19
21
  end
20
22
  end
21
23
 
22
- def self.load_config_file(path, environment)
23
- config = YAML.load_file(path)[environment.to_s] and Client.new(config.symbolize_keys)
24
+ def self.load_config_file(path)
25
+ YAML.load(ERB.new(path.read).result)
24
26
  end
25
27
 
26
28
  def self.register_default_client(client)
@@ -226,19 +228,16 @@ module RorVsWild
226
228
  @data.delete(Thread.current.object_id)
227
229
  end
228
230
 
231
+ MEANINGLESS_QUERIES = %w[BEGIN COMMIT].freeze
232
+
229
233
  def push_query(query)
230
- if hash = queries.find { |hash| hash[:line] == query[:line] && hash[:file] == query[:file] }
231
- if query[:runtime] > hash[:max_runtime]
232
- hash[:max_runtime] = query[:runtime]
233
- hash[:plan] = query[:plan]
234
- hash[:sql] = query[:sql]
235
- end
236
- hash[:runtime] += query[:runtime]
234
+ hash = queries.find { |hash| hash[:line] == query[:line] && hash[:file] == query[:file] }
235
+ queries << hash = {file: query[:file], line: query[:line], runtime: 0, times: 0} if !hash
236
+ hash[:runtime] += query[:runtime]
237
+ if !MEANINGLESS_QUERIES.include?(query[:sql])
237
238
  hash[:times] += 1
238
- else
239
- query[:times] = 1
240
- query[:max_runtime] = query[:runtime]
241
- queries << query
239
+ hash[:sql] ||= query[:sql]
240
+ hash[:plan] ||= query[:plan] if query[:plan]
242
241
  end
243
242
  end
244
243
 
@@ -275,11 +274,21 @@ module RorVsWild
275
274
  post("/errors".freeze, error: hash)
276
275
  end
277
276
 
278
- GEM_HOME_REGEX = ENV["GEM_HOME"] ? /\A#{ENV["GEM_HOME"]}/.freeze : nil
277
+ def gem_home
278
+ if ENV["GEM_HOME"] && !ENV["GEM_HOME"].empty?
279
+ ENV["GEM_HOME"]
280
+ elsif ENV["GEM_PATH"] && !(first_gem_path = ENV["GEM_PATH"].split(":").first)
281
+ first_gem_path if first_gem_path && !first_gem_path.empty?
282
+ end
283
+ end
284
+
285
+ def gem_home_regex
286
+ @gem_home_regex ||= gem_home ? /\A#{gem_home}/.freeze : /\/gems\//.freeze
287
+ end
279
288
 
280
289
  def extract_most_relevant_location(stack)
281
- location = stack.find { |str| str =~ app_root_regex && !(str =~ GEM_HOME_REGEX) } if app_root_regex
282
- location ||= stack.find { |str| !(str =~ GEM_HOME_REGEX) } if GEM_HOME_REGEX
290
+ location = stack.find { |str| str =~ app_root_regex && !(str =~ gem_home_regex) } if app_root_regex
291
+ location ||= stack.find { |str| !(str =~ gem_home_regex) } if gem_home_regex
283
292
  split_file_location(relative_path(location || stack.first))
284
293
  end
285
294
 
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "0.3.4".freeze
2
+ VERSION = "0.3.5".freeze
3
3
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = RorVsWild::VERSION
9
9
  spec.authors = ["Alexis Bernard"]
10
10
  spec.email = ["alexis@bernard.io"]
11
- spec.summary = "Simple Ruby on Rails application monitoring for hardcore developers with no time to waste."
12
- spec.description = "Simple Ruby on Rails application monitoring for hardcore developers with no time to waste."
11
+ spec.summary = "All-in-one monitoring for Ruby on Rails applications."
12
+ spec.description = "All-in-one monitoring for Ruby on Rails applications."
13
13
  spec.homepage = "http://www.rorvswild.com"
14
14
  spec.license = "MIT"
15
15
 
@@ -7,7 +7,7 @@ require "minitest/autorun"
7
7
  require 'mocha/mini_test'
8
8
  require "top_tests"
9
9
 
10
- class RorVsWildTest < MiniTest::Unit::TestCase
10
+ class RorVsWildTest < Minitest::Test
11
11
  include TopTests
12
12
 
13
13
  def test_measure_code
@@ -79,12 +79,34 @@ class RorVsWildTest < MiniTest::Unit::TestCase
79
79
  assert_equal(["/app/models/user.rb", "3", "method3"], client.send(:extract_most_relevant_location, callstack))
80
80
  end
81
81
 
82
+ def test_extract_most_relevant_location_when_gem_path_is_set_instead_of_gem_home
83
+ original_gem_home, original_gem_path = ENV["GEM_HOME"], ENV["GEM_PATH"]
84
+ ENV["GEM_HOME"], ENV["GEM_PATH"] = "", "/gem/path"
85
+
86
+ callstack = ["/gem/path/lib/sql.rb:1:in `method1'", "/usr/lib/ruby/net/http.rb:2:in `method2'", "/rails/root/app/models/user.rb:3:in `method3'"]
87
+ assert_equal(%w[/app/models/user.rb 3 method3], client.send(:extract_most_relevant_location, callstack))
88
+ ensure
89
+ ENV["GEM_HOME"], ENV["GEM_PATH"] = original_gem_home, original_gem_path
90
+ end
91
+
92
+ def test_extract_most_relevant_location_when_gem_path_and_gem_home_are_undefined
93
+ original_gem_home, original_gem_path = ENV["GEM_HOME"], ENV["GEM_PATH"]
94
+ ENV["GEM_HOME"], ENV["GEM_PATH"] = "", ""
95
+
96
+ callstack = ["/gem/path/lib/sql.rb:1:in `method1'", "/usr/lib/ruby/net/http.rb:2:in `method2'", "/rails/root/app/models/user.rb:3:in `method3'"]
97
+ assert_equal(%w[/app/models/user.rb 3 method3], client.send(:extract_most_relevant_location, callstack))
98
+ ensure
99
+ ENV["GEM_HOME"], ENV["GEM_PATH"] = original_gem_home, original_gem_path
100
+ end
101
+
82
102
  def test_push_query
83
103
  client = initialize_client
84
104
  client.send(:data)[:queries] = []
105
+ client.send(:push_query, {file: "file", line: 123, sql: "BEGIN", runtime: 10})
106
+ client.send(:push_query, {file: "file", line: 123, sql: "SELECT 1", runtime: 10})
85
107
  client.send(:push_query, {file: "file", line: 123, sql: "SELECT 1", runtime: 10})
86
- client.send(:push_query, {file: "file", line: 123, sql: "SELECT 2", runtime: 11})
87
- assert_equal([{file: "file", line: 123, sql: "SELECT 2", runtime: 21, max_runtime: 11, times: 2, plan: nil,}], client.send(:queries))
108
+ client.send(:push_query, {file: "file", line: 123, sql: "COMMIT", runtime: 10})
109
+ assert_equal([{file: "file", line: 123, sql: "SELECT 1", runtime: 40, times: 2}], client.send(:queries))
88
110
  end
89
111
 
90
112
  def test_after_exception
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.3.4
4
+ version: 0.3.5
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-06-19 00:00:00.000000000 Z
11
+ date: 2015-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,8 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
- description: Simple Ruby on Rails application monitoring for hardcore developers with
28
- no time to waste.
27
+ description: All-in-one monitoring for Ruby on Rails applications.
29
28
  email:
30
29
  - alexis@bernard.io
31
30
  executables: []
@@ -62,10 +61,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
61
  version: '0'
63
62
  requirements: []
64
63
  rubyforge_project:
65
- rubygems_version: 2.2.2
64
+ rubygems_version: 2.4.8
66
65
  signing_key:
67
66
  specification_version: 4
68
- summary: Simple Ruby on Rails application monitoring for hardcore developers with
69
- no time to waste.
67
+ summary: All-in-one monitoring for Ruby on Rails applications.
70
68
  test_files:
71
69
  - test/ror_vs_wild_test.rb