soar_auditing_provider 1.1.4 → 1.1.5

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
  SHA1:
3
- metadata.gz: 8f6e6230240453cbcf257ea412f057a05cbd6fbf
4
- data.tar.gz: 7a1b94a471a5dddc85c830c581f41e36d92983e7
3
+ metadata.gz: 263b7fc728885f0bc350e4c339cb70c365ab0181
4
+ data.tar.gz: 2ef1bee6ad5a0b42568ceb41bdb6a621c3b9df77
5
5
  SHA512:
6
- metadata.gz: 2431fa22341e866135f6e431fe151a9566e44fa51f83275d1ced4ffd6161bf4c55306ad58c9333102d405d46cb51f3d1e191f9884d11bae88eba230f24f07ad7
7
- data.tar.gz: a0de67d9d644f525e28cfd30700d158f29c864c123a410dd44b38bc98b1c6260ebad9b2ca1ab04809af41e649a376ce7ad1615f5c38a3a95b2da3f21949ec3ea
6
+ metadata.gz: 0bd74895116aaa81c4dc780f42a54a5a569a16d8a3040eb26affabffa64dc43d13cd9ad97ec48a34af55a91a8a4eadb2424806f5df5c79a4fb3b076cb9374ae4
7
+ data.tar.gz: 53d08d6854c16b74168a711d9f85a0a7774737d6149c2f2916d2ef2c59fa56e8e40cc8fbaba6f71810140c8e41498fec41fec24287deba3c4cd7fe757bebce2d
@@ -78,6 +78,13 @@ module SoarAuditingProvider
78
78
  @worker.flush
79
79
  end
80
80
 
81
+ def audit_exception(exception:, level: :error, flow_id: nil)
82
+ exception_message = "#{exception.class}: #{exception.message}"
83
+ exception_message = exception_message + ":\n\t" + exception.backtrace.join("\n\t") if ENV['RACK_ENV'] == 'development'
84
+ level = :error if not is_valid_audit_level?(level)
85
+ send(level,exception_message,flow_id)
86
+ end
87
+
81
88
  private
82
89
 
83
90
  def prepend_caller_information(data)
@@ -97,17 +104,11 @@ module SoarAuditingProvider
97
104
  end
98
105
 
99
106
  def exit_cleanup(exception = nil)
100
- audit_exception_message(exception) if exception
107
+ audit_exception(exception: exception, level: :fatal, flow_id: @startup_flow_id) if exception
101
108
  info("Application exit",@startup_flow_id)
102
109
  flush
103
110
  end
104
111
 
105
- def audit_exception_message(exception)
106
- exception_message = "#{exception.class}: #{exception.message}"
107
- exception_message = exception_message + ":\n\t" + exception.backtrace.join("\n\t") if ENV['RACK_ENV'] == 'development'
108
- fatal(exception_message,@startup_flow_id)
109
- end
110
-
111
112
  def enqueue(level, data)
112
113
  @worker.enqueue(level, data)
113
114
  @enqueued_audit_events += 1
@@ -178,5 +179,9 @@ module SoarAuditingProvider
178
179
  'startup_timestamp' => @startup_timestamp
179
180
  }
180
181
  end
182
+
183
+ def is_valid_audit_level?(level)
184
+ [:debug, :info, :warn, :error, :fatal].include?(level)
185
+ end
181
186
  end
182
187
  end
@@ -2,10 +2,17 @@ require 'soar_thread_worker/thread_worker'
2
2
 
3
3
  module SoarAuditingProvider
4
4
  class AuditingWorker < SoarThreadWorker::ThreadWorker
5
+ attr_reader :failed_audit_attempts
6
+ attr_reader :latest_failed_audit_timestamp
7
+ attr_reader :latest_failed_audit_error_message
8
+ attr_reader :successful_audits
9
+ attr_reader :dequeued_audits
10
+ attr_reader :latest_successful_audit_timespan
11
+ attr_reader :latest_successful_audit_timestamp
12
+
5
13
  def initialize
6
14
  @queue = Queue.new
7
15
  @start_mutex = Mutex.new
8
- @queue_mutex = Mutex.new
9
16
  initialize_metrics
10
17
  end
11
18
 
@@ -19,17 +26,20 @@ module SoarAuditingProvider
19
26
  end
20
27
 
21
28
  def enqueue(level, data)
22
- @queue_mutex.synchronize {
23
- raise AuditingOverflowError if @queue.size >= @maximum_queue_size
29
+ if @queue.size < @maximum_queue_size then
24
30
  @queue.push({:level => level, :data => data})
25
- start
26
- }
31
+ else
32
+ raise AuditingOverflowError
33
+ end
34
+ ensure_worker_is_running
27
35
  end
28
36
 
29
- def start
37
+ def start(verbose: false)
30
38
  @start_mutex.synchronize {
31
- @stopping = false
32
- super if not running?
39
+ if not running? then
40
+ super()
41
+ $stderr.puts("Auditing worker was not running and respawned") if verbose
42
+ end
33
43
  }
34
44
  end
35
45
 
@@ -54,16 +64,11 @@ module SoarAuditingProvider
54
64
  failed_before = true
55
65
  retry
56
66
  end
57
-
58
- @queue_mutex.synchronize {
59
- return false if not @queue.empty? #indicates to thread worker that we are not done executing since the queue is not empty
60
- stop #explicitly stop the thread so that the stop occur automatically along with queue operations.
61
- return true #indicates to thread worker that we are done executing since the queue is empty
62
- }
67
+ return false #indicates to thread worder that we are not done executing
63
68
  end
64
69
 
65
70
  def flush(timeout = 1)
66
- start
71
+ ensure_worker_is_running
67
72
  wait_for_worker_to_clear_queue(timeout)
68
73
  fallback_flush_to_stderr if @queue.size > 0
69
74
  end
@@ -109,6 +114,10 @@ module SoarAuditingProvider
109
114
  $stderr.puts "#{notification}: #{message}"
110
115
  end
111
116
 
117
+ def ensure_worker_is_running
118
+ start(verbose: true)
119
+ end
120
+
112
121
  def ensure_worker_is_stopped
113
122
  attempt_graceful_stop
114
123
  sleep_while_still_running(5)
@@ -1,3 +1,3 @@
1
1
  module SoarAuditingProvider
2
- VERSION = "1.1.4"
2
+ VERSION = "1.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar_auditing_provider
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernst van Graan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-10-11 00:00:00.000000000 Z
12
+ date: 2016-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler