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 +4 -4
- data/lib/tracebin/agent.rb +54 -19
- data/lib/tracebin/config.rb +3 -1
- data/lib/tracebin/initializer.rb +20 -0
- data/lib/tracebin/middleware.rb +13 -6
- data/lib/tracebin/puppet_master.rb +0 -2
- data/lib/tracebin/reporter.rb +29 -6
- data/lib/tracebin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d11ab424f832624ca57e0fb3fb89ef91f94266c
|
4
|
+
data.tar.gz: cb885677c01a2f4c4a72042aae0d0c54c1148c93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a65c599d300cb4f2b519774a4be78cc04a128961a23ca70a904f278aed37c4ca7a9b993222551f705755045f3b0cb48ea5e17745394c105e1b2931c223a256f
|
7
|
+
data.tar.gz: ce8338418589aa3a034bed548bd5bbd3afbfa98d78a7cfc6343a350d45daebbfc327d0e7360e60d5e89808885f6320e873ee3b231cafdf286b1d4e63b62e0bd0
|
data/lib/tracebin/agent.rb
CHANGED
@@ -11,41 +11,76 @@ module Tracebin
|
|
11
11
|
class << self
|
12
12
|
attr_accessor :config, :storage, :logger
|
13
13
|
|
14
|
-
def
|
15
|
-
return if
|
14
|
+
def start_parent_process
|
15
|
+
return if parent_process_started? || !config.enabled
|
16
16
|
|
17
|
-
logger.info "TRACEBIN: Starting Tracebin
|
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
|
-
@
|
24
|
+
@parent_process_reporter = Reporter.new
|
25
|
+
@parent_process_reporter.start!
|
24
26
|
|
25
|
-
@
|
26
|
-
|
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
|
-
|
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
|
32
|
-
return unless
|
48
|
+
def stop_parent_process
|
49
|
+
return unless parent_process_started?
|
33
50
|
|
34
|
-
logger.info "TRACEBIN: Shutting down
|
51
|
+
logger.info "TRACEBIN: Shutting down parent process..."
|
35
52
|
|
36
53
|
@health_monitor.stop!
|
37
54
|
@worker_process_monitor.stop!
|
38
|
-
@
|
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
|
-
@
|
73
|
+
@child_process_started = false
|
74
|
+
|
75
|
+
logger.info "TRACEBIN: Child process stopped!"
|
76
|
+
end
|
43
77
|
|
44
|
-
|
78
|
+
def parent_process_started?
|
79
|
+
@parent_process_started
|
45
80
|
end
|
46
81
|
|
47
|
-
def
|
48
|
-
@
|
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
|
data/lib/tracebin/config.rb
CHANGED
@@ -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
|
data/lib/tracebin/middleware.rb
CHANGED
@@ -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
|
-
|
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
|
52
|
-
Tracebin::Agent.
|
53
|
-
|
54
|
-
|
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.
|
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
|
data/lib/tracebin/reporter.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
88
|
+
stop_all_agent_processes
|
84
89
|
when Net::HTTPBadRequest
|
85
|
-
logger.warn 'Something went wrong with the server. Please contact us!'
|
86
|
-
|
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.
|
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
|
data/lib/tracebin/version.rb
CHANGED
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.
|
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-
|
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
|