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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9d32204aeaa5465b3355828b2459e627de152ee625cf0be0a89d9d81880ba64
4
- data.tar.gz: d180cf68507c480fe88ec081601acd24cfab99ea8ca592deb33b7fe1a10e13e4
3
+ metadata.gz: 722e5fcda718182f47faa927fbfd9f19b96567d472eaa0f929bef3982b6024a3
4
+ data.tar.gz: f009f58f3659233bd2cb88670698e8cbcf382d85602abb0d898b3a49a0395d34
5
5
  SHA512:
6
- metadata.gz: bb42860e0eacb4e1b0c07d8d8c12eb6817d9fe138a49f9b84c450e9596f889545806d4060b2d19852ace9f3c25fd59de14607dbcbf7810c252c352542ced5383
7
- data.tar.gz: 5d37cfde92eee0bfa8cfe158fa5a511099cf2f5f4f72fba74eade39666fd09d6ac15b050488ff98de6a17284d6dce13dbf3ce9a047bab921290fd2d7d159266c
6
+ metadata.gz: a9ba92e08cbfb0a6daa8fcb30b2d6dc88b37e7ea1ed426197982c0a23df7df493737925b1cc56d7c6f53baa4a72495db4b9241b6d49aa91a7c10afffdc3ddc65
7
+ data.tar.gz: 55b09ee50f6e2c85ba683678de3f2216ceafff367a1e6aa89526ae359ae5b565aa7565e20356ba5b3e0ea5c1b3bb27360e5b288069065aec390c468dbdfbe281
@@ -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',
@@ -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::DEBUG
66
- option :log_path, type: :string, default: '-'
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?
@@ -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.hostname
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
- debug 'working message', msg
64
+ begin
65
+ debug 'working message', msg
65
66
 
66
- # wait if we don't have a config
67
- while config.agentConfig.nil?
68
- sleep 0.1
69
- end
70
-
71
- case msg
72
- when StopMessage
73
- debug 'Stopping worker -- %s', self
74
- done = true
75
- break
76
- else
77
- batch = []
78
- current_batch_size = 0
79
-
80
- # Use this as the first message in the batch
81
- event = msg.filtered ? msg : filter_resource(msg)
82
- unless event.nil?
83
- event_size = resource_size(event)
84
- if current_batch_size + event_size <= @config.batch_size
85
- unless host_blacklisted(event)
86
- current_batch_size += event_size
87
- if event.retries < @config.max_event_retries
88
- batch.push(event)
89
- else
90
- debug "max retries hit for event"
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
- # Do inner loop reading queue to build report
99
- requeue_messages = []
100
- while current_batch_size < @config.batch_size && !queue.empty?
101
- next_msg = queue.pop
102
- case next_msg
103
- when StopMessage
104
- debug 'Stopping worker -- %s', self
105
- done = true
106
- break
107
- else
108
- event = next_msg.filtered ? next_msg : filter_resource(next_msg) unless
109
- unless event.nil?
110
- event_size = resource_size(event)
111
- if current_batch_size + event_size <= @config.batch_size
112
- unless host_blacklisted(event)
113
- current_batch_size += event_size
114
- if event.retries < @config.max_event_retries
115
- batch.push(event)
116
- else
117
- debug "max retries hit for event"
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
- debug "Requeue #{requeue_messages.length} messages" if requeue_messages.length > 0
134
- requeue_messages.each {|msg| queue.push(msg, false) }
129
+ if batch.length == 0
130
+ debug "batch is empty, breaking"
131
+ break
132
+ end
135
133
 
136
- report = Report.new
137
- report.events = batch.map {|event| serializers.serialize(event) }
134
+ debug "Requeue #{requeue_messages.length} messages" if requeue_messages.length > 0
135
+ requeue_messages.each {|msg| queue.push(msg, false) }
138
136
 
139
- debug "Finished building report"
140
- data = serializers.serialize(report)
141
- json = JSON.fast_generate(data)
142
- begin
143
- debug json
144
- rescue Exception => e
145
- debug 'unable to print body'
146
- puts json
147
- end
148
- begin
149
- connection.write(json)
150
- rescue Exception => e
151
- error format('Failed send report: %s %s', e.inspect, e.backtrace)
152
- batch.each do |m|
153
- m.retries += 1
154
- queue.push(m, false)
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)
@@ -18,5 +18,5 @@
18
18
  # frozen_string_literal: true
19
19
 
20
20
  module Hoss
21
- VERSION = '1.0.1'
21
+ VERSION = '1.0.6'
22
22
  end
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.1
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-17 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby