instana 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/instana/agent.rb +75 -26
- data/lib/instana/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e23278bff6774c0cc9d5d3a82677044c03db4f
|
4
|
+
data.tar.gz: 0ff491c646782556866bfa6c0751e22f19f6dca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82e66f9aae2e19b921332f6daecd7e184ee6e98fa38802490bcd291ea35881ebc0b1396def590b8825542b40932513aa959ab69a488234fbf0f0bd6c99e8952
|
7
|
+
data.tar.gz: 013a6f0b98e114cfecca44c05b47b2b8af4e365398e71d3133ae796a671812e3e05ca829ae368c51d38ea068cc61364a713e10c2180bd700f9b04b9edad05275
|
data/lib/instana/agent.rb
CHANGED
@@ -15,10 +15,6 @@ module Instana
|
|
15
15
|
DISCOVERY_PATH = 'com.instana.plugin.ruby.discovery'.freeze
|
16
16
|
|
17
17
|
def initialize
|
18
|
-
# Host agent defaults. Can be configured via Instana.config
|
19
|
-
@host = LOCALHOST
|
20
|
-
@port = 42699
|
21
|
-
|
22
18
|
# Supported two states (unannounced & announced)
|
23
19
|
@state = :unannounced
|
24
20
|
|
@@ -54,7 +50,11 @@ module Instana
|
|
54
50
|
# The agent UUID returned from the host agent
|
55
51
|
@agent_uuid = nil
|
56
52
|
|
53
|
+
# Collect process information
|
57
54
|
@process = ::Instana::Util.collect_process_info
|
55
|
+
|
56
|
+
# This will hold info on the discovered agent host
|
57
|
+
@discovered = nil
|
58
58
|
end
|
59
59
|
|
60
60
|
# Used post fork to re-initialize state and restart communications with
|
@@ -162,15 +162,20 @@ module Instana
|
|
162
162
|
# the host agent.
|
163
163
|
#
|
164
164
|
def announce_sensor
|
165
|
+
unless @discovered
|
166
|
+
::Instana.logger.agent("#{__method__} called but discovery hasn't run yet!")
|
167
|
+
return false
|
168
|
+
end
|
169
|
+
|
165
170
|
announce_payload = {}
|
166
171
|
announce_payload[:pid] = pid_namespace? ? get_real_pid : Process.pid
|
167
172
|
announce_payload[:args] = @process[:arguments]
|
168
173
|
|
169
|
-
uri = URI.parse("http://#{@
|
174
|
+
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH}")
|
170
175
|
req = Net::HTTP::Put.new(uri)
|
171
176
|
req.body = announce_payload.to_json
|
172
177
|
|
173
|
-
::Instana.logger.agent "Announce: http://#{@
|
178
|
+
::Instana.logger.agent "Announce: http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{DISCOVERY_PATH} - payload: #{req.body}"
|
174
179
|
|
175
180
|
response = make_host_agent_request(req)
|
176
181
|
|
@@ -193,9 +198,14 @@ module Instana
|
|
193
198
|
# @param paylod [Hash] The collection of metrics to report.
|
194
199
|
#
|
195
200
|
def report_entity_data(payload)
|
201
|
+
unless @discovered
|
202
|
+
::Instana.logger.agent("#{__method__} called but discovery hasn't run yet!")
|
203
|
+
return false
|
204
|
+
end
|
205
|
+
|
196
206
|
with_snapshot = false
|
197
207
|
path = "com.instana.plugin.ruby.#{@process[:report_pid]}"
|
198
|
-
uri = URI.parse("http://#{@
|
208
|
+
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
|
199
209
|
req = Net::HTTP::Post.new(uri)
|
200
210
|
|
201
211
|
# Every 5 minutes, send snapshot data as well
|
@@ -253,7 +263,7 @@ module Instana
|
|
253
263
|
end
|
254
264
|
|
255
265
|
path = "com.instana.plugin.ruby/response.#{@process[:report_pid]}?messageId=#{URI.encode(their_request['messageId'])}"
|
256
|
-
uri = URI.parse("http://#{@
|
266
|
+
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
|
257
267
|
req = Net::HTTP::Post.new(uri)
|
258
268
|
req.body = payload.to_json
|
259
269
|
::Instana.logger.agent_response "Responding to agent: #{req.inspect}"
|
@@ -268,8 +278,13 @@ module Instana
|
|
268
278
|
def report_spans(spans)
|
269
279
|
return unless @state == :announced
|
270
280
|
|
281
|
+
unless @discovered
|
282
|
+
::Instana.logger.agent("#{__method__} called but discovery hasn't run yet!")
|
283
|
+
return false
|
284
|
+
end
|
285
|
+
|
271
286
|
path = "com.instana.plugin.ruby/traces.#{@process[:report_pid]}"
|
272
|
-
uri = URI.parse("http://#{@
|
287
|
+
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/#{path}")
|
273
288
|
req = Net::HTTP::Post.new(uri)
|
274
289
|
|
275
290
|
req.body = spans.to_json
|
@@ -290,39 +305,73 @@ module Instana
|
|
290
305
|
|
291
306
|
# Check that the host agent is available and can be contacted. This will
|
292
307
|
# first check localhost and if not, then attempt on the default gateway
|
293
|
-
# for docker in bridged mode.
|
294
|
-
# in @host that is used in subsequent HTTP calls.
|
308
|
+
# for docker in bridged mode.
|
295
309
|
#
|
296
310
|
def host_agent_ready?
|
297
|
-
|
298
|
-
|
311
|
+
@discovered ||= run_discovery
|
312
|
+
|
313
|
+
if @discovered
|
314
|
+
# Try default location or manually configured (if so)
|
315
|
+
uri = URI.parse("http://#{@discovered[:agent_host]}:#{@discovered[:agent_port]}/")
|
316
|
+
req = Net::HTTP::Get.new(uri)
|
317
|
+
|
318
|
+
response = make_host_agent_request(req)
|
319
|
+
|
320
|
+
if response && (response.code.to_i == 200)
|
321
|
+
return true
|
322
|
+
end
|
323
|
+
end
|
324
|
+
false
|
325
|
+
rescue => e
|
326
|
+
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
327
|
+
Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test?
|
328
|
+
return false
|
329
|
+
end
|
330
|
+
|
331
|
+
# Runs a discovery process to determine where we can contact the host agent. This is usually just
|
332
|
+
# localhost but in docker can be found on the default gateway. This also allows for manual
|
333
|
+
# configuration via ::Instana.config[:agent_host/port].
|
334
|
+
#
|
335
|
+
# @return [Hash] a hash with :agent_host, :agent_port values or empty hash
|
336
|
+
#
|
337
|
+
def run_discovery
|
338
|
+
discovered = {}
|
339
|
+
|
340
|
+
::Instana.logger.debug "#{__method__}: Running agent discovery..."
|
341
|
+
|
342
|
+
# Try default location or manually configured (if so)
|
343
|
+
uri = URI.parse("http://#{::Instana.config[:agent_host]}:#{::Instana.config[:agent_port]}/")
|
299
344
|
req = Net::HTTP::Get.new(uri)
|
300
345
|
|
346
|
+
::Instana.logger.debug "#{__method__}: Trying #{::Instana.config[:agent_host]}:#{::Instana.config[:agent_port]}"
|
347
|
+
|
301
348
|
response = make_host_agent_request(req)
|
302
349
|
|
303
350
|
if response && (response.code.to_i == 200)
|
304
|
-
|
305
|
-
|
351
|
+
discovered[:agent_host] = ::Instana.config[:agent_host]
|
352
|
+
discovered[:agent_port] = ::Instana.config[:agent_port]
|
353
|
+
::Instana.logger.debug "#{__method__}: Found #{discovered[:agent_host]}:#{discovered[:agent_port]}"
|
354
|
+
return discovered
|
306
355
|
end
|
307
356
|
|
308
|
-
return
|
357
|
+
return nil unless @is_linux
|
309
358
|
|
310
359
|
# We are potentially running on Docker in bridged networking mode.
|
311
360
|
# Attempt to contact default gateway
|
312
|
-
uri = URI.parse("http://#{@default_gateway}:#{
|
361
|
+
uri = URI.parse("http://#{@default_gateway}:#{::Instana.config[:agent_port]}/")
|
313
362
|
req = Net::HTTP::Get.new(uri)
|
314
363
|
|
364
|
+
::Instana.logger.debug "#{__method__}: Trying default gateway #{@default_gateway}:#{::Instana.config[:agent_port]}"
|
365
|
+
|
315
366
|
response = make_host_agent_request(req)
|
316
367
|
|
317
368
|
if response && (response.code.to_i == 200)
|
318
|
-
|
319
|
-
|
369
|
+
discovered[:agent_host] = @default_gateway
|
370
|
+
discovered[:agent_port] = ::Instana.config[:agent_port]
|
371
|
+
::Instana.logger.debug "#{__method__}: Found #{discovered[:agent_host]}:#{discovered[:agent_port]}"
|
372
|
+
return discovered
|
320
373
|
end
|
321
|
-
|
322
|
-
rescue => e
|
323
|
-
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
324
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
325
|
-
return false
|
374
|
+
nil
|
326
375
|
end
|
327
376
|
|
328
377
|
# Returns the PID that we are reporting to
|
@@ -346,7 +395,7 @@ module Instana
|
|
346
395
|
@state == :announced
|
347
396
|
rescue => e
|
348
397
|
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
349
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
398
|
+
Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test?
|
350
399
|
return false
|
351
400
|
end
|
352
401
|
|
@@ -403,7 +452,7 @@ module Instana
|
|
403
452
|
return nil
|
404
453
|
rescue => e
|
405
454
|
Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
406
|
-
Instana.logger.debug e.backtrace.join("\r\n")
|
455
|
+
Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test?
|
407
456
|
return nil
|
408
457
|
end
|
409
458
|
|
data/lib/instana/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Giacomo Lombardo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|