rorvswild 1.5.1 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9273a6bd33ffb223f1d894975c3d25ad0e4f291295e3267fb6d995ad367b777a
4
- data.tar.gz: 3e32db66b9ee0984352b5e559efa94b3b6a2f35b9c43af0631a1c95a3ecdb6ba
3
+ metadata.gz: a9e6a2963e38a065dfaba2af93a5d05275a18d6a57c9e3b12b80b027f8f6c605
4
+ data.tar.gz: 953c30a7d822f9ea69b2c2ef16d96f7a16ed5765da2fa8d013982a553c1a06f8
5
5
  SHA512:
6
- metadata.gz: 53433ea46f20730ee3813ecac8437761fb700645e2c9e4ced1a69c67dafe22e1f6ec3905fa7d320798b984fdaecd1c4c252c6c2373a465f4788a0a9e905edebe
7
- data.tar.gz: 8b27c4b3eb3e4f37a5e2c4dbacce88c52ff022ecd7cacf328fe39f7466bef8aaa9d35739c369481368f5ac147b62d73ab41a2d6b0a4ea979720ef0a8ab94215a
6
+ metadata.gz: bad6d0f028f564619f7283f582fbf5f008f8cf5fcd5b38ab8036fb570438ef1e4e75d2bffeeff93f562f541dc4bdf7cbdf3b38435fc44d354c82f9fd01b7cc5b
7
+ data.tar.gz: 31a9d64bbc3a6468022705025bab670c2dd3d156a9e35ba9241450f2d98a45c4f30448f25ceab7d7b983a21d251907dc3c4aeef6900084559a47b1c27841748b
@@ -48,11 +48,11 @@ module RorVsWild
48
48
  end
49
49
 
50
50
  def measure_block(name, kind = "code".freeze, &block)
51
- data[:name] ? measure_section(name, kind: kind, &block) : measure_job(name, &block)
51
+ current_data ? measure_section(name, kind: kind, &block) : measure_job(name, &block)
52
52
  end
53
53
 
54
54
  def measure_section(name, kind: "code", appendable_command: false, &block)
55
- return block.call unless data[:name]
55
+ return block.call unless current_data
56
56
  begin
57
57
  RorVsWild::Section.start do |section|
58
58
  section.appendable_command = appendable_command
@@ -66,29 +66,27 @@ module RorVsWild
66
66
  end
67
67
 
68
68
  def measure_job(name, parameters: nil, &block)
69
- return measure_section(name, &block) if data[:name] # For recursive jobs
69
+ return measure_section(name, &block) if current_data # For recursive jobs
70
70
  return block.call if ignored_job?(name)
71
- initialize_data(name)
71
+ initialize_data[:name] = name
72
72
  begin
73
73
  block.call
74
74
  rescue Exception => ex
75
75
  push_exception(ex, parameters: parameters)
76
76
  raise
77
77
  ensure
78
- data[:runtime] = RorVsWild.clock_milliseconds - data[:started_at]
78
+ current_data[:runtime] = RorVsWild.clock_milliseconds - current_data[:started_at]
79
79
  post_job
80
80
  end
81
81
  end
82
82
 
83
- def start_request(payload)
84
- return if data[:name]
85
- initialize_data(payload[:name])
86
- data[:path] = payload[:path]
83
+ def start_request
84
+ current_data || initialize_data
87
85
  end
88
86
 
89
87
  def stop_request
90
- return unless data[:name]
91
- data[:runtime] = RorVsWild.clock_milliseconds - data[:started_at]
88
+ return unless current_data
89
+ current_data[:runtime] = RorVsWild.clock_milliseconds - current_data[:started_at]
92
90
  post_request
93
91
  end
94
92
 
@@ -107,21 +105,21 @@ module RorVsWild
107
105
 
108
106
  def push_exception(exception, options = nil)
109
107
  return if ignored_exception?(exception)
110
- data[:error] = exception_to_hash(exception)
111
- data[:error].merge!(options) if options
112
- data[:error]
108
+ current_data[:error] = exception_to_hash(exception)
109
+ current_data[:error].merge!(options) if options
110
+ current_data[:error]
113
111
  end
114
112
 
115
- def data
116
- Thread.current[:rorvswild_data] ||= {}
113
+ def current_data
114
+ Thread.current[:rorvswild_data]
117
115
  end
118
116
 
119
117
  def add_section(section)
120
- return unless data[:sections]
121
- if sibling = data[:sections].find { |s| s.sibling?(section) }
118
+ return unless current_data[:sections]
119
+ if sibling = current_data[:sections].find { |s| s.sibling?(section) }
122
120
  sibling.merge(section)
123
121
  else
124
- data[:sections] << section
122
+ current_data[:sections] << section
125
123
  end
126
124
  end
127
125
 
@@ -139,11 +137,8 @@ module RorVsWild
139
137
 
140
138
  private
141
139
 
142
- def initialize_data(name)
143
- data[:name] = name
144
- data[:sections] = []
145
- data[:section_stack] = []
146
- data[:started_at] = RorVsWild.clock_milliseconds
140
+ def initialize_data
141
+ Thread.current[:rorvswild_data] = {sections: [], section_stack: [], started_at: RorVsWild.clock_milliseconds}
147
142
  end
148
143
 
149
144
  def cleanup_data
@@ -153,7 +148,7 @@ module RorVsWild
153
148
  end
154
149
 
155
150
  def post_request
156
- queue.push_request(cleanup_data)
151
+ (data = cleanup_data) && data[:name] && queue.push_request(data)
157
152
  end
158
153
 
159
154
  def post_job
@@ -34,15 +34,15 @@ module RorVsWild
34
34
  end
35
35
 
36
36
  def relative_path(path)
37
- path.index(current_path) == 0 ? path.sub(current_path, "".freeze) : path
37
+ path.start_with?(current_path) ? path.sub(current_path, "".freeze) : path
38
38
  end
39
39
 
40
40
  def relevant_path?(path)
41
- path.index(current_path) == 0 && !irrelevant_path?(path)
41
+ path.start_with?(current_path) && !irrelevant_path?(path)
42
42
  end
43
43
 
44
44
  def irrelevant_path?(path)
45
- irrelevant_paths.any? { |irrelevant_path| path.index(irrelevant_path) }
45
+ path.start_with?(*irrelevant_paths)
46
46
  end
47
47
 
48
48
  def irrelevant_paths
@@ -52,7 +52,7 @@ module RorVsWild
52
52
  private
53
53
 
54
54
  def initialize_irrelevant_paths
55
- array = ["RUBYLIB", "GEM_HOME", "GEM_PATH", "BUNDLER_ORIG_PATH", "BUNDLER_ORIG_GEM_PATH"].flat_map do |name|
55
+ array = ["RUBYLIB", "GEM_HOME", "GEM_PATH", "BUNDLER_ORIG_GEM_PATH"].flat_map do |name|
56
56
  ENV[name].split(":".freeze) if ENV[name]
57
57
  end
58
58
  array += [heroku_ruby_lib_path] if File.exists?(heroku_ruby_lib_path)
@@ -5,11 +5,28 @@ module RorVsWild
5
5
  return if @installed
6
6
  return unless defined?(::ActionController::Base)
7
7
  ActiveSupport::Notifications.subscribe("process_action.action_controller", new)
8
- ::ActionController::Base.around_action(&method(:around_action))
9
8
  ::ActionController::Base.rescue_from(StandardError) { |ex| RorVsWild::Plugin::ActionController.after_exception(ex, self) }
10
9
  @installed = true
11
10
  end
12
11
 
12
+ def start(name, id, payload)
13
+ controller_action = "#{payload[:controller]}##{payload[:action]}"
14
+ if !RorVsWild.agent.ignored_request?(controller_action)
15
+ section = RorVsWild::Section.start
16
+ RorVsWild.agent.current_data[:name] = controller_action
17
+ controller = payload[:headers]["action_controller.instance".freeze]
18
+ method_name = controller.method_for_action(payload[:action])
19
+ section.file, section.line = controller.method(method_name).source_location
20
+ section.file = RorVsWild.agent.locator.relative_path(section.file)
21
+ section.command = "#{controller.class}##{method_name}"
22
+ section.kind = "code".freeze
23
+ end
24
+ end
25
+
26
+ def finish(name, id, payload)
27
+ RorVsWild::Section.stop
28
+ end
29
+
13
30
  def self.after_exception(exception, controller)
14
31
  if hash = RorVsWild.agent.push_exception(exception)
15
32
  hash[:session] = controller.session.to_hash
@@ -19,32 +36,6 @@ module RorVsWild
19
36
  raise exception
20
37
  end
21
38
 
22
- def self.around_action(controller, block)
23
- begin
24
- RorVsWild::Section.start do |section|
25
- method_name = controller.method_for_action(controller.action_name)
26
- section.file, section.line = controller.method(method_name).source_location
27
- section.file = RorVsWild.agent.locator.relative_path(section.file)
28
- section.command = "#{controller.class}##{method_name}"
29
- section.kind = "code".freeze
30
- end
31
- block.call
32
- ensure
33
- RorVsWild::Section.stop
34
- end
35
- end
36
-
37
- # Payload: controller, action, params, format, method, path
38
- def start(name, id, payload)
39
- if !RorVsWild.agent.ignored_request?(name = "#{payload[:controller]}##{payload[:action]}")
40
- RorVsWild.agent.start_request(name: name, path: payload[:path])
41
- end
42
- end
43
-
44
- def finish(name, id, payload)
45
- RorVsWild.agent.stop_request
46
- end
47
-
48
39
  def self.extract_http_headers(headers)
49
40
  headers.reduce({}) do |hash, (name, value)|
50
41
  if name.index("HTTP_".freeze) == 0 && name != "HTTP_COOKIE".freeze
@@ -0,0 +1,27 @@
1
+ module RorVsWild
2
+ module Plugin
3
+ class ActionDispatch
4
+ def self.setup
5
+ return if @installed
6
+ return unless defined?(::ActiveSupport::Notifications)
7
+ ActiveSupport::Notifications.subscribe("request.action_dispatch", new)
8
+ @installed = true
9
+ end
10
+
11
+ def start(name, id, payload)
12
+ RorVsWild.agent.start_request
13
+ RorVsWild.agent.current_data[:path] = payload[:request].original_fullpath
14
+ @action_dispath_location ||= ::ActionDispatch::Executor.instance_method(:call).source_location
15
+ section = RorVsWild::Section.start
16
+ section.file, section.line = @action_dispath_location
17
+ section.command = "ActionDispatch::Executor.#call".freeze
18
+ section.kind = "code".freeze
19
+ end
20
+
21
+ def finish(name, id, payload)
22
+ RorVsWild::Section.stop
23
+ RorVsWild.agent.stop_request
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,6 +1,6 @@
1
1
  module RorVsWild
2
2
  module Plugin
3
- module ActiveJob
3
+ class ActiveJob
4
4
  def self.setup
5
5
  return if @installed
6
6
  return unless defined?(::ActiveJob::Base)
@@ -9,7 +9,17 @@ module RorVsWild
9
9
  end
10
10
 
11
11
  def self.around_perform(job, block)
12
- RorVsWild.agent.measure_job(job.class.name, parameters: job.arguments, &block)
12
+ RorVsWild.agent.measure_job(job.class.name, parameters: job.arguments) do
13
+ begin
14
+ section = RorVsWild::Section.start
15
+ section.command = "#{job.class}#perform"
16
+ section.file, section.line = job.method(:perform).source_location
17
+ section.file = RorVsWild.agent.locator.relative_path(section.file)
18
+ block.call
19
+ ensure
20
+ RorVsWild::Section.stop
21
+ end
22
+ end
13
23
  end
14
24
  end
15
25
  end
@@ -58,7 +58,6 @@ module RorVsWild
58
58
  end
59
59
 
60
60
  def flush
61
- RorVsWild.logger.info("RorVsWild::Queue#flush".freeze)
62
61
  data = pull_jobs and client.post("/jobs", jobs: data)
63
62
  data = pull_requests and client.post("/requests", requests: data)
64
63
  end
@@ -6,12 +6,12 @@ module RorVsWild
6
6
  def self.start(&block)
7
7
  section = Section.new
8
8
  block.call(section) if block_given?
9
- stack.push(section)
9
+ stack && stack.push(section)
10
10
  section
11
11
  end
12
12
 
13
13
  def self.stop(&block)
14
- section = stack.pop
14
+ return unless stack && section = stack.pop
15
15
  block.call(section) if block_given?
16
16
  section.total_runtime = RorVsWild.clock_milliseconds - section.started_at
17
17
  current.children_runtime += section.total_runtime if current
@@ -19,17 +19,18 @@ module RorVsWild
19
19
  end
20
20
 
21
21
  def self.stack
22
- RorVsWild.agent.data[:section_stack] ||= []
22
+ (data = RorVsWild.agent.current_data) && data[:section_stack]
23
23
  end
24
24
 
25
25
  def self.current
26
- stack.last
26
+ (sections = stack) && sections.last
27
27
  end
28
28
 
29
29
  def initialize
30
30
  @calls = 1
31
31
  @total_runtime = 0
32
32
  @children_runtime = 0
33
+ @kind = "code".freeze
33
34
  @started_at = RorVsWild.clock_milliseconds
34
35
  location = RorVsWild.agent.locator.find_most_relevant_location(caller_locations)
35
36
  @file = RorVsWild.agent.locator.relative_path(location.path)
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "1.5.1".freeze
2
+ VERSION = "1.5.2".freeze
3
3
  end
data/lib/rorvswild.rb CHANGED
@@ -40,7 +40,7 @@ module RorVsWild
40
40
  end
41
41
 
42
42
  def self.initialize_logger(destination = nil)
43
- if destination.is_a?(Logger)
43
+ if destination.respond_to?(:info) && destination.respond_to?(:warn) && destination.respond_to?(:error)
44
44
  destination
45
45
  elsif destination
46
46
  Logger.new(destination)
@@ -54,6 +54,16 @@ module RorVsWild
54
54
  def self.clock_milliseconds
55
55
  Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
56
56
  end
57
+
58
+ def self.check
59
+ api_key = RorVsWild.agent.config[:api_key]
60
+ return puts "You API key is missing and has to be defined in config/rorvswild.yml." if !api_key || api_key.empty?
61
+ puts case response = agent.client.post("/jobs", jobs: [{sections: [], name: "RorVsWild.check", runtime: 0}])
62
+ when Net::HTTPOK then "Connection to RorVsWild works fine !"
63
+ when Net::HTTPUnauthorized then "Wrong API key"
64
+ else puts "Something went wrong: #{response.inspect}"
65
+ end
66
+ end
57
67
  end
58
68
 
59
69
  if defined?(Rails)
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.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-04 00:00:00.000000000 Z
11
+ date: 2020-04-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Performances and quality insights for rails developers.
14
14
  email:
@@ -39,6 +39,7 @@ files:
39
39
  - lib/rorvswild/local/stylesheet/vendor/prism.css
40
40
  - lib/rorvswild/locator.rb
41
41
  - lib/rorvswild/plugin/action_controller.rb
42
+ - lib/rorvswild/plugin/action_dispatch.rb
42
43
  - lib/rorvswild/plugin/action_mailer.rb
43
44
  - lib/rorvswild/plugin/action_view.rb
44
45
  - lib/rorvswild/plugin/active_job.rb