rorvswild 1.1.1 → 1.2.0

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: 3d99dccaa0be65ef42005f19618032f0ed6dd02b
4
- data.tar.gz: 00f69ad52c795d66d6f46cf1fa2b075e42da047b
3
+ metadata.gz: dbddf42d7a3d87901206dcdb0872b689c733b100
4
+ data.tar.gz: 51c9aeebb5d2ec07863465db44f2253990421336
5
5
  SHA512:
6
- metadata.gz: d16fbec1a331e049787751d4116eaee4945b1e4e69d7b59f7738353d77098987dbbef94b1c469a1eb619ba0d619d4a5ca288db94c4745685fd0d4c3a7d3b4a90
7
- data.tar.gz: fb2ed2951ee072a73c19a4bd384259c0f1d59c6954e606f150241f9acae2b38cc987233a41cdb50ad4b7b6d084de6b740b0e9d1607ab53b924668326e7dbef65
6
+ metadata.gz: 1b109fabeb568743f2d306c8295bdb4201fa01773fb0940c9c2c8ebe1679426fe91969d56fa3c6c02217ef91e9f4241b23eac881a68ef276f6354b86c4eb69f4
7
+ data.tar.gz: e20ff2a1eae18fbaa31e4631f7a6093ce7b97be390ddc0acea6a6e6483820a1cefe7737572a439c90442d8299c79a119998c9ba33fee635f90d4c3194fadc8d4
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ gem "top_tests"
8
8
 
9
9
  gem "mongo"
10
10
  gem "redis"
11
+ gem "elasticsearch"
11
12
 
12
13
  gem "actionpack"
13
14
  gem "activejob"
@@ -40,6 +40,7 @@ module RorVsWild
40
40
 
41
41
  Plugin::Redis.setup
42
42
  Plugin::Mongo.setup
43
+ Plugin::Elasticsearch.setup
43
44
 
44
45
  Plugin::Resque.setup
45
46
  Plugin::Sidekiq.setup
@@ -0,0 +1,23 @@
1
+ module RorVsWild
2
+ module Plugin
3
+ class Elasticsearch
4
+ def self.setup
5
+ return if !defined?(::Elasticsearch::Transport)
6
+ return if ::Elasticsearch::Transport::Client.method_defined?(:perform_request_without_rorvswild)
7
+
8
+ ::Elasticsearch::Transport::Client.class_eval do
9
+ alias_method :perform_request_without_rorvswild, :perform_request
10
+
11
+ def perform_request(method, path, params={}, body=nil)
12
+ RorVsWild::Plugin::NetHttp.ignore do
13
+ command = {method: method, path: path, params: params, body: body}.to_json
14
+ RorVsWild.agent.measure_section(command, kind: "elasticsearch") do
15
+ perform_request_without_rorvswild(method, path, params, body)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -12,6 +12,14 @@ module RorVsWild
12
12
  alias_method :request_without_rorvswild, :request
13
13
 
14
14
  def request(req, body = nil, &block)
15
+ if Thread.current[:rorvswild_ignore_net_http]
16
+ request_without_rorvswild(req, body, &block)
17
+ else
18
+ request_with_rorvswild(req, body, &block)
19
+ end
20
+ end
21
+
22
+ def request_with_rorvswild(req, body = nil, &block)
15
23
  return request_without_rorvswild(req, body, &block) if request_called_twice?
16
24
  scheme = use_ssl? ? HTTPS : HTTP
17
25
  url = "#{req.method} #{scheme}://#{address}#{req.path}"
@@ -27,6 +35,14 @@ module RorVsWild
27
35
  end
28
36
  end
29
37
  end
38
+
39
+ def self.ignore(&block)
40
+ old_value = Thread.current[:rorvswild_ignore_net_http]
41
+ Thread.current[:rorvswild_ignore_net_http] = true
42
+ block.call
43
+ ensure
44
+ Thread.current[:rorvswild_ignore_net_http] = old_value
45
+ end
30
46
  end
31
47
  end
32
48
  end
@@ -2,6 +2,7 @@ require "rorvswild/plugin/net_http"
2
2
 
3
3
  require "rorvswild/plugin/redis"
4
4
  require "rorvswild/plugin/mongo"
5
+ require "rorvswild/plugin/elasticsearch"
5
6
 
6
7
  require "rorvswild/plugin/resque"
7
8
  require "rorvswild/plugin/sidekiq"
@@ -41,8 +41,6 @@ module RorVsWild
41
41
  kind == section.kind && line == section.line && file == section.file
42
42
  end
43
43
 
44
- MAX_COMMAND_HISTORY = 5
45
-
46
44
  def merge(section)
47
45
  self.calls += section.calls
48
46
  self.total_runtime += section.total_runtime
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "1.1.1".freeze
2
+ VERSION = "1.2.0".freeze
3
3
  end
data/test/helper.rb CHANGED
@@ -12,7 +12,7 @@ module RorVsWildAgentHelper
12
12
  end
13
13
 
14
14
  def initialize_agent(options = {})
15
- agent ||= RorVsWild.start(options)
15
+ agent ||= RorVsWild.start({logger: "/dev/null"}.merge(options))
16
16
  agent.stubs(:post_request)
17
17
  agent.stubs(:post_job)
18
18
  agent
@@ -0,0 +1,17 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../helper")
2
+
3
+ require "elasticsearch"
4
+
5
+ class RorVsWild::Plugin::ElasticsearchTest < Minitest::Test
6
+ include RorVsWildAgentHelper
7
+
8
+ def test_callback
9
+ agent.measure_block("elastic") do
10
+ ::Elasticsearch::Client.new.search(q: "test")
11
+ end
12
+ assert_equal(1, agent.data[:sections].size)
13
+ assert_equal(1, agent.data[:sections][0].calls)
14
+ assert_equal("elasticsearch", agent.data[:sections][0].kind)
15
+ assert_equal('{"method":"GET","path":"_search","params":{"q":"test"},"body":null}', agent.data[:sections][0].command)
16
+ end
17
+ end
data/test/queue_test.rb CHANGED
@@ -1,13 +1,17 @@
1
1
  require File.expand_path("#{File.dirname(__FILE__)}/helper")
2
2
 
3
3
  class QueueTest < Minitest::Test
4
+ include RorVsWildAgentHelper
5
+
4
6
  def test_push_job
7
+ queue.start_thread
5
8
  queue.thread.expects(:wakeup)
6
9
  10.times { queue.push_job(1) }
7
10
  assert_equal(10, queue.jobs.size)
8
11
  end
9
12
 
10
13
  def test_push_request
14
+ queue.start_thread
11
15
  queue.thread.expects(:wakeup)
12
16
  10.times { queue.push_request(1) }
13
17
  assert_equal(10, queue.requests.size)
@@ -43,10 +47,10 @@ class QueueTest < Minitest::Test
43
47
  end
44
48
 
45
49
  def queue
46
- @queue ||= RorVsWild::Queue.new(client)
50
+ @queue ||= agent.instance_variable_get(:@queue)
47
51
  end
48
52
 
49
53
  def client
50
- @client ||= RorVsWild::Client.new({})
54
+ @client ||= agent.instance_variable_get(:@client)
51
55
  end
52
56
  end
@@ -145,7 +145,7 @@ class RorVsWildTest < Minitest::Test
145
145
  end
146
146
 
147
147
  def initialize_agent(options = {})
148
- agent ||= RorVsWild.start(options)
148
+ agent ||= RorVsWild.start({logger: "/dev/null"}.merge(options))
149
149
  agent.stubs(:post_request)
150
150
  agent.stubs(:post_task)
151
151
  agent
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: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2017-11-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Performances and quality insights for rails developers.
14
14
  email:
@@ -36,6 +36,7 @@ files:
36
36
  - lib/rorvswild/plugin/active_job.rb
37
37
  - lib/rorvswild/plugin/active_record.rb
38
38
  - lib/rorvswild/plugin/delayed_job.rb
39
+ - lib/rorvswild/plugin/elasticsearch.rb
39
40
  - lib/rorvswild/plugin/mongo.rb
40
41
  - lib/rorvswild/plugin/net_http.rb
41
42
  - lib/rorvswild/plugin/redis.rb
@@ -55,6 +56,7 @@ files:
55
56
  - test/plugin/active_job_test.rb
56
57
  - test/plugin/active_record_test.rb
57
58
  - test/plugin/delayed_job_test.rb
59
+ - test/plugin/elasticsearch_test.rb
58
60
  - test/plugin/mongo_test.rb
59
61
  - test/plugin/net_http_test.rb
60
62
  - test/plugin/redis_test.rb
@@ -97,6 +99,7 @@ test_files:
97
99
  - test/plugin/active_job_test.rb
98
100
  - test/plugin/active_record_test.rb
99
101
  - test/plugin/delayed_job_test.rb
102
+ - test/plugin/elasticsearch_test.rb
100
103
  - test/plugin/mongo_test.rb
101
104
  - test/plugin/net_http_test.rb
102
105
  - test/plugin/redis_test.rb