rookout 0.1.5 → 0.1.10

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
  SHA256:
3
- metadata.gz: a651effede1b4bb60cf30bcc0ad23adac929ebb41ac69e0e059acc988542defc
4
- data.tar.gz: dd89562cd624e99ee1dbac58a9f045ee49175ccf12b9341df5cd0fbae1122774
3
+ metadata.gz: bb5339cdc9cb66af897ace6857663f6c784809a17948e17a854f7b204fc9c4a1
4
+ data.tar.gz: d80f3651e6284b7b2262a4f092b7f41b96d7fc45ada08ff1b70a4e1a1efe1304
5
5
  SHA512:
6
- metadata.gz: 42e4512c638fa18f2e75ac71154422a6a4a953ac013f070dfe07276f582aa695336baff015233df77bfe3daa36c44784ba65147c5d89682eacd6d985fa7d63aa
7
- data.tar.gz: 71926999899dd01a46af82f6ac5884f543b56804e91559f7085256e09d9a172541baf55b3f0a712d06b9997e3ec9f90ac372a028c5a4bf5839a539b17e5d6497
6
+ metadata.gz: 05c9290a00720940c4f3782126dd3d59d346bddf417e41334b00a3386d7ab14274a06f4744ddb89dad81ab65c0074ae99a13e799dceddd57c54c33a93ffef81a
7
+ data.tar.gz: 50f822a8bac76ead40a06595a8467661c4ac6718d72e270d2c5b88abbadd1e4754e06ff54d3e8d89a9397faabb2a208f9b97ef3d808c1ecd9c890560e781277b
@@ -0,0 +1,73 @@
1
+ module Rookout
2
+ class ForkManager
3
+ require "singleton"
4
+ include Singleton
5
+
6
+ def initialize
7
+ @active = false
8
+ end
9
+
10
+ def activate!
11
+ @active = true
12
+ end
13
+
14
+ def disable!
15
+ @active = false
16
+ end
17
+
18
+ def active?
19
+ @active
20
+ end
21
+
22
+ def fork_hook original_fork
23
+ if block_given?
24
+ original_fork.call do
25
+ post_fork_child if active?
26
+ yield
27
+ end
28
+ else
29
+ res = original_fork.call
30
+ post_fork_child if active? && !res
31
+ res
32
+ end
33
+ end
34
+
35
+ def post_fork_child
36
+ require_relative "rookout_singleton"
37
+ require_relative "interface"
38
+
39
+ RookoutSingleton.instance.post_fork_clean
40
+ Interface.instance.stop
41
+ Interface.instance.start post_fork: true
42
+
43
+ # Disable fork handler in child process
44
+ disable!
45
+ end
46
+ end
47
+ end
48
+
49
+ alias _rookout_original_fork fork
50
+
51
+ def self.fork &block
52
+ Rookout::ForkManager.instance.fork_hook method(:_rookout_original_fork), &block
53
+ end
54
+
55
+ def fork &block
56
+ Rookout::ForkManager.instance.fork_hook method(:_rookout_original_fork), &block
57
+ end
58
+
59
+ module Kernel
60
+ alias _rookout_original_fork fork
61
+
62
+ def self.fork &block
63
+ Rookout::ForkManager.instance.fork_hook method(:_rookout_original_fork), &block
64
+ end
65
+ end
66
+
67
+ module Process
68
+ alias _rookout_original_fork fork
69
+
70
+ def self.fork &block
71
+ Rookout::ForkManager.instance.fork_hook method(:_rookout_original_fork), &block
72
+ end
73
+ end
@@ -7,6 +7,7 @@ module Rookout
7
7
  require_relative "../processor/namespaces/container_namespace"
8
8
  require_relative "../processor/namespaces/ruby_utils_namespace"
9
9
  require_relative "../processor/namespaces/noop_namespace"
10
+ require_relative "../logger"
10
11
 
11
12
  class Aug
12
13
  def initialize aug_id, action, condition, rate_limiter, _max_aug_time
@@ -32,6 +33,7 @@ module Rookout
32
33
 
33
34
  @rate_limiter.with_limit do
34
35
  report_id = Utils.uuid
36
+ Logger.instance.info "Executing aug-\t#{id} (msg ID #{report_id})"
35
37
  @action.execute @id, report_id, namespace, output
36
38
  end
37
39
  end
@@ -39,7 +39,8 @@ module Rookout
39
39
  @info = Information.new labels
40
40
  reset_id
41
41
 
42
- @thread = nil
42
+ @main_thread = nil
43
+ @outgoing_thread = nil
43
44
  @pending_messages = Queue.new
44
45
 
45
46
  @running = false
@@ -64,8 +65,17 @@ module Rookout
64
65
  def connect
65
66
  @running = true
66
67
 
67
- @thread = Thread.new { connection_thread }
68
- @thread.name = "rookout-connection-thread"
68
+ @main_thread = Thread.new { connection_thread }
69
+ @main_thread.name = "rookout-connection-thread"
70
+ end
71
+
72
+ def stop
73
+ @running = false
74
+
75
+ # Ask outgoing thread to exit (if running)
76
+ @pending_messages << ExitMessage.new(@outgoing_thread)
77
+
78
+ @main_thread.join
69
79
  end
70
80
 
71
81
  def wait_for_ready
@@ -133,8 +143,8 @@ module Rookout
133
143
 
134
144
  def connection_pump client
135
145
  on_outgoing_exit = proc { client.close }
136
- send_thread = Thread.new { outgoing client, on_outgoing_exit }
137
- send_thread.name = "rookout-outgoing-thread"
146
+ @outgoing_thread = Thread.new { outgoing client, on_outgoing_exit }
147
+ @outgoing_thread.name = "rookout-outgoing-thread"
138
148
 
139
149
  message_handler = proc do |raw_message|
140
150
  envelope = Com::Rookout::Envelope.decode raw_message.pack("c*")
@@ -150,7 +160,8 @@ module Rookout
150
160
  Logger.instance.debug "Incoming loop - socket disconnected"
151
161
 
152
162
  @pending_messages.push ExitMessage.new(send_thread)
153
- send_thread.join
163
+ @outgoing_thread.join
164
+ @outgoing_thread = nil
154
165
  end
155
166
 
156
167
  def outgoing client, on_exit
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- COMMIT = "2a847bf58dabb4d6abd2957f4c382256a4a467db".freeze
2
+ COMMIT = "1ef929297eb0815aa058874e7a9a342c77062fdf".freeze
3
3
  end
@@ -105,7 +105,7 @@ module Rookout
105
105
  end
106
106
 
107
107
  class RookInvalidToken < ToolException
108
- def initialize token
108
+ def initialize token = ""
109
109
  super "The Rookout token supplied #{token[0..6]} is not valid; please check the token and try again",
110
110
  { token: token[0...6] }
111
111
  end
@@ -114,7 +114,7 @@ module Rookout
114
114
  class RookSourceFilePathSuggestion < ToolException
115
115
  def initialize wanted_path, matching_path
116
116
  super "Rookout found alternative file path: #{matching_path}",
117
- { wanted_path: wanted_path, matching_path: matching_path }
117
+ { "wanted_path" => wanted_path, "matching_path" => matching_path }
118
118
  end
119
119
  end
120
120
 
@@ -9,6 +9,7 @@ module Rookout
9
9
 
10
10
  def initialize
11
11
  @rook = nil
12
+ @start_options = nil
12
13
  end
13
14
 
14
15
  def start options = {}
@@ -19,14 +20,20 @@ module Rookout
19
20
  begin
20
21
  require_relative "rookout_singleton"
21
22
 
22
- configure_logging options
23
- configure_git options
23
+ # If we are running post fork, use previous start_options
24
+ if options[:post_fork]
25
+ # Don't re-enable the fork handler
26
+ @start_options[:fork] = false
27
+ else
28
+ configure_logging options
29
+ configure_git options
24
30
 
25
- start_options = configure_start_options options
26
- print_config start_options
31
+ @start_options = configure_start_options options
32
+ print_config @start_options
33
+ end
27
34
 
28
35
  rook = RookoutSingleton.instance
29
- rook.connect(**start_options)
36
+ rook.connect(**@start_options)
30
37
  rescue RookMissingToken, RookInvalidToken, RookInvalidOptions, RookVersionNotSupported => e
31
38
  raise if throw_errors
32
39
  STDERR.puts "[Rookout] Failed to start Rookout: #{e.message}"
@@ -40,9 +40,14 @@ module Rookout
40
40
  @services_started = false
41
41
  end
42
42
 
43
- def connect token: nil, host: nil, port: nil, proxy: nil, labels: [], async_start: false, **_
43
+ def connect token: nil, host: nil, port: nil, proxy: nil, labels: [], async_start: false, fork: false
44
44
  raise Exceptions::RookInterfaceException, "Multiple connection attempts not supported!" unless @agent_com.nil?
45
45
 
46
+ if fork
47
+ require_relative "atfork"
48
+ Rookout::ForkManager.instance.activate!
49
+ end
50
+
46
51
  start_trigger_services
47
52
 
48
53
  Logger.instance.debug "Initiating AgentCom-\t#{host}:#{port}"
@@ -61,6 +66,16 @@ module Rookout
61
66
  @output.flush_messages if !@output.nil && !@agent_com.nil?
62
67
  end
63
68
 
69
+ def post_fork_clean
70
+ @agent_com.stop
71
+ @agent_com = nil
72
+
73
+ @command_handler = nil
74
+
75
+ # We don't disable services because we will lose all loaded scripts
76
+ @services.clear_augs
77
+ end
78
+
64
79
  attr_reader :services
65
80
 
66
81
  private
@@ -102,13 +102,16 @@ module Rookout
102
102
  elsif suggested_match? location, filename
103
103
  warning = Exceptions::RookSourceFilePathSuggestion.new location.filename, filename
104
104
  location.notify_warning warning
105
+ # Must return nil in order to skip this script
106
+ nil
105
107
  end
106
108
  end
107
109
 
108
110
  #########################################################################################
109
111
  # Utils
110
112
  def exact_match? location_filename, script_filename
111
- script_filename.end_with? location_filename
113
+ return unless script_filename.end_with? location_filename
114
+ File.basename(script_filename) == File.basename(location_filename)
112
115
  end
113
116
 
114
117
  def suggested_match? location, filename
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.10".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rookout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liran Haimovitch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -53,33 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.5.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: google-protobuf
56
+ name: event_emitter
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0
61
+ version: 0.2.6
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0
68
+ version: 0.2.6
69
69
  - !ruby/object:Gem::Dependency
70
- name: event_emitter
70
+ name: google-protobuf
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.6
75
+ version: 3.9.2
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.6
82
+ version: 3.9.2
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: google-style
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -189,6 +189,7 @@ files:
189
189
  - LICENSE
190
190
  - bin/rookout
191
191
  - lib/rookout.rb
192
+ - lib/rookout/atfork.rb
192
193
  - lib/rookout/augs/actions/action.rb
193
194
  - lib/rookout/augs/actions/action_run_processor.rb
194
195
  - lib/rookout/augs/aug.rb