oyencov 0.0.8 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/oyencov/api_connection.rb +1 -1
- data/lib/oyencov/background.rb +20 -4
- data/lib/oyencov/cli.rb +3 -5
- data/lib/oyencov/configuration.rb +10 -6
- data/lib/oyencov/logger.rb +1 -1
- data/lib/oyencov/puma/plugin/oyencov.rb +16 -1
- data/lib/oyencov/railtie.rb +10 -5
- data/lib/oyencov/version.rb +1 -1
- data/lib/oyencov.rb +20 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a4f51c426c0d097999e548f0ba5920105655e1fbb04b731055573889239fb85
|
4
|
+
data.tar.gz: 57eee19f6e39579159c9175ee78faf3b8b7e6e40d8f1adb15fe85d325ee0c652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf0d4fd53946d6fe3e43155a3dd9aa3dca94d81054a8b8b0789e29a3241cb26589f25e565fb0b31e4874ae5ec91f8e69c47defc275a4d2272259f4c8823ec7bf
|
7
|
+
data.tar.gz: 106e34406d36a110d79f21b536c0deaa304ff3ed927b100c7343917b5a6c4dbe0d05c70a400d84e69d2e97d5a7a918e3d1fa712474ca896a506c13d84f35dc45
|
data/lib/oyencov/background.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "securerandom"
|
2
2
|
require "singleton"
|
3
3
|
require_relative "api_connection"
|
4
|
+
require_relative "controller_tracking"
|
4
5
|
require_relative "coverage_peek_delta"
|
5
6
|
require_relative "logger"
|
6
7
|
|
@@ -16,18 +17,29 @@ require_relative "logger"
|
|
16
17
|
#
|
17
18
|
module OyenCov
|
18
19
|
class Background
|
20
|
+
# Added to be more fork-aware. Ruby/Puma can fork a process copy-on-write,
|
21
|
+
# but it won't start the threads that are running in the parent process.
|
22
|
+
#
|
23
|
+
# If the PID > 0 but also not the current process_id, make the thread run.
|
24
|
+
@@running_pid = 0
|
25
|
+
|
19
26
|
@loop_interval = 60 # seconds, can be set from server
|
20
|
-
@semaphore = Mutex.new
|
21
27
|
@thread = nil
|
22
28
|
@reporter = nil
|
23
29
|
@api_conn = OyenCov::APIConnection.instance
|
24
30
|
@config = OyenCov.config
|
25
31
|
|
26
32
|
def self.start
|
33
|
+
if @@running_pid == $$
|
34
|
+
OyenCov::Logger.log("OyenCov Background thread is already running.")
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
|
27
38
|
OyenCov::Logger.log(<<~TXT)
|
28
39
|
Env: #{@config.mode}
|
29
|
-
|
30
|
-
|
40
|
+
program_name: #{$PROGRAM_NAME || "nil"}
|
41
|
+
process_type: #{@config.process_type}
|
42
|
+
release/git_commit_sha: #{@config.release}
|
31
43
|
Env vars set: #{ENV.keys.grep(/^OYENCOV_/)}
|
32
44
|
TXT
|
33
45
|
|
@@ -43,7 +55,7 @@ module OyenCov
|
|
43
55
|
clearance = @api_conn.get_data_submission_clearance
|
44
56
|
|
45
57
|
unless clearance && clearance["status"] == "ok"
|
46
|
-
OyenCov::Logger.log "Unable to obtain oyencov submission clearance. Stopping OyenCov background thread."
|
58
|
+
OyenCov::Logger.log "Unable to obtain oyencov submission clearance. Stopping OyenCov background thread. #{clearance.inspect}"
|
47
59
|
Thread.stop
|
48
60
|
end
|
49
61
|
|
@@ -77,6 +89,7 @@ module OyenCov
|
|
77
89
|
OyenCov::Logger.log "POST runtime_report ok."
|
78
90
|
else
|
79
91
|
OyenCov::Logger.log "POST runtime_report failed. Stopping background thread."
|
92
|
+
@@running_pid = 0
|
80
93
|
Thread.stop
|
81
94
|
end
|
82
95
|
|
@@ -85,6 +98,8 @@ module OyenCov
|
|
85
98
|
}
|
86
99
|
|
87
100
|
@thread.run
|
101
|
+
OyenCov::Logger.log("OyenCov Background thread starts.")
|
102
|
+
@@running_pid = $$
|
88
103
|
|
89
104
|
nil
|
90
105
|
end
|
@@ -93,6 +108,7 @@ module OyenCov
|
|
93
108
|
# For `test`, persist controller report.
|
94
109
|
def self.stop
|
95
110
|
@thread.stop
|
111
|
+
@@running_pid = 0
|
96
112
|
end
|
97
113
|
|
98
114
|
private_class_method
|
data/lib/oyencov/cli.rb
CHANGED
@@ -82,11 +82,9 @@ module OyenCov
|
|
82
82
|
"git_commit_sha" => options[:git_commit_sha]
|
83
83
|
})
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
ENV["OYENCOV_API_KEY"] ||= options[:token]
|
85
|
+
if options[:token]
|
86
|
+
ENV["OYENCOV_API_KEY"] = options[:token]
|
87
|
+
end
|
90
88
|
unless ENV["OYENCOV_API_KEY"]
|
91
89
|
warn "API token not set. Unable to submit."
|
92
90
|
exit(1)
|
@@ -42,7 +42,7 @@ module OyenCov
|
|
42
42
|
|
43
43
|
# Lots of ideas came from sentry-ruby, thanks to nate berkopec.
|
44
44
|
def suggest_release
|
45
|
-
release = `git rev-parse HEAD
|
45
|
+
release = `git rev-parse HEAD 2>/dev/null || true`.strip
|
46
46
|
|
47
47
|
if release == "" || release.nil?
|
48
48
|
[".source_version", "REVISION"].each do |version_clue|
|
@@ -52,7 +52,8 @@ module OyenCov
|
|
52
52
|
Bundler.root.join(version_clue)
|
53
53
|
elsif defined?(Pathname.pwd) && Pathname.pwd
|
54
54
|
Pathname.pwd.join(version_clue)
|
55
|
-
else
|
55
|
+
else
|
56
|
+
next
|
56
57
|
end
|
57
58
|
|
58
59
|
if File.exist?(version_clue_path)
|
@@ -85,10 +86,13 @@ module OyenCov
|
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
# If its cluster mode & we are in worker process, puma is at the beginning.
|
90
|
+
# If it's `bundle exec puma` then it comes in the end
|
91
|
+
#
|
92
|
+
# If it's booted up by puma not rails server, `Rails` module wont be defined.
|
93
|
+
# We will just assume puma = rails-server
|
94
|
+
if /^puma/.match?($0) || sliced_program_name == "puma"
|
95
|
+
return "rails-server"
|
92
96
|
end
|
93
97
|
|
94
98
|
# Rails can be server or rake task
|
data/lib/oyencov/logger.rb
CHANGED
@@ -12,7 +12,7 @@ module OyenCov
|
|
12
12
|
if Exception === msg
|
13
13
|
msg = msg.inspect
|
14
14
|
end
|
15
|
-
formatted_msg = msg.split("\n").map { |m| "#{ORANGE_TEXT}[OyenCov] #{m}#{RESET_COLOR}" }.join("\n")
|
15
|
+
formatted_msg = msg.split("\n").map { |m| "#{ORANGE_TEXT}[OyenCov] PID##{$$} #{m}#{RESET_COLOR}" }.join("\n")
|
16
16
|
|
17
17
|
if level == 2
|
18
18
|
warn formatted_msg
|
@@ -2,15 +2,30 @@ require "puma/plugin"
|
|
2
2
|
require_relative "../../background"
|
3
3
|
require_relative "../../logger"
|
4
4
|
|
5
|
-
Puma::Plugin.create do
|
5
|
+
defined?(Puma::Plugin.create) && Puma::Plugin.create do
|
6
6
|
OyenCov::Logger.log("Puma::Plugin.create running...")
|
7
7
|
|
8
8
|
def config(c)
|
9
9
|
OyenCov::Logger.log("Puma::Plugin.create config(c) running...")
|
10
10
|
|
11
|
+
c.on_booted do
|
12
|
+
OyenCov::Logger.log("Puma::Plugin.create config on_booted called")
|
13
|
+
OyenCov::Background.start
|
14
|
+
if defined?(Rails::Railtie)
|
15
|
+
load(File.expand_path("../../railtie.rb", File.dirname(__FILE__)))
|
16
|
+
else
|
17
|
+
OyenCov::Logger.log("on_booted: Railtie undefined 😭")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
c.on_worker_boot do
|
12
22
|
OyenCov::Logger.log("Puma::Plugin.create config on_worker_boot called")
|
13
23
|
OyenCov::Background.start
|
24
|
+
if defined?(Rails::Railtie)
|
25
|
+
load(File.expand_path("../../railtie.rb", File.dirname(__FILE__)))
|
26
|
+
else
|
27
|
+
OyenCov::Logger.log("on_worker_boot: Railtie undefined 😭")
|
28
|
+
end
|
14
29
|
end
|
15
30
|
end
|
16
31
|
end
|
data/lib/oyencov/railtie.rb
CHANGED
@@ -5,6 +5,9 @@ require_relative "logger"
|
|
5
5
|
|
6
6
|
module OyenCov
|
7
7
|
class Railtie < Rails::Railtie
|
8
|
+
@@controller_tracker_notification = nil
|
9
|
+
|
10
|
+
# This is only useful when `rails s` is run in lieu of webserver command first.
|
8
11
|
def install_puma_hooks
|
9
12
|
return unless defined?(Puma)
|
10
13
|
OyenCov::Logger.log("Puma defined, installing puma hooks")
|
@@ -15,7 +18,7 @@ module OyenCov
|
|
15
18
|
OyenCov::Logger.log("Load errors: #{e}")
|
16
19
|
end
|
17
20
|
|
18
|
-
#
|
21
|
+
# Cluster mode
|
19
22
|
if defined?(Puma::Plugin)
|
20
23
|
OyenCov::Logger.log("Puma::Plugin defined, installing hooks for CLUSTER MODE")
|
21
24
|
require_relative "puma/plugin/oyencov"
|
@@ -25,12 +28,14 @@ module OyenCov
|
|
25
28
|
initializer "oyencov.configure" do
|
26
29
|
OyenCov::Background.start
|
27
30
|
install_puma_hooks
|
28
|
-
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
if @@controller_tracker_notification.nil?
|
33
|
+
OyenCov::Logger.log "@@controller_tracker_notification is nil"
|
34
|
+
else
|
35
|
+
OyenCov::Logger.log "@@controller_tracker_notification is already set, Railtie init rerun."
|
36
|
+
end
|
32
37
|
|
33
|
-
ActiveSupport::Notifications.subscribe("start_processing.action_controller") do |name, start, finish, id, payload|
|
38
|
+
@@controller_tracker_notification ||= ActiveSupport::Notifications.subscribe("start_processing.action_controller") do |name, start, finish, id, payload|
|
34
39
|
ControllerTracking.bump("#{payload[:controller]}##{payload[:action]}")
|
35
40
|
OyenCov::Logger.log "ControllerTracking.bump(#{payload[:controller]}##{payload[:action]})"
|
36
41
|
end
|
data/lib/oyencov/version.rb
CHANGED
data/lib/oyencov.rb
CHANGED
@@ -3,17 +3,33 @@ require_relative "oyencov/simplecov_resultset_translator"
|
|
3
3
|
require_relative "oyencov/version"
|
4
4
|
require_relative "oyencov/logger"
|
5
5
|
|
6
|
-
# For now, support only Rails. We bootstrap from Railtie.
|
6
|
+
# For now, support only Rails. We bootstrap background thread and controller tracking from Railtie.
|
7
7
|
module OyenCov
|
8
8
|
def self.config
|
9
9
|
@config ||= OyenCov::Configuration.new
|
10
10
|
end
|
11
11
|
|
12
|
+
# Sometimes oyencov cant start on their own, maybe when oyencov is loaded
|
13
|
+
# before Rails did.
|
14
|
+
#
|
15
|
+
# For Rails, put `OyenCov.start!` in `config/initializers/oyencov.rb`.
|
16
|
+
def self.start!
|
17
|
+
require_relative "oyencov/railtie"
|
18
|
+
end
|
19
|
+
|
12
20
|
OyenCov::Logger.log("Hello! Booting from #{__FILE__}")
|
13
|
-
|
14
|
-
|
21
|
+
OyenCov::Logger.log("Checking/Forcing Rails existence")
|
22
|
+
|
23
|
+
begin
|
24
|
+
require "rails"
|
25
|
+
rescue LoadError
|
26
|
+
# do nothing
|
27
|
+
end
|
28
|
+
|
15
29
|
if defined?(Rails::Railtie) # && ENV["OYENCOV_API_KEY"]
|
16
|
-
OyenCov::Logger.log("
|
30
|
+
OyenCov::Logger.log("Rails::Railtie already present, starting oyencov/railtie")
|
17
31
|
require_relative "oyencov/railtie"
|
32
|
+
else
|
33
|
+
OyenCov::Logger.log("Rails::Railtie absent, cannot start tracking & reporting yet.")
|
18
34
|
end
|
19
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oyencov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anonoz Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|