tracebin 0.0.11 → 0.0.12

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
  SHA1:
3
- metadata.gz: e823382bbf674934553df737b9a52652f9081a14
4
- data.tar.gz: ab4ac41cead343e9d8068c925113c241340e15a7
3
+ metadata.gz: 8d11ab424f832624ca57e0fb3fb89ef91f94266c
4
+ data.tar.gz: cb885677c01a2f4c4a72042aae0d0c54c1148c93
5
5
  SHA512:
6
- metadata.gz: cdb4d07940b6895511a4866ca1e140502f463f984c074b82524930e493042b1020a7edf02a75e9ca79d21f5da4a53c34eb458b73860266ee0fd3ad049a58439d
7
- data.tar.gz: b6d60fd08949816eb22f5273f415d4dfb04266ce25b4e7829bfa00799624690d8c70cd45bdbac37923007f297a3bc02c9af6e769f11ab0111fe15e2e8003f8a4
6
+ metadata.gz: 4a65c599d300cb4f2b519774a4be78cc04a128961a23ca70a904f278aed37c4ca7a9b993222551f705755045f3b0cb48ea5e17745394c105e1b2931c223a256f
7
+ data.tar.gz: ce8338418589aa3a034bed548bd5bbd3afbfa98d78a7cfc6343a350d45daebbfc327d0e7360e60d5e89808885f6320e873ee3b231cafdf286b1d4e63b62e0bd0
@@ -11,41 +11,76 @@ module Tracebin
11
11
  class << self
12
12
  attr_accessor :config, :storage, :logger
13
13
 
14
- def start!
15
- return if started? || !config.enabled
14
+ def start_parent_process
15
+ return if parent_process_started? || !config.enabled
16
16
 
17
- logger.info "TRACEBIN: Starting Tracebin agent..."
17
+ logger.info "TRACEBIN: Starting Tracebin parent process..."
18
+ init_storage
18
19
 
19
20
  @subscribers = Subscribers.new
20
21
  @health_monitor = HealthMonitor.start
21
22
  @worker_process_monitor = WorkerProcessMonitor.start
22
23
 
23
- @reporter = Reporter.new(storage, config, logger)
24
+ @parent_process_reporter = Reporter.new
25
+ @parent_process_reporter.start!
24
26
 
25
- @reporter.start!
26
- @started = true
27
+ @parent_process_started = true
28
+ logger.info "TRACEBIN: Tracebin parent process started!"
29
+ rescue => e
30
+ logger.info "TRACEBIN: Error occurred while trying to start parent process: #{e.message}"
31
+ end
32
+
33
+ def start_child_process
34
+ return if child_process_started? || !config.enabled
35
+
36
+ logger.info "TRACEBIN: Starting Tracebin child process..."
37
+ init_storage
27
38
 
28
- logger.info "TRACEBIN: Tracebin agent started!"
39
+ @child_process_reporter = Reporter.new
40
+ @child_process_reporter.start!
41
+
42
+ @child_process_started = true
43
+ logger.info "TRACEBIN: Tracebin child process started!"
44
+ rescue => e
45
+ logger.info "TRACEBIN: Error occurred while trying to start child process: #{e.message}"
29
46
  end
30
47
 
31
- def stop!
32
- return unless started?
48
+ def stop_parent_process
49
+ return unless parent_process_started?
33
50
 
34
- logger.info "TRACEBIN: Shutting down Tracebin agent..."
51
+ logger.info "TRACEBIN: Shutting down parent process..."
35
52
 
36
53
  @health_monitor.stop!
37
54
  @worker_process_monitor.stop!
38
- @reporter.stop!
55
+ @parent_process_reporter.stop!
56
+
57
+ storage.unload
58
+
59
+ @parent_process_started = false
60
+
61
+ logger.info "TRACEBIN: Parent process stopped!"
62
+ end
63
+
64
+ def stop_child_processes
65
+ return unless child_process_started?
66
+
67
+ logger.info "TRACEBIN: Shutting down child process..."
68
+
69
+ @child_process_reporter.stop!
39
70
 
40
71
  storage.unload
41
72
 
42
- @started = false
73
+ @child_process_started = false
74
+
75
+ logger.info "TRACEBIN: Child process stopped!"
76
+ end
43
77
 
44
- logger.info "TRACEBIN: Tracebin agent stopped!"
78
+ def parent_process_started?
79
+ @parent_process_started
45
80
  end
46
81
 
47
- def started?
48
- @started
82
+ def child_process_started?
83
+ @child_process_started
49
84
  end
50
85
 
51
86
  def init_logger
@@ -69,16 +104,16 @@ module Tracebin
69
104
  else Logger::INFO
70
105
  end
71
106
  end
107
+
108
+ def init_storage
109
+ @storage = ::Tracebin::Storage.new
110
+ end
72
111
  end
73
112
 
74
113
  def self.logger
75
114
  @logger || init_logger
76
115
  end
77
116
 
78
- def self.storage
79
- @storage ||= ::Tracebin::Storage.new
80
- end
81
-
82
117
  def self.config
83
118
  @config ||= Config.new
84
119
  end
@@ -6,7 +6,9 @@ module Tracebin
6
6
  report_path: 'reports',
7
7
  enable_ssl: true,
8
8
  ignored_paths: [],
9
- enabled: true
9
+ enabled: true,
10
+ report_frequency: 60,
11
+ report_retry_limit: 10
10
12
  }.freeze
11
13
 
12
14
  attr_accessor *(DEFAULTS.keys + [:bin_id])
@@ -0,0 +1,20 @@
1
+ module Tracebin
2
+ module Initializer
3
+ class << self
4
+ def start!
5
+ if forking_server?
6
+ # This will not work yet.
7
+ Tracebin::Agent.start!
8
+ else
9
+ Tracebin::Agent.start!
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def forking_server?
16
+ defined? ::Puma
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,6 @@
1
1
  require 'tracebin/timer'
2
2
  require 'tracebin/puppet_master'
3
+ # require 'tracebin/initializer'
3
4
 
4
5
  module Tracebin
5
6
  class Middleware
@@ -7,10 +8,11 @@ module Tracebin
7
8
 
8
9
  def initialize(app)
9
10
  @app = app
11
+
10
12
  @config = Tracebin::Agent.config
11
13
  @logger = Tracebin::Agent.logger
12
14
 
13
- start_agent
15
+ start_agent_parent_process
14
16
  end
15
17
 
16
18
  def call(env)
@@ -18,7 +20,10 @@ module Tracebin
18
20
  end
19
21
 
20
22
  def __call(env)
23
+ start_agent_child_process
24
+
21
25
  if agent_disabled?(env)
26
+ @logger.debug "TRACEBIN: Tracebin disabled for this request."
22
27
  return @app.call env
23
28
  else
24
29
  @tracebin_timer = Timer.new
@@ -48,17 +53,19 @@ module Tracebin
48
53
  end
49
54
  end
50
55
 
51
- def start_agent
52
- Tracebin::Agent.start!
53
- rescue => e
54
- @logger.warn "TRACEBIN: Failed to start agent: #{e.message}"
56
+ def start_agent_child_process
57
+ Tracebin::Agent.start_child_process
58
+ end
59
+
60
+ def start_agent_parent_process
61
+ Tracebin::Agent.start_parent_process
55
62
  end
56
63
 
57
64
  def agent_disabled?(env)
58
65
  path = env['REQUEST_PATH']
59
66
  ignored_paths = config.ignored_paths.map { |root| %r{^#{root}} }
60
67
 
61
- !Tracebin::Agent.started? ||
68
+ !Tracebin::Agent.child_process_started? ||
62
69
  ignored_paths.any? { |root| !!root.match(path) }
63
70
  end
64
71
  end
@@ -5,12 +5,10 @@ module Tracebin
5
5
  class PuppetMaster
6
6
  def initialize(puppet, options = {})
7
7
  @puppet = puppet
8
- @logger = RequestLogger.new(options[:logger])
9
8
  @storage = ::Tracebin::Agent.storage
10
9
  end
11
10
 
12
11
  def process
13
- # @logger.display_payload @puppet.payload
14
12
  @storage << @puppet.payload
15
13
  end
16
14
  end
@@ -9,6 +9,7 @@ module Tracebin
9
9
  @logger = logger
10
10
  @config = config
11
11
  @storage = storage
12
+ @retry_limit = config.report_retry_limit
12
13
 
13
14
  if config.enable_ssl
14
15
  require 'net/https'
@@ -24,7 +25,10 @@ module Tracebin
24
25
  end
25
26
 
26
27
  def start!
27
- @task = Concurrent::TimerTask.new do
28
+ freq = config.report_frequency >= 5 ? config.report_frequency : 5
29
+ @retries = 0
30
+
31
+ @task = Concurrent::TimerTask.new execution_interval: freq do
28
32
  unless storage.unloaded?
29
33
  payload = storage.unload
30
34
  res = send_data payload
@@ -71,22 +75,41 @@ module Tracebin
71
75
  rescue Exception => e
72
76
  logger.warn "TRACEBIN: Exception occurred sending data to the server: #{e.message}"
73
77
  logger.debug "TRACEBIN: #{e.backtrace.join("\n\t")}"
74
- Tracebin::Agent.stop!
78
+ stop_all_agent_processes
75
79
  end
76
80
 
77
81
  def handle_response(res, payload)
78
82
  case res
79
83
  when Net::HTTPSuccess
84
+ @retries = 0
80
85
  logger.info 'TRACEBIN: Successfully sent payload to the server.'
81
86
  when Net::HTTPNotFound
82
87
  logger.warn 'TRACEBIN: App bin ID not found. Please create a new app bin and add it to the config.'
83
- Tracebin::Agent.stop!
88
+ stop_all_agent_processes
84
89
  when Net::HTTPBadRequest
85
- logger.warn 'Something went wrong with the server. Please contact us!'
86
- Tracebin::Agent.stop!
90
+ logger.warn 'TRACEBIN: Something went wrong with the server. Please contact us!'
91
+ stop_all_agent_processes
92
+ when Net::HTTPRequestTimeout
93
+ handle_timeout
87
94
  else
88
- logger.warn 'TRACEBIN: Failed to send data to the server. Will try again in 1 minute.'
95
+ logger.warn 'TRACEBIN: Failed to send data to the server.'
96
+ stop_all_agent_processes
97
+ end
98
+ end
99
+
100
+ def stop_all_agent_processes
101
+ ::Tracebin::Agent.stop_parent_process
102
+ ::Tracebin::Agent.stop_child_process
103
+ end
104
+
105
+ def handle_timeout
106
+ if @retries < @retry_limit
107
+ logger.info "TRACEBIN: Couldn't contact the server. Will try again in #{config.report_frequency} seconds."
89
108
  @storage.add_payload payload
109
+ @retries += 1
110
+ else
111
+ logger.warn "TRACEBIN: Couldn't contact the server. Retry limit reached."
112
+ stop_all_agent_processes
90
113
  end
91
114
  end
92
115
  end
@@ -1,3 +1,3 @@
1
1
  module Tracebin
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracebin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Guillen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-27 00:00:00.000000000 Z
11
+ date: 2017-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -109,6 +109,7 @@ files:
109
109
  - lib/tracebin/events.rb
110
110
  - lib/tracebin/health_monitor.rb
111
111
  - lib/tracebin/helpers.rb
112
+ - lib/tracebin/initializer.rb
112
113
  - lib/tracebin/logger.rb
113
114
  - lib/tracebin/middleware.rb
114
115
  - lib/tracebin/patches.rb