rookout 0.1.22 → 0.1.26

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: 1189352fe3bb2817944ec553c3a658bcd0d677781ffee90190521e1ed55189c3
4
- data.tar.gz: 63bf916c9f3140c4bf2be89a3469ffd3f451f37edc4741c39c6336ef1373269c
3
+ metadata.gz: 71a48ffc9af42b9e823c1bb8511514e95954425a6ff43495b0f90f7defc98f9c
4
+ data.tar.gz: a525931c98fc3f8d23068f7d774a18c1b33b2edb756a1abea72a07efe8f2bef6
5
5
  SHA512:
6
- metadata.gz: cace5dbc2f61f8e1987397345061080fecc85cbcaeb065976f8a8ae071621c01b717e46dd98df55a48fd399f7b2f02b467b786b335d9dcf4088e09a3094f1961
7
- data.tar.gz: d33370845b6bb7166c93626e74b73a743d5a799f8b69722bae627561fbd747a36542c2a38e7f3135f099e90415d5b5219775407e942a8f3e25c60939a1be9012
6
+ metadata.gz: b7fac6cf5a613e6dc45c6071d5c6f6e133568911fa1ee6a66e17e50e22c61523dcd0706c1126ea8390320137e44ca832cb78946c4c57c2608fee0b4d590755b2
7
+ data.tar.gz: baad1dcec8ec04456aeb993825e36b5025d9c901aaf56970709b51801b55e397f25be02e14153a31978433f8127576e02484af4cdfcb4f34229a22463524669a
@@ -28,6 +28,11 @@ module Rookout
28
28
  def execute frame, extracted, output
29
29
  return unless @enabled
30
30
 
31
+ if output.user_messages_queue_full?
32
+ Logger.instance.warning "Skipping aug-\t#{id} execution because the queue is full"
33
+ return
34
+ end
35
+
31
36
  namespace = create_namespaces frame, extracted
32
37
  return if @condition && !@condition.evaluate(namespace)
33
38
 
@@ -10,6 +10,7 @@ module Rookout
10
10
  require_relative "locations/location_exception_handler"
11
11
  require_relative "aug_rate_limiter"
12
12
  require_relative "aug"
13
+ require_relative "../utils"
13
14
 
14
15
  class AugFactory
15
16
  def initialize output
@@ -34,7 +35,8 @@ module Rookout
34
35
 
35
36
  rate_limit = create_rate_limit configuration
36
37
 
37
- aug = Aug.new aug_id, action, condition, rate_limit, max_aug_time
38
+ max_aug_time_ns = Utils.milliseconds_to_nanoseconds max_aug_time
39
+ aug = Aug.new aug_id, action, condition, rate_limit, max_aug_time_ns
38
40
 
39
41
  location_configuration = configuration["location"]
40
42
  raise Exceptions::RookAugInvalidKey.new("location", configuration) unless location_configuration.is_a? Hash
@@ -72,7 +74,10 @@ module Rookout
72
74
 
73
75
  rate_limit_modifier = configuration["rateLimitModifier"] || 5
74
76
 
75
- AugRateLimiter.new window_quota, window_size, rate_limit_modifier
77
+ window_quota_ns = Utils.milliseconds_to_nanoseconds window_quota
78
+ window_size_ns = Utils.milliseconds_to_nanoseconds window_size
79
+
80
+ AugRateLimiter.new window_quota_ns, window_size_ns, rate_limit_modifier
76
81
  end
77
82
  end
78
83
  end
@@ -1,10 +1,12 @@
1
1
  module Rookout
2
2
  module Augs
3
3
  require_relative "../exceptions"
4
+ require_relative "../utils"
4
5
 
5
6
  class AugRateLimiter
6
7
  def initialize quota, window_size, active_limit
7
8
  @quota = quota
9
+ @has_quota = !@quota.nil? && (@quota > 0)
8
10
  @window_size = window_size
9
11
  @active_weight = quota / active_limit
10
12
 
@@ -18,24 +20,22 @@ module Rookout
18
20
  start_time ||= Time.now
19
21
 
20
22
  # If quota, verify it
21
- if @quota && @quota > 0
23
+ if @has_quota
22
24
  # Get current time
23
- now_ms = (start_time.to_f * 1000).to_i
25
+ now_ns = Utils.time_to_nanoseconds start_time
24
26
 
25
27
  # Calculate window keys
26
- current_window_key = (now_ms / @window_size) * @window_size
27
- prev_window_key = current_window_key - @window_size
28
+ current_window_key, prev_window_key = timestamp_to_window_keys now_ns
28
29
 
29
30
  @mutex.synchronize do
30
31
  # Clean old windows
31
- cleanup now_ms
32
-
32
+ cleanup now_ns
33
33
  # Increase active count
34
34
  @active_count += 1
35
35
  active = true
36
36
 
37
37
  # If exceeding quota
38
- if current_usage(now_ms, current_window_key, prev_window_key) > @quota
38
+ if current_usage(now_ns, current_window_key, prev_window_key) > @quota
39
39
  warning = Processor::RookError.new Exceptions::RookRuleRateLimited.new
40
40
  UserWarnings.notify_warning warning
41
41
  return
@@ -46,7 +46,9 @@ module Rookout
46
46
  begin
47
47
  yield
48
48
  ensure
49
- @mutex.synchronize { record_usage current_window_key, (Time.now - start_time) * 1000 } if @quota && @quota > 0
49
+ if @has_quota
50
+ @mutex.synchronize { record_usage current_window_key, Utils.time_to_nanoseconds(Time.now) - now_ns }
51
+ end
50
52
  end
51
53
  ensure
52
54
  # Reduce active count
@@ -55,7 +57,15 @@ module Rookout
55
57
 
56
58
  private
57
59
 
58
- def current_usage now_ms, current_window_key, prev_window_key
60
+ attr_reader :windows # will be used only in tests using <OBJ>.send(:windows)
61
+
62
+ def timestamp_to_window_keys now_ns
63
+ current_window_key = (now_ns / @window_size) * @window_size
64
+ prev_window_key = current_window_key - @window_size
65
+ [current_window_key, prev_window_key]
66
+ end
67
+
68
+ def current_usage now_ns, current_window_key, prev_window_key
59
69
  # Get usage information
60
70
  current_window_usage = @windows[current_window_key]
61
71
  if current_window_usage.nil?
@@ -65,7 +75,7 @@ module Rookout
65
75
  prev_window_usage = @windows[prev_window_key] || 0
66
76
 
67
77
  # Previous window weight
68
- prev_weight = 1 - (now_ms - current_window_key) / @window_size.to_f
78
+ prev_weight = 1 - (now_ns - current_window_key) / @window_size.to_f
69
79
 
70
80
  # Final weighted usage
71
81
  (prev_window_usage * prev_weight) + (@active_count * @active_weight) + current_window_usage
@@ -80,16 +90,8 @@ module Rookout
80
90
  @windows[current_window_key] += [duration, 5].max.to_f
81
91
  end
82
92
 
83
- def cleanup now_ms
84
- # Don't bother with contention
85
- return if @mutex.locked?
86
-
87
- @mutex.synchronize do
88
- # every 5 windows-times, clear windows older than 10 window-times
89
- if @windows.length > 10
90
- @windows.reject! { |key, _| key < (now_ms - @window_size * 5) }
91
- end
92
- end
93
+ def cleanup now_ns
94
+ @windows.reject! { |key, _| key < (now_ns - @window_size * 5) } if @windows.length > 10
93
95
  end
94
96
  end
95
97
  end
@@ -23,6 +23,8 @@ module Rookout
23
23
  class AgentComWs
24
24
  include EventEmitter
25
25
 
26
+ attr_reader :pending_messages
27
+
26
28
  def initialize output, agent_host, agent_port, proxy, token, labels
27
29
  agent_host_with_protocl = agent_host.include?("://") ? agent_host : "ws://#{agent_host}"
28
30
  @uri = "#{agent_host_with_protocl}:#{agent_port}/v1"
@@ -62,6 +64,10 @@ module Rookout
62
64
  @pending_messages.push buffer if @pending_messages.length < Config.agent_com_max_queued_messages
63
65
  end
64
66
 
67
+ def queue_full?
68
+ @pending_messages.length >= Config.agent_com_max_queued_messages
69
+ end
70
+
65
71
  def connect
66
72
  @running = true
67
73
 
@@ -11,11 +11,16 @@ module Rookout
11
11
  require_relative "git"
12
12
  include Git
13
13
 
14
- def initialize labels
14
+ def initialize labels, k8s_file_path = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
15
15
  @agent_id = nil
16
16
  @labels = labels.clone
17
17
  @labels["rookout_debug"] = "on" if Config.debug
18
18
 
19
+ k8_namespace = create_cluster_namespace k8s_file_path
20
+ unless k8_namespace == ""
21
+ @labels["k8s_namespace"] = k8_namespace
22
+ end
23
+
19
24
  @ip_addr = local_ip
20
25
 
21
26
  @scm_info = create_scm_information
@@ -49,7 +54,7 @@ module Rookout
49
54
  scm: @scm_info
50
55
  end
51
56
 
52
- attr_accessor :agent_id
57
+ attr_accessor :agent_id, :labels
53
58
 
54
59
  private
55
60
 
@@ -65,6 +70,18 @@ module Rookout
65
70
  end
66
71
  # rubocop:enable Style/ParallelAssignment
67
72
 
73
+ def create_cluster_namespace k8s_file_path
74
+ return_value = ""
75
+
76
+ # No Kubernetes is valid
77
+ if File.file? k8s_file_path
78
+ # Read the file contents and return it as result
79
+ return_value = File.read k8s_file_path
80
+ end
81
+
82
+ return_value
83
+ end
84
+
68
85
  def create_scm_information
69
86
  user_git_origin = Config.user_git_origin || ENV["ROOKOUT_REMOTE_ORIGIN"]
70
87
  user_git_commit = Config.user_git_commit || ENV["ROOKOUT_COMMIT"]
@@ -49,6 +49,10 @@ module Rookout
49
49
  Logger.instance.remove_output self
50
50
  end
51
51
 
52
+ def user_messages_queue_full?
53
+ @user_message_bucket.exhausted? || (!@agent_com.nil? && @agent_com.queue_full?)
54
+ end
55
+
52
56
  def send_warning rule_id, error
53
57
  send_rule_status rule_id, :Warning, error
54
58
  end
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- COMMIT = "f6730b0a0901306d41b983fb4b7a8c7f85d46c81".freeze
2
+ COMMIT = "5dbaa8024d9dd61fbf97ca654094c5c30728d4f9".freeze
3
3
  end
@@ -25,7 +25,7 @@ module Rookout
25
25
  Rookout::Config.agent_com_ping_interval = 10
26
26
  Rookout::Config.agent_com_ping_timeout = 30
27
27
  Rookout::Config.agent_com_flush_timeout = 3
28
- Rookout::Config.agent_com_max_queued_messages = 500
28
+ Rookout::Config.agent_com_max_queued_messages = 100
29
29
 
30
30
  attr_accessor :backoff_factor, :backoff_reset_time, :backoff_max_time
31
31
  Rookout::Config.backoff_factor = 0.2
@@ -113,8 +113,11 @@ module Rookout
113
113
  end
114
114
 
115
115
  def build_handlers
116
- @handlers.push new_file_handler unless Config.logger_filename.nil? || Config.logger_filename.empty?
117
- @handlers.push new_stderr_handler if Config.logger_log_to_stderr
116
+ if Config.logger_log_to_stderr
117
+ @handlers.push new_file_handler unless Config.logger_filename.nil? || Config.logger_filename.empty?
118
+ @handlers.push new_stderr_handler
119
+ end
120
+
118
121
  @handlers.push new_remote_handler
119
122
  end
120
123
 
@@ -49,6 +49,8 @@ module Rookout
49
49
  @dump_config = OBJECT_DUMP_CONFIG_STRING
50
50
  elsif @obj.is_a?(Hash) || @obj.is_a?(Array)
51
51
  @dump_config = OBJECT_DUMP_CONFIG_COLLECTION
52
+ else
53
+ @dump_config = OBJECT_DUMP_CONFIG_TOLERANT
52
54
  end
53
55
  self
54
56
  end
@@ -20,7 +20,7 @@ module Rookout
20
20
 
21
21
  begin
22
22
  trace_point.enable target: position.method, target_line: position.lineno
23
- rescue ArgumentError => e
23
+ rescue RuntimeError, ArgumentError => e
24
24
  raise Exceptions::RookSetTracepointFailed.new(position.lineno, e)
25
25
  end
26
26
 
data/lib/rookout/utils.rb CHANGED
@@ -6,4 +6,15 @@ module Utils
6
6
  def uuid
7
7
  SecureRandom.uuid.gsub(/-/, "")
8
8
  end
9
+
10
+ def milliseconds_to_nanoseconds milliseconds
11
+ nano = milliseconds * (10**6)
12
+ nano.to_i
13
+ end
14
+
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
9
20
  end
@@ -1,3 +1,3 @@
1
1
  module Rookout
2
- VERSION = "0.1.22".freeze
2
+ VERSION = "0.1.26".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.22
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liran Haimovitch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-11 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 3.9.2
75
+ version: 3.17.3
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: 3.9.2
82
+ version: 3.17.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: google-style
85
85
  requirement: !ruby/object:Gem::Requirement