rookout 0.1.41 → 0.1.43

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: 07a2d9fa41fdf140e81f22c1a46f47bbaf5412b31d1ab62c1f59460c07113c03
4
- data.tar.gz: 9dd40c49cc6b8417aa3424cedd26aad1b8e63813fe0e2fcc063749d03c20f602
3
+ metadata.gz: 451da8de695dcbffddf0e548b213741155298be1877e390c7cbcb776a21744e6
4
+ data.tar.gz: 5d006c7a1e89e0ab1d6e407c4afa4e1410f50f2770e92c1cdc083498cee54af0
5
5
  SHA512:
6
- metadata.gz: 7204403b2efd52cce60b533b396c93ffc963b60554d3fbf4fbc414f4a2d6a80c0ced39e7d6c6cceda6d2470ee46563cc8704871b058957599f8b6f7ad1d433ff
7
- data.tar.gz: 2a05c92e5f984035bcbe84e5e4f2f25be8b2458032272c03fd4e94f8e94252bcaf8c11d7989c294e5a7d07773e95170bb7f479c3806945636869b2b7b491349d
6
+ metadata.gz: 743f3550703c0cfaa55527a185f014c31129761addff6584dbd01dc63d8bd0bc245188ce6cb51812de8ebb1c0d8ac1b6df9460c6a9f9c47b342ef5519cba1137
7
+ data.tar.gz: bb0dbcbb2ee6bbc8fa0b0d957e197021fb156e8a49fd2f8bd365072f665f23d7b7d6eb06bf490ccd880602f02dd43a226496d0e25dbb67e4c90932121a7d2f01
@@ -27,7 +27,7 @@ module Rookout
27
27
  return unless @enabled
28
28
 
29
29
  if output.user_messages_queue_full?
30
- Logger.instance.warning "Skipping aug-\t#{id} execution because the queue is full"
30
+ output.send_output_queue_full_warning @id
31
31
  return
32
32
  end
33
33
 
@@ -67,8 +67,10 @@ module Rookout
67
67
  def create_limits_manager configuration
68
68
  limiters = []
69
69
  if global_rate_limiter.nil?
70
- rate_limit = parse_rate_limit configuration["rateLimit"], configuration["rateLimitModifier"], 200, 5000
71
- limiters.append AugRateLimiter.new(*rate_limit)
70
+ rate_limit = parse_rate_limit configuration["rateLimit"], configuration["rateLimitModifier"], 200, 5000, 1
71
+ unless rate_limit.nil?
72
+ limiters.append AugRateLimiter.new(*rate_limit)
73
+ end
72
74
  else
73
75
  limiters.append global_rate_limiter
74
76
  end
@@ -78,7 +80,19 @@ module Rookout
78
80
 
79
81
  def global_rate_limiter
80
82
  if @global_rate_limiter.nil? && Rookout::Config.global_rate_limit != ""
81
- rate_limit = parse_rate_limit Rookout::Config.global_rate_limit, "0", 0, 0
83
+ begin
84
+ rate_limit = parse_rate_limit Rookout::Config.global_rate_limit,
85
+ "0", 0, 0, Rookout::Config.global_rate_limit_multiplier
86
+ if rate_limit.nil?
87
+ raise Exceptions::RookInvalidRateLimitConfiguration, Rookout::Config.global_rate_limit
88
+ end
89
+ rescue Exceptions::RookInvalidRateLimitConfiguration => e
90
+ Logger.instance.warning "Failed to create global rate limiter: #{e.message}"
91
+ err = Processor::RookError.new e
92
+ UserWarnings.notify_error err
93
+ return nil
94
+ end
95
+
82
96
  @global_rate_limiter = AugRateLimiter.new(*rate_limit)
83
97
  Logger.instance.debug "Using global rate limiter with configuration: #{rate_limit}"
84
98
  Rookout::Config.using_global_rate_limiter = true
@@ -87,13 +101,15 @@ module Rookout
87
101
  @global_rate_limiter
88
102
  end
89
103
 
90
- def parse_rate_limit config, modifier_config, default_quota, default_window
104
+ def parse_rate_limit config, modifier_config, default_quota, default_window, multiplier
91
105
  window_quota = default_quota
92
106
  window_size = default_window
93
107
 
94
108
  unless config.nil? || config.empty?
95
109
  rate_limit_split = config.split "/"
96
- unless rate_limit_split.length == 2 && rate_limit_split[0].is_number? && rate_limit_split[1].is_number?
110
+ unless rate_limit_split.length == 2 && \
111
+ Utils.is_number?(rate_limit_split[0]) && \
112
+ Utils.is_number?(rate_limit_split[1])
97
113
  raise Exceptions::RookInvalidRateLimitConfiguration, config
98
114
  end
99
115
 
@@ -105,7 +121,15 @@ module Rookout
105
121
  window_size_ns = Utils.milliseconds_to_nanoseconds window_size
106
122
  rate_limit_modifier = modifier_config.to_i || 5
107
123
 
108
- [window_quota_ns, window_size_ns, rate_limit_modifier]
124
+ if window_quota_ns == 0
125
+ return nil
126
+ end
127
+
128
+ if window_quota_ns >= window_size_ns
129
+ raise Exceptions::RookInvalidRateLimitConfiguration, config
130
+ end
131
+
132
+ [window_quota_ns * multiplier, window_size_ns, rate_limit_modifier]
109
133
  end
110
134
  end
111
135
  end
@@ -26,8 +26,12 @@ module Rookout
26
26
  attr_reader :pending_messages
27
27
 
28
28
  def initialize output, agent_host, agent_port, proxy, token, labels, print_on_connect
29
- agent_host_with_protocl = agent_host.include?("://") ? agent_host : "ws://#{agent_host}"
30
- @uri = "#{agent_host_with_protocl}:#{agent_port}/v1"
29
+ if agent_host.nil? || agent_host.empty?
30
+ @uri = ""
31
+ else
32
+ agent_host_with_protocl = agent_host.include?("://") ? agent_host : "ws://#{agent_host}"
33
+ @uri = "#{agent_host_with_protocl}:#{agent_port}/v1"
34
+ end
31
35
  if proxy.nil? || proxy.empty?
32
36
  @proxy = nil
33
37
  else
@@ -57,14 +61,7 @@ module Rookout
57
61
  msg_size = envelope_wrapper.calculate_size
58
62
  if @pending_messages_length + msg_size > Config.agent_com_max_queue_messages_length ||
59
63
  queue_full?
60
- exc = Exceptions::RookMessageSizeExceeded.new msg_size, Config.agent_com_max_queue_messages_length
61
- warning = Processor::RookError.new exc
62
- UserWarnings.notify_warning warning
63
-
64
- Logger.instance.warning "Dropping message, size was #{msg_size}, pedning messages: #{@pending_messages_length}
65
- which is over the message size limit #{Config.agent_com_max_queue_messages_length},
66
- queue length: #{@pending_messages.length}"
67
- return
64
+ raise Exceptions::RookOutputQueueFull
68
65
  end
69
66
 
70
67
  @pending_messages.push envelope_wrapper
@@ -108,7 +105,6 @@ module Rookout
108
105
 
109
106
  private
110
107
 
111
- # rubocop:disable Style/StderrPuts
112
108
  def connection_thread
113
109
  backoff = Backoff.new
114
110
 
@@ -118,7 +114,8 @@ module Rookout
118
114
 
119
115
  if @print_on_initial_connection
120
116
  @print_on_initial_connection = false
121
- $stderr.puts "[Rookout] Successfully connected to controller"
117
+ Utils.quiet_puts "[Rookout] Successfully connected to controller"
118
+ Utils.quiet_puts "[Rookout] Rook's ID is #{@agent_id}"
122
119
  end
123
120
  Logger.instance.debug "WebSocket connected successfully"
124
121
  Logger.instance.info "Finished initialization"
@@ -142,13 +139,11 @@ module Rookout
142
139
  rescue Exception => e
143
140
  Logger.instance.error "Unexpected error in connection_thread", e
144
141
  end
145
- # rubocop:enable Style/StderrPuts
146
142
 
147
143
  def open_new_connection
148
144
  client = WebsocketClient.new @uri, @proxy, @token
149
145
  client.connect
150
146
 
151
- Logger.instance.info "Registering agent with id #{@agent_id}"
152
147
  msg = Com::Rookout::NewAgentMessage.new agent_info: @info.pack
153
148
  client.send_frame wrap_in_envelope(msg)
154
149
 
@@ -11,11 +11,15 @@ module Rookout
11
11
  require_relative "token_bucket"
12
12
  require_relative "envelope_wrapper"
13
13
 
14
+ require "concurrent"
15
+
14
16
  class Output
15
17
  def initialize
16
18
  @agent_id = nil
17
19
  @agent_com = nil
18
20
 
21
+ @skipped_aug_ids = Concurrent::Set.new
22
+
19
23
  @rule_status_update_bucket = TokenBucket.new Config.output_max_status_updates,
20
24
  Config.output_bucket_refresh_rate do
21
25
  Logger.instance.error "Limit reached, dropping status updates"
@@ -55,6 +59,17 @@ module Rookout
55
59
  @user_message_bucket.exhausted? || (!@agent_com.nil? && @agent_com.queue_full?)
56
60
  end
57
61
 
62
+ def send_output_queue_full_warning aug_id
63
+ if @skipped_aug_ids.include? aug_id
64
+ return
65
+ end
66
+
67
+ @skipped_aug_ids.add aug_id
68
+ error = Processor::RookError.new Exceptions::RookOutputQueueFull.new
69
+ send_rule_status aug_id, :Warning, error
70
+ Logger.instance.warning "Skipping aug-\t#{aug_id} execution because the queue is full"
71
+ end
72
+
58
73
  def send_warning rule_id, error
59
74
  send_rule_status rule_id, :Warning, error
60
75
  end
@@ -63,6 +78,10 @@ module Rookout
63
78
  return if @closing || !@agent_com
64
79
 
65
80
  @rule_status_update_bucket.if_available do
81
+ if active == "Deleted"
82
+ @skipped_aug_ids.delete? rule_id
83
+ end
84
+
66
85
  status = Com::Rookout::RuleStatusMessage.new agent_id: @agent_id,
67
86
  rule_id: rule_id,
68
87
  active: active
@@ -73,7 +92,11 @@ module Rookout
73
92
 
74
93
  envelope_wrapper = EnvelopeWrapper.new status
75
94
 
76
- @agent_com.add envelope_wrapper
95
+ begin
96
+ @agent_com.add envelope_wrapper
97
+ rescue Exceptions::RookOutputQueueFull
98
+ # Ignored
99
+ end
77
100
  end
78
101
  end
79
102
 
@@ -100,7 +123,12 @@ module Rookout
100
123
  )
101
124
  end
102
125
 
103
- @agent_com.add envelope_wrapper
126
+ begin
127
+ @agent_com.add envelope_wrapper
128
+ @skipped_aug_ids.delete? aug_id
129
+ rescue Exceptions::RookOutputQueueFull
130
+ send_output_queue_full_warning aug_id
131
+ end
104
132
  end
105
133
  end
106
134
 
@@ -144,7 +172,11 @@ module Rookout
144
172
 
145
173
  envelope_wrapper = EnvelopeWrapper.new msg
146
174
 
147
- @agent_com.add envelope_wrapper
175
+ begin
176
+ @agent_com.add envelope_wrapper
177
+ rescue Exceptions::RookOutputQueueFull
178
+ # Ignored
179
+ end
148
180
  end
149
181
  end
150
182
  end
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- COMMIT = "ed682099e24a661d30178506cb58f2a25d4af877".freeze
2
+ COMMIT = "5444c2c813f2ee703b7bbcd51f5591ace3e1150f".freeze
3
3
  end
@@ -6,8 +6,10 @@ module Rookout
6
6
  # Magic to allow for module variables to be easily accessible
7
7
  class << self
8
8
  attr_accessor :debug
9
+ attr_accessor :quiet
9
10
 
10
11
  Rookout::Config.debug = false
12
+ Rookout::Config.quiet = false
11
13
 
12
14
  attr_accessor :logger_filename
13
15
  attr_accessor :logger_log_to_stderr
@@ -76,10 +78,16 @@ module Rookout
76
78
 
77
79
  Rookout::Config.true_values = ["y", "Y", "yes", "Yes", "YES", "true", "True", "TRUE", "1"]
78
80
 
81
+ attr_accessor :global_rate_limit_quota
82
+ attr_accessor :global_rate_limit_window_size
79
83
  attr_accessor :global_rate_limit
84
+ attr_accessor :global_rate_limit_multiplier
80
85
  attr_accessor :using_global_rate_limiter
81
86
 
87
+ Rookout::Config.global_rate_limit_quota = ""
88
+ Rookout::Config.global_rate_limit_window_size = ""
82
89
  Rookout::Config.global_rate_limit = ""
90
+ Rookout::Config.global_rate_limit_multiplier = 1
83
91
  Rookout::Config.using_global_rate_limiter = false
84
92
 
85
93
  def update_config configuration
@@ -103,7 +111,12 @@ module Rookout
103
111
  def update_global_rate_limit_config configuration
104
112
  global_rate_limit = ENV["ROOKOUT_GLOBAL_RATE_LIMIT"]
105
113
  if global_rate_limit.nil?
106
- global_rate_limit = configuration["RUBY_GLOBAL_RATE_LIMIT"]
114
+ quota = configuration["RUBY_GLOBAL_RATE_LIMIT_QUOTA_MS"]
115
+ window_size = configuration["RUBY_GLOBAL_RATE_LIMIT_WINDOW_SIZE_MS"]
116
+
117
+ if quota != "" && !quota.nil? && window_size != "" && !window_size.nil?
118
+ global_rate_limit = "#{quota}/#{window_size}"
119
+ end
107
120
  end
108
121
 
109
122
  return if global_rate_limit.nil? || global_rate_limit == ""
@@ -95,6 +95,13 @@ module Rookout
95
95
  end
96
96
  end
97
97
 
98
+ class RookOutputQueueFull < ToolException
99
+ def initialize
100
+ super "Breakpoint triggered but output queue is full. " \
101
+ "Data collection will be disabled until the queue has emptied."
102
+ end
103
+ end
104
+
98
105
  class RookRuleAugRateLimited < ToolException
99
106
  def initialize
100
107
  super "Breakpoint was disabled due to rate-limiting. " \
@@ -234,7 +241,7 @@ module Rookout
234
241
  def initialize config
235
242
  super "Invalid rate limit configuration: #{config}",
236
243
  {
237
- "rate_limit_config" => config
244
+ "config" => config
238
245
  }
239
246
  end
240
247
  end
@@ -4,6 +4,7 @@ module Rookout
4
4
  include Singleton
5
5
 
6
6
  require_relative "config"
7
+ require_relative "utils"
7
8
  require_relative "exceptions"
8
9
  include Exceptions
9
10
 
data/lib/rookout/utils.rb CHANGED
@@ -1,26 +1,34 @@
1
- module Utils
2
- require "securerandom"
1
+ module Rookout
2
+ module Utils
3
+ require "securerandom"
4
+ require_relative "config"
3
5
 
4
- module_function
6
+ module_function
5
7
 
6
- def uuid
7
- SecureRandom.uuid.gsub(/-/, "")
8
- end
8
+ def uuid
9
+ SecureRandom.uuid.gsub(/-/, "")
10
+ end
9
11
 
10
- def milliseconds_to_nanoseconds milliseconds
11
- nano = milliseconds * (10**6)
12
- nano.to_i
13
- end
12
+ def milliseconds_to_nanoseconds milliseconds
13
+ nano = milliseconds * (10**6)
14
+ nano.to_i
15
+ end
14
16
 
15
- def time_to_nanoseconds time_obj
16
- secs = time_obj.to_i
17
- nsecs = time_obj.nsec
18
- ((10**9) * secs) + nsecs
19
- end
20
- end
17
+ def time_to_nanoseconds time_obj
18
+ secs = time_obj.to_i
19
+ nsecs = time_obj.nsec
20
+ ((10**9) * secs) + nsecs
21
+ end
22
+
23
+ def quiet_puts msg
24
+ # rubocop:disable Style/StderrPuts
25
+ return if Config.quiet
26
+ $stderr.puts msg
27
+ # rubocop:enable Style/StderrPuts
28
+ end
21
29
 
22
- class String
23
- def is_number?
24
- to_f.to_s == self || to_i.to_s == self
30
+ def is_number? string
31
+ true if Float(string) rescue false
32
+ end
25
33
  end
26
34
  end
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- VERSION = "0.1.41".freeze
2
+ VERSION = "0.1.43".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.41
4
+ version: 0.1.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liran Haimovitch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-12 00:00:00.000000000 Z
11
+ date: 2022-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller