rookout 0.1.12 → 0.1.17

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: 9c698c16bfbf7520a5f3fef8f0cda0f3140ba6be1f875e04223053b63ca421dc
4
- data.tar.gz: 27a0f9fa6cd4f47749b48c552a8dd6a42c1eff4e359458417df725c618fd7864
3
+ metadata.gz: 412df2821122abb540f4baeed9fd11432ebdc2a50373130ba148c43863c62b9b
4
+ data.tar.gz: afe3d60125a31190bc17dcf2b27a5fa18cf7da70acde921cc959438a8a285dfc
5
5
  SHA512:
6
- metadata.gz: 0756d328dbdd0249b3cb24f109283f28687d7f414b8c81d219a974973df1e768fa7481940c0246dd044ebb11e0af44e314d199b48530f8928f6a718518cc165b
7
- data.tar.gz: e9e2b8468f70300e029391fdbd19e3da9b75a25f2fcad02f6f41f1327ca781c37bd7e0d76bf26b9137f0cfb702c841c6bc29ee167e6824499b08a0736b4cddfe
6
+ metadata.gz: 4a576e0968b7fdc91b80e4ef7b6b465d046cb44ad5eac73e6817898c422796dedc0a33fc4749480966814029143c83984c26edfecad18b508aaf9da03455205e
7
+ data.tar.gz: 608e9960132a87e86fd1ab9fa6bc045d493b7f95dece96fa5dd8bcbceedc2ea538b4a30a28702ec4e7c8f7951005b9826755b48a4d3171f3a77345ac643b24ea
@@ -51,11 +51,11 @@ module Rookout
51
51
  def add message
52
52
  buffer = wrap_in_envelope message
53
53
  if buffer.length > Config.agent_com_max_message_limit
54
- exc = Exceptions::RookMessageSizeExceeded.new buffer.length, Coonfig.agent_com_max_message_limit
55
- warning = RookError.new exc, message
54
+ exc = Exceptions::RookMessageSizeExceeded.new buffer.length, Config.agent_com_max_message_limit
55
+ warning = Processor::RookError.new exc
56
56
  UserWarnings.notify_warning warning
57
57
 
58
- Logger.instance.warn "Dropping message, size was #{buffer.length} which is over the message size limit"
58
+ Logger.instance.warning "Dropping message, size was #{buffer.length} which is over the message size limit"
59
59
  return
60
60
  end
61
61
 
@@ -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
@@ -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,13 @@ 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
17
  @last_ping = nil
17
18
  end
18
19
 
19
20
  def connect
20
- # TODO: add proxy support
21
- @connection.connect
21
+ connection_error = nil
22
22
  @driver = WebSocket::Driver.client @connection
23
23
 
24
24
  headers.each do |key, value|
@@ -26,18 +26,20 @@ module Rookout
26
26
  end
27
27
 
28
28
  @driver.on :error do |error|
29
- @error = error
29
+ connection_error = error
30
30
  end
31
31
 
32
32
  # Connect to the remote server
33
- @driver.start
34
33
  # TODO: ADD CONNECT TIMEOUT
34
+ @connection.connect @driver
35
+ @driver.start
36
+
35
37
  while @driver.state == :connecting
36
38
  recv_data = @connection.read_char
37
39
  @driver.parse recv_data
38
40
  end
39
41
 
40
- raise Exceptions::RookWebsocketException, @error if @driver.state != :open
42
+ raise Exceptions::RookWebsocketException, connection_error if @driver.state != :open
41
43
  end
42
44
 
43
45
  def connection_pump message_handler
@@ -88,14 +90,36 @@ module Rookout
88
90
  @secure = %w[https wss].include? @uri.scheme
89
91
 
90
92
  @socket = nil
93
+
94
+ @proxy_connected = false
91
95
  end
92
96
 
93
- def connect
94
- if @secure
95
- @socket = ssl_connect
96
- else
97
- @socket = tcp_connect
97
+ def connect driver
98
+ @socket = tcp_connect
99
+
100
+ proxy_connect driver if @proxy
101
+
102
+ @socket = ssl_connect @socket if @secure
103
+ end
104
+
105
+ def proxy_connect driver
106
+ connection_error = nil
107
+ @proxy_connected = false
108
+ proxy = driver.proxy @proxy
109
+
110
+ proxy.on :connect do
111
+ @proxy_connected = true
98
112
  end
113
+
114
+ proxy.on :error do |error|
115
+ connection_error = error
116
+ end
117
+
118
+ proxy.start
119
+
120
+ proxy.parse read_char until @proxy_connected == true || !connection_error.nil?
121
+
122
+ raise Exceptions::RookProxyException, connection_error unless connection_error.nil?
99
123
  end
100
124
 
101
125
  attr_reader :url
@@ -118,13 +142,16 @@ module Rookout
118
142
  private
119
143
 
120
144
  def tcp_connect
121
- TCPSocket.new @uri.host,
122
- @uri.port || (@secure ? 443 : 80)
145
+ if @proxy
146
+ uri = URI(@proxy)
147
+ TCPSocket.new uri.host, uri.port
148
+ else
149
+ TCPSocket.new @uri.host,
150
+ @uri.port || (@secure ? 443 : 80)
151
+ end
123
152
  end
124
153
 
125
- def ssl_connect
126
- tcp_socket = tcp_connect
127
-
154
+ def ssl_connect tcp_socket
128
155
  ctx = ::OpenSSL::SSL::SSLContext.new
129
156
  ctx.min_version = ::OpenSSL::SSL::TLS1_2_VERSION
130
157
  cert_store = ::OpenSSL::X509::Store.new
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- COMMIT = "0f0cf1533a7338ef3e5ca1416415ff3b54dffe98".freeze
2
+ COMMIT = "c966c378ce29011cd64cc0cd52ca6f4acbed2025".freeze
3
3
  end
@@ -94,7 +94,7 @@ module Rookout
94
94
  super "Message size of #{message_size} exceeds max size limit of #{max_message_size}. " \
95
95
  "Change the depth of collection or change the default by setting ROOKOUT_MAX_MESSAGE_SIZE " \
96
96
  "as environment variable or system property",
97
- { message_size: message_size, max_message_size: max_message_size }
97
+ { "message_size" => message_size, "max_message_size" => max_message_size }
98
98
  end
99
99
  end
100
100
 
@@ -177,5 +177,23 @@ module Rookout
177
177
  super "Error from Websocket #{error}", { "error" => error }
178
178
  end
179
179
  end
180
+
181
+ class RookProxyException < ToolException
182
+ def initialize error
183
+ super "Error from proxy #{error}", { "error" => error }
184
+ end
185
+ end
186
+
187
+ class RookBadProtobuf < ToolException
188
+ def initialize
189
+ super 'Bad protobuf version. Please execute "bundle config force_ruby_platform true" before "bundler install".'
190
+ end
191
+ end
192
+
193
+ class RookBadProtobufPlatform < ToolException
194
+ def initialize platform
195
+ super "Bad protobuf platform: #{platform}"
196
+ end
197
+ end
180
198
  end
181
199
  end
@@ -17,24 +17,22 @@ module Rookout
17
17
  throw_errors = options[:throw_errors] == true
18
18
  Config.debug = evaluate_flag options[:debug], "ROOKOUT_DEBUG"
19
19
 
20
+ puts "[Rookout] Running in debug mode" if Config.debug
21
+
20
22
  begin
23
+ verify_env
24
+
21
25
  require_relative "rookout_singleton"
22
26
 
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
30
-
31
- @start_options = configure_start_options options
32
- print_config @start_options
33
- end
27
+ configure options
34
28
 
35
29
  rook = RookoutSingleton.instance
36
30
  rook.connect(**@start_options)
37
- rescue RookMissingToken, RookInvalidToken, RookInvalidOptions, RookVersionNotSupported => e
31
+ rescue LoadError
32
+ raise if throw_errors
33
+ STDERR.puts "[Rookout] Failed to load Rookout. Please make sure to force build native extensions by setting" \
34
+ "'bundle config force_ruby_platform true'"
35
+ rescue RookMissingToken, RookInvalidToken, RookInvalidOptions, RookVersionNotSupported, RookBadProtobuf => e
38
36
  raise if throw_errors
39
37
  STDERR.puts "[Rookout] Failed to start Rookout: #{e.message}"
40
38
  rescue RookCommunicationException => e
@@ -61,7 +59,32 @@ module Rookout
61
59
 
62
60
  TRUE_VALUE = [true, "y", "Y", "yes", "Yes", "YES", "true", "True", "TRUE", "1"].freeze
63
61
 
64
- def configure_logging options
62
+ def configure options
63
+ # If we are running post fork, use previous start_options
64
+ if options[:post_fork]
65
+ # Don't re-enable the fork handler
66
+ @start_options[:fork] = false
67
+ else
68
+ configure_globals options
69
+
70
+ @start_options = configure_start_options options
71
+ print_config @start_options
72
+ end
73
+ end
74
+
75
+ def verify_env
76
+ # Only test alpine
77
+ return unless File.exist? "/etc/alpine-release"
78
+
79
+ protobuf = Gem::Specification.find_by_path "google/protobuf"
80
+ STDERR.puts RookBadProtobuf.new.message if protobuf.nil?
81
+ return unless protobuf.platform != "ruby"
82
+
83
+ error = RookBadProtobufPlatform.new protobuf.platform
84
+ STDERR.puts error.message
85
+ end
86
+
87
+ def configure_globals options
65
88
  if Config.debug
66
89
  log_to_stderr = true
67
90
  log_level = :DEBUG
@@ -75,9 +98,7 @@ module Rookout
75
98
  Config.logger_log_to_stderr = log_to_stderr unless log_to_stderr.nil?
76
99
  Config.logger_filename = log_file unless log_file.nil?
77
100
  Config.logger_log_level = log_level unless log_level.nil?
78
- end
79
101
 
80
- def configure_git options
81
102
  Config.user_git_origin = options[:git_origin] if options[:git_origin]
82
103
  Config.user_git_commit = options[:git_commit] if options[:git_commit]
83
104
  end
@@ -88,7 +109,7 @@ module Rookout
88
109
  proxy = evaluate_config options[:proxy], "ROOKOUT_PROXY"
89
110
  token = evaluate_config options[:token], "ROOKOUT_TOKEN"
90
111
 
91
- raise RookMissingToken if token.nil? && host == "wss://control.rookout.com"
112
+ raise RookMissingToken if token.nil? && !(host_specified options)
92
113
  verify_token token if token
93
114
 
94
115
  labels = stringify_labels(options[:labels]) || parse_labels(ENV["ROOKOUT_LABELS"])
@@ -100,6 +121,10 @@ module Rookout
100
121
  { host: host, port: port, proxy: proxy, token: token, labels: labels, async_start: async_start, fork: fork }
101
122
  end
102
123
 
124
+ def host_specified options
125
+ !options[:host].nil? || !ENV["ROOKOUT_CONTROLLER_HOST"].nil? || !ENV["ROOKOUT_AGENT_HOST"].nil?
126
+ end
127
+
103
128
  def evaluate_flag argument, env_var_name
104
129
  return true? argument unless argument.nil?
105
130
  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
@@ -12,15 +12,15 @@ module Rookout
12
12
  end
13
13
 
14
14
  def call_method _name, _args
15
- RubyObjectNamespace nil
15
+ Rookout::Processor::Namespaces::RubyObjectNamespace.new nil
16
16
  end
17
17
 
18
18
  def read_attribute _name
19
- RubyObjectNamespace nil
19
+ Rookout::Processor::Namespaces::RubyObjectNamespace.new nil
20
20
  end
21
21
 
22
22
  def read_key _key
23
- RubyObjectNamespace nil
23
+ Rookout::Processor::Namespaces::RubyObjectNamespace.new nil
24
24
  end
25
25
 
26
26
  def dump _log_object_errors
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- VERSION = "0.1.12".freeze
2
+ VERSION = "0.1.17".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.12
4
+ version: 0.1.17
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-22 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller