hoss-agent 1.0.1 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hoss/agent.rb +4 -0
- data/lib/hoss/config.rb +12 -3
- data/lib/hoss/spies/http.rb +1 -1
- data/lib/hoss/transport/worker.rb +86 -79
- data/lib/hoss/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 722e5fcda718182f47faa927fbfd9f19b96567d472eaa0f929bef3982b6024a3
|
4
|
+
data.tar.gz: f009f58f3659233bd2cb88670698e8cbcf382d85602abb0d898b3a49a0395d34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9ba92e08cbfb0a6daa8fcb30b2d6dc88b37e7ea1ed426197982c0a23df7df493737925b1cc56d7c6f53baa4a72495db4b9241b6d49aa91a7c10afffdc3ddc65
|
7
|
+
data.tar.gz: 55b09ee50f6e2c85ba683678de3f2216ceafff367a1e6aa89526ae359ae5b565aa7565e20356ba5b3e0ea5c1b3bb27360e5b288069065aec390c468dbdfbe281
|
data/lib/hoss/agent.rb
CHANGED
@@ -103,6 +103,10 @@ module Hoss
|
|
103
103
|
def_delegator :@central_config, :config
|
104
104
|
|
105
105
|
def start
|
106
|
+
unless config.api_key
|
107
|
+
config.logger.warn "Hoss API Key missing, not starting."
|
108
|
+
return
|
109
|
+
end
|
106
110
|
unless config.disable_start_message?
|
107
111
|
config.logger.info format(
|
108
112
|
'[%s] Starting agent, reporting to %s',
|
data/lib/hoss/config.rb
CHANGED
@@ -33,13 +33,14 @@ module Hoss
|
|
33
33
|
# rubocop:disable Metrics/LineLength, Layout/ExtraSpacing
|
34
34
|
option :config_file, type: :string, default: 'config/hoss.yml'
|
35
35
|
option :api_host, type: :url, default: ENV['HOSS_API_HOST'] || 'https://app.hoss.com'
|
36
|
-
option :api_key, type: :string
|
36
|
+
option :api_key, type: :string, default: ENV['HOSS_API_KEY']
|
37
37
|
option :ingress_host, type: :string, default: ENV['HOSS_INGRESS_HOST'] || 'https://ingress.hoss.com/v1'
|
38
38
|
option :max_queue_size, type: :int, default: 3000
|
39
39
|
option :batch_size, type: :int, default: ENV['HOSS_BATCH_SIZE'] || 512000
|
40
40
|
option :max_event_retries, type: :int, default: 100
|
41
41
|
option :remote_config_fetch_interval, type: :int, default: 300
|
42
42
|
option :agentConfig, type: :dict
|
43
|
+
option :debug, type: :boolean, default: ENV['HOSS_DEBUG']
|
43
44
|
|
44
45
|
|
45
46
|
option :central_config, type: :bool, default: true
|
@@ -62,8 +63,8 @@ module Hoss
|
|
62
63
|
option :hostname, type: :string
|
63
64
|
option :http_compression, type: :bool, default: true
|
64
65
|
option :instrument, type: :bool, default: true
|
65
|
-
option :log_level, type: :int, default: Logger::
|
66
|
-
option :log_path, type: :string
|
66
|
+
option :log_level, type: :int, default: Logger::WARN
|
67
|
+
option :log_path, type: :string
|
67
68
|
option :pool_size, type: :int, default: 1
|
68
69
|
option :proxy_address, type: :string
|
69
70
|
option :proxy_headers, type: :dict
|
@@ -100,6 +101,14 @@ module Hoss
|
|
100
101
|
assign(load_config_file)
|
101
102
|
assign(env)
|
102
103
|
|
104
|
+
if self.debug == true || self.debug == 'true'
|
105
|
+
assign(
|
106
|
+
log_level: Logger::DEBUG,
|
107
|
+
debug: true,
|
108
|
+
log_path: '-'
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
103
112
|
warn '[HOSS] No API Key provided' unless self.api_key
|
104
113
|
|
105
114
|
yield self if block_given?
|
data/lib/hoss/spies/http.rb
CHANGED
@@ -45,7 +45,7 @@ module Hoss
|
|
45
45
|
return perform_without_apm(req, options)
|
46
46
|
end
|
47
47
|
Hoss.with_event do |event|
|
48
|
-
event.request.headers['host'] = req.uri.
|
48
|
+
event.request.headers['host'] = req.uri.host
|
49
49
|
req.headers.each {|n,v| event.request.headers[n] = v}
|
50
50
|
event.request.method = req.verb.to_s.upcase
|
51
51
|
event.request.url = req.uri.to_s
|
@@ -61,100 +61,104 @@ module Hoss
|
|
61
61
|
|
62
62
|
done = false
|
63
63
|
while (!done && msg = queue.pop)
|
64
|
-
|
64
|
+
begin
|
65
|
+
debug 'working message', msg
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
67
|
+
# wait if we don't have a config
|
68
|
+
while config.agentConfig.nil?
|
69
|
+
sleep 0.1
|
70
|
+
end
|
71
|
+
|
72
|
+
case msg
|
73
|
+
when StopMessage
|
74
|
+
debug 'Stopping worker -- %s', self
|
75
|
+
done = true
|
76
|
+
break
|
77
|
+
else
|
78
|
+
batch = []
|
79
|
+
current_batch_size = 0
|
80
|
+
|
81
|
+
# Use this as the first message in the batch
|
82
|
+
event = msg.filtered ? msg : filter_resource(msg)
|
83
|
+
unless event.nil?
|
84
|
+
event_size = resource_size(event)
|
85
|
+
if current_batch_size + event_size <= @config.batch_size
|
86
|
+
unless host_blacklisted(event)
|
87
|
+
current_batch_size += event_size
|
88
|
+
if event.retries < @config.max_event_retries
|
89
|
+
batch.push(event)
|
90
|
+
else
|
91
|
+
debug "max retries hit for event"
|
92
|
+
end
|
91
93
|
end
|
94
|
+
else
|
95
|
+
debug "Event is too large, body needs to be truncated"
|
92
96
|
end
|
93
|
-
else
|
94
|
-
debug "Event is too large, body needs to be truncated"
|
95
97
|
end
|
96
|
-
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
99
|
+
# Do inner loop reading queue to build report
|
100
|
+
requeue_messages = []
|
101
|
+
while current_batch_size < @config.batch_size && !queue.empty?
|
102
|
+
next_msg = queue.pop
|
103
|
+
case next_msg
|
104
|
+
when StopMessage
|
105
|
+
debug 'Stopping worker -- %s', self
|
106
|
+
done = true
|
107
|
+
break
|
108
|
+
else
|
109
|
+
event = next_msg.filtered ? next_msg : filter_resource(next_msg)
|
110
|
+
unless event.nil?
|
111
|
+
event_size = resource_size(event)
|
112
|
+
if current_batch_size + event_size <= @config.batch_size
|
113
|
+
unless host_blacklisted(event)
|
114
|
+
current_batch_size += event_size
|
115
|
+
if event.retries < @config.max_event_retries
|
116
|
+
batch.push(event)
|
117
|
+
else
|
118
|
+
debug "max retries hit for event"
|
119
|
+
end
|
118
120
|
end
|
121
|
+
else
|
122
|
+
debug "Event too large for this batch, requeue"
|
123
|
+
requeue_messages.push(event)
|
119
124
|
end
|
120
|
-
else
|
121
|
-
debug "Event too large for this batch, requeue"
|
122
|
-
requeue_messages.push(event)
|
123
125
|
end
|
124
126
|
end
|
125
127
|
end
|
126
|
-
end
|
127
|
-
|
128
|
-
if batch.length == 0
|
129
|
-
debug "batch is empty, breaking"
|
130
|
-
break
|
131
|
-
end
|
132
128
|
|
133
|
-
|
134
|
-
|
129
|
+
if batch.length == 0
|
130
|
+
debug "batch is empty, breaking"
|
131
|
+
break
|
132
|
+
end
|
135
133
|
|
136
|
-
|
137
|
-
|
134
|
+
debug "Requeue #{requeue_messages.length} messages" if requeue_messages.length > 0
|
135
|
+
requeue_messages.each {|msg| queue.push(msg, false) }
|
138
136
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
137
|
+
report = Report.new
|
138
|
+
report.events = batch.map {|event| serializers.serialize(event) }
|
139
|
+
|
140
|
+
debug "Finished building report"
|
141
|
+
data = serializers.serialize(report)
|
142
|
+
json = JSON.fast_generate(data)
|
143
|
+
begin
|
144
|
+
debug json
|
145
|
+
rescue Exception => e
|
146
|
+
debug 'unable to print body'
|
147
|
+
puts json if config.debug
|
148
|
+
end
|
149
|
+
begin
|
150
|
+
connection.write(json)
|
151
|
+
rescue Exception => e
|
152
|
+
error format('Failed send report: %s %s', e.inspect, e.backtrace)
|
153
|
+
batch.each do |m|
|
154
|
+
m.retries += 1
|
155
|
+
queue.push(m, false)
|
156
|
+
end
|
157
|
+
sleep 1
|
155
158
|
end
|
156
|
-
sleep 1
|
157
159
|
end
|
160
|
+
rescue Exception => e
|
161
|
+
debug "error in worker #{e.inspect}"
|
158
162
|
end
|
159
163
|
end
|
160
164
|
rescue Exception => e
|
@@ -183,6 +187,9 @@ module Hoss
|
|
183
187
|
else
|
184
188
|
body
|
185
189
|
end
|
190
|
+
rescue Exception => e
|
191
|
+
debug "unable to decompress body #{e.inspect}"
|
192
|
+
return nil
|
186
193
|
end
|
187
194
|
|
188
195
|
def get_header(headers, name)
|
data/lib/hoss/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoss-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Cooper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|