rookout 0.1.14 → 0.1.19

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: 768d976e24dea5552d46df61aae43d63ca09bc620cc5ea04f2d350ce0d1fdd26
4
- data.tar.gz: 9261c7aea1c3e1269129ddfe9941c4241e8ee6107be39e839c7e35be36156d80
3
+ metadata.gz: f0a6779a6336398a744919c44647b6d63cb1c7178c9063545f70530954750e74
4
+ data.tar.gz: 498661e2d876a90a3df2e91c63e4ecef923bffab7dc1a08c375c43708a85018a
5
5
  SHA512:
6
- metadata.gz: b3fae0189f0f86b8e61c4ed763677882760f2d155a704e08504751f0e31aac3325660bcd089fcf5d393a9e6de3627d6e767fee5c8a3962d7d7b3d6e17b38e78c
7
- data.tar.gz: 58fb6dddd9364f299d184e637ff4e28c13cad9b9f1bc098324eff01342f0d6b0a0fc35b8853553f1f6f4e8f63145e576b67cdfd2bf519509ad19ea72bab1d318
6
+ metadata.gz: bd968a36a0e0cdb97bc6032d2f2e916099b7bde3f01cbe78c99985cc352b98f784c02b50a9b6f07bb3259113dbbc1cc30b2d5a08bdf7f830e3486904b00f7315
7
+ data.tar.gz: b0a1d91c5461c758363e4e5d2a28f25f41d81592b549e8374b08580a99c0ee7c6485c66ef71644cf19aff6cfc30244ba9de55a51b3cbc9b3c3eb84a46cb4f627
@@ -100,10 +100,11 @@ module Rookout
100
100
 
101
101
  while @running
102
102
  begin
103
- backoff.before_connection_attempt
104
103
  client = open_new_connection
105
104
 
106
105
  Logger.instance.debug "WebSocket connected successfully"
106
+ Logger.instance.info "Finished initialization"
107
+
107
108
  @token_valid = true
108
109
  backoff.after_connect
109
110
 
@@ -4,25 +4,20 @@ module Rookout
4
4
 
5
5
  class Backoff
6
6
  def initialize
7
- @connected = false
8
- @last_successful_connection = Time.mktime 1970
9
- reset_backoff
10
- end
11
-
12
- def before_connection_attempt
13
- return unless Time.new > @last_successful_connection + Config.backoff_reset_time
7
+ @connect_time = nil
14
8
  reset_backoff
15
9
  end
16
10
 
17
11
  def after_disconnect
18
- @connected = false
12
+ reset_backoff if @connect_time && Time.new > @connect_time + Config.backoff_reset_time
13
+ @connect_time = nil
14
+
19
15
  sleep @next_backoff
20
16
  @next_backoff = [@next_backoff * 2, Config.backoff_max_time].min
21
17
  end
22
18
 
23
19
  def after_connect
24
- @connected = true
25
- @last_successful_connection = Time.now
20
+ @connect_time = Time.now
26
21
  end
27
22
 
28
23
  private
@@ -17,9 +17,14 @@ module Rookout
17
17
  if Time.now - @last_ping > @interval
18
18
  Logger.instance.debug "Sending Ping"
19
19
  @last_ping = Time.now
20
- @connection.ping Time.now.to_s do
21
- Logger.instance.debug "Got Ping reply"
22
- @last_pong = Time.now
20
+ begin
21
+ @connection.ping Time.now.to_s do
22
+ Logger.instance.debug "Got Ping reply"
23
+ @last_pong = Time.now
24
+ end
25
+ rescue RuntimeError
26
+ Logger.instance.debug "Failed to send ping"
27
+ break
23
28
  end
24
29
  end
25
30
 
@@ -2,6 +2,7 @@ module Rookout
2
2
  module ComWs
3
3
  require "openssl"
4
4
  require "websocket/driver"
5
+ require "uri"
5
6
 
6
7
  require_relative "../config"
7
8
  require_relative "../logger"
@@ -11,14 +12,12 @@ module Rookout
11
12
  def initialize url, proxy, token
12
13
  @token = token
13
14
  @connection = WebsocketConnection.new url, proxy
15
+ @proxy = proxy
14
16
  @driver = nil
15
- @error = nil
16
- @last_ping = nil
17
17
  end
18
18
 
19
19
  def connect
20
- # TODO: add proxy support
21
- @connection.connect
20
+ connection_error = nil
22
21
  @driver = WebSocket::Driver.client @connection
23
22
 
24
23
  headers.each do |key, value|
@@ -26,18 +25,20 @@ module Rookout
26
25
  end
27
26
 
28
27
  @driver.on :error do |error|
29
- @error = error
28
+ connection_error = error
30
29
  end
31
30
 
32
31
  # Connect to the remote server
33
- @driver.start
34
32
  # TODO: ADD CONNECT TIMEOUT
33
+ @connection.connect @driver
34
+ @driver.start
35
+
35
36
  while @driver.state == :connecting
36
37
  recv_data = @connection.read_char
37
38
  @driver.parse recv_data
38
39
  end
39
40
 
40
- raise Exceptions::RookWebsocketException, @error if @driver.state != :open
41
+ raise Exceptions::RookWebsocketException, connection_error if @driver.state != :open
41
42
  end
42
43
 
43
44
  def connection_pump message_handler
@@ -62,7 +63,12 @@ module Rookout
62
63
  def close
63
64
  return if @driver.nil?
64
65
 
65
- @driver.close
66
+ begin
67
+ @driver.close
68
+ rescue RuntimeError
69
+ # Protocol close may fail if the connection is already closed
70
+ nil
71
+ end
66
72
  @connection.close
67
73
  end
68
74
 
@@ -88,14 +94,36 @@ module Rookout
88
94
  @secure = %w[https wss].include? @uri.scheme
89
95
 
90
96
  @socket = nil
97
+
98
+ @proxy_connected = false
91
99
  end
92
100
 
93
- def connect
94
- if @secure
95
- @socket = ssl_connect
96
- else
97
- @socket = tcp_connect
101
+ def connect driver
102
+ @socket = tcp_connect
103
+
104
+ proxy_connect driver if @proxy
105
+
106
+ @socket = ssl_connect @socket if @secure
107
+ end
108
+
109
+ def proxy_connect driver
110
+ connection_error = nil
111
+ @proxy_connected = false
112
+ proxy = driver.proxy @proxy
113
+
114
+ proxy.on :connect do
115
+ @proxy_connected = true
98
116
  end
117
+
118
+ proxy.on :error do |error|
119
+ connection_error = error
120
+ end
121
+
122
+ proxy.start
123
+
124
+ proxy.parse read_char until @proxy_connected == true || !connection_error.nil?
125
+
126
+ raise Exceptions::RookProxyException, connection_error unless connection_error.nil?
99
127
  end
100
128
 
101
129
  attr_reader :url
@@ -118,13 +146,16 @@ module Rookout
118
146
  private
119
147
 
120
148
  def tcp_connect
121
- TCPSocket.new @uri.host,
122
- @uri.port || (@secure ? 443 : 80)
149
+ if @proxy
150
+ uri = URI(@proxy)
151
+ TCPSocket.new uri.host, uri.port
152
+ else
153
+ TCPSocket.new @uri.host,
154
+ @uri.port || (@secure ? 443 : 80)
155
+ end
123
156
  end
124
157
 
125
- def ssl_connect
126
- tcp_socket = tcp_connect
127
-
158
+ def ssl_connect tcp_socket
128
159
  ctx = ::OpenSSL::SSL::SSLContext.new
129
160
  ctx.min_version = ::OpenSSL::SSL::TLS1_2_VERSION
130
161
  cert_store = ::OpenSSL::X509::Store.new
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- COMMIT = "982cb7ee1b842b306f30a9b5bdcf5a5410528499".freeze
2
+ COMMIT = "d73fb2179498d7e9dd75c474b5b5aeee97db687b".freeze
3
3
  end
@@ -144,6 +144,12 @@ module Rookout
144
144
  end
145
145
  end
146
146
 
147
+ class RookInvalidLabel < ToolException
148
+ def initialize label_name
149
+ super "Invalid label: must not start with the '$' character (#{label_name})"
150
+ end
151
+ end
152
+
147
153
  class RookCrcMismatchException < ToolException
148
154
  def initialize filepath, expected, calculated
149
155
  super "Line CRC32s do not match! path: #{filepath}, expected: #{expected}, calculated:#{calculated}",
@@ -178,10 +184,22 @@ module Rookout
178
184
  end
179
185
  end
180
186
 
187
+ class RookProxyException < ToolException
188
+ def initialize error
189
+ super "Error from proxy #{error}", { "error" => error }
190
+ end
191
+ end
192
+
181
193
  class RookBadProtobuf < ToolException
182
194
  def initialize
183
195
  super 'Bad protobuf version. Please execute "bundle config force_ruby_platform true" before "bundler install".'
184
196
  end
185
197
  end
198
+
199
+ class RookBadProtobufPlatform < ToolException
200
+ def initialize platform
201
+ super "Bad protobuf platform: #{platform}"
202
+ end
203
+ end
186
204
  end
187
205
  end
@@ -12,29 +12,31 @@ module Rookout
12
12
  @start_options = nil
13
13
  end
14
14
 
15
+ def print_debug_messages
16
+ puts "[Rookout] Running in debug mode"
17
+ puts "[Rookout] Rookout SDK for ruby: " + Config.rookout_version
18
+ end
19
+
15
20
  def start options = {}
16
21
  return unless @rook.nil?
17
22
  throw_errors = options[:throw_errors] == true
18
23
  Config.debug = evaluate_flag options[:debug], "ROOKOUT_DEBUG"
19
24
 
25
+ print_debug_messages if Config.debug
26
+
20
27
  begin
21
28
  verify_env
22
29
 
23
30
  require_relative "rookout_singleton"
24
31
 
25
- # If we are running post fork, use previous start_options
26
- if options[:post_fork]
27
- # Don't re-enable the fork handler
28
- @start_options[:fork] = false
29
- else
30
- configure_globals options
31
-
32
- @start_options = configure_start_options options
33
- print_config @start_options
34
- end
32
+ configure options
35
33
 
36
34
  rook = RookoutSingleton.instance
37
35
  rook.connect(**@start_options)
36
+ rescue LoadError
37
+ raise if throw_errors
38
+ STDERR.puts "[Rookout] Failed to load Rookout. Please make sure to force build native extensions by setting" \
39
+ "'bundle config force_ruby_platform true'"
38
40
  rescue RookMissingToken, RookInvalidToken, RookInvalidOptions, RookVersionNotSupported, RookBadProtobuf => e
39
41
  raise if throw_errors
40
42
  STDERR.puts "[Rookout] Failed to start Rookout: #{e.message}"
@@ -62,12 +64,29 @@ module Rookout
62
64
 
63
65
  TRUE_VALUE = [true, "y", "Y", "yes", "Yes", "YES", "true", "True", "TRUE", "1"].freeze
64
66
 
67
+ def configure options
68
+ # If we are running post fork, use previous start_options
69
+ if options[:post_fork]
70
+ # Don't re-enable the fork handler
71
+ @start_options[:fork] = false
72
+ else
73
+ configure_globals options
74
+
75
+ @start_options = configure_start_options options
76
+ print_config @start_options
77
+ end
78
+ end
79
+
65
80
  def verify_env
66
81
  # Only test alpine
67
82
  return unless File.exist? "/etc/alpine-release"
68
83
 
69
84
  protobuf = Gem::Specification.find_by_path "google/protobuf"
70
- raise RookBadProtobuf if protobuf.nil? || protobuf.platform != "ruby"
85
+ STDERR.puts RookBadProtobuf.new.message if protobuf.nil?
86
+ return unless protobuf.platform != "ruby"
87
+
88
+ error = RookBadProtobufPlatform.new protobuf.platform
89
+ STDERR.puts error.message
71
90
  end
72
91
 
73
92
  def configure_globals options
@@ -95,7 +114,7 @@ module Rookout
95
114
  proxy = evaluate_config options[:proxy], "ROOKOUT_PROXY"
96
115
  token = evaluate_config options[:token], "ROOKOUT_TOKEN"
97
116
 
98
- raise RookMissingToken if token.nil? && host == "wss://control.rookout.com"
117
+ raise RookMissingToken if token.nil? && !(host_specified options)
99
118
  verify_token token if token
100
119
 
101
120
  labels = stringify_labels(options[:labels]) || parse_labels(ENV["ROOKOUT_LABELS"])
@@ -107,6 +126,10 @@ module Rookout
107
126
  { host: host, port: port, proxy: proxy, token: token, labels: labels, async_start: async_start, fork: fork }
108
127
  end
109
128
 
129
+ def host_specified options
130
+ !options[:host].nil? || !ENV["ROOKOUT_CONTROLLER_HOST"].nil? || !ENV["ROOKOUT_AGENT_HOST"].nil?
131
+ end
132
+
110
133
  def evaluate_flag argument, env_var_name
111
134
  return true? argument unless argument.nil?
112
135
  true? ENV[env_var_name]
@@ -12,7 +12,8 @@ module Rookout
12
12
 
13
13
  def initialize
14
14
  # Detect unit tests
15
- if ($PROGRAM_NAME.end_with?("minitest_runner.rb") ||
15
+ if (Config.debug ||
16
+ $PROGRAM_NAME.end_with?("minitest_runner.rb") ||
16
17
  $PROGRAM_NAME.end_with?("tunit_or_minitest_in_folder_runner.rb")) &&
17
18
  Dir.pwd.end_with?("ruby-sdk")
18
19
  Config.logger_log_level = :DEBUG
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- VERSION = "0.1.14".freeze
2
+ VERSION = "0.1.19".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.14
4
+ version: 0.1.19
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-28 00:00:00.000000000 Z
11
+ date: 2021-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -268,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
268
  - !ruby/object:Gem::Version
269
269
  version: '0'
270
270
  requirements: []
271
- rubygems_version: 3.1.2
271
+ rubygems_version: 3.1.4
272
272
  signing_key:
273
273
  specification_version: 4
274
274
  summary: rookout is the Ruby SDK for the Rookout Debugging Platform