instana 0.8.3 → 0.8.4
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/instana/agent.rb +40 -11
- 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: 4cb7dba41c21a606e4cdbfa46abe2f365235cd6a
|
4
|
+
data.tar.gz: 45236a2a90db9f2b559808febe3bd03007c35bc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94e3a10570b4a2513dd2ecd26bf1cae2e2d08dedcf165cbd30e549a3ce49003cc3bcca943de158959c55fed7d44cd2504a57855f97486e239561e0c6baaff4fa
|
7
|
+
data.tar.gz: 4f9e776398af412dd270bfe61b6d73d140780b32217d101ed0340ef04b60fc33a7642d8f173c7fb59d649bf3c814479da7ca3bfc5294f70f6c46ecda84775cc9
|
data/lib/instana/agent.rb
CHANGED
@@ -9,12 +9,14 @@ module Instana
|
|
9
9
|
class Agent
|
10
10
|
attr_accessor :state
|
11
11
|
|
12
|
+
LOCALHOST = '127.0.0.1'.freeze
|
13
|
+
MIME_JSON = 'application/json'.freeze
|
14
|
+
DISCOVERY_PATH = 'com.instana.plugin.ruby.discovery'.freeze
|
15
|
+
|
12
16
|
def initialize
|
13
17
|
# Host agent defaults. Can be configured via Instana.config
|
14
|
-
@
|
15
|
-
@host = '127.0.0.1'
|
18
|
+
@host = LOCALHOST
|
16
19
|
@port = 42699
|
17
|
-
@server_header = 'Instana Agent'
|
18
20
|
|
19
21
|
# Supported two states (unannounced & announced)
|
20
22
|
@state = :unannounced
|
@@ -35,6 +37,13 @@ module Instana
|
|
35
37
|
@timers = ::Timers::Group.new
|
36
38
|
@announce_timer = nil
|
37
39
|
@collect_timer = nil
|
40
|
+
|
41
|
+
# Detect if we're on linux or not (used in host_agent_ready?)
|
42
|
+
@is_linux = (RUBY_PLATFORM =~ /linux/i) ? true : false
|
43
|
+
|
44
|
+
# In case we're running in Docker, have the default gateway available
|
45
|
+
# to check in case we're running in bridged network mode
|
46
|
+
@default_gateway = `/sbin/ip route | awk '/default/ { print $3 }'`.chomp
|
38
47
|
end
|
39
48
|
|
40
49
|
##
|
@@ -99,8 +108,7 @@ module Instana
|
|
99
108
|
arguments.shift
|
100
109
|
announce_payload[:args] = arguments
|
101
110
|
|
102
|
-
|
103
|
-
uri = URI.parse("http://#{@host}:#{@port}/#{path}")
|
111
|
+
uri = URI.parse("http://#{@host}:#{@port}/#{DISCOVERY_PATH}")
|
104
112
|
req = Net::HTTP::Put.new(uri)
|
105
113
|
req.body = announce_payload.to_json
|
106
114
|
|
@@ -152,15 +160,37 @@ module Instana
|
|
152
160
|
##
|
153
161
|
# host_agent_ready?
|
154
162
|
#
|
155
|
-
# Check that the host agent is available and can be contacted.
|
163
|
+
# Check that the host agent is available and can be contacted. This will
|
164
|
+
# first check localhost and if not, then attempt on the default gateway
|
165
|
+
# for docker in bridged mode. It will save where it found the host agent
|
166
|
+
# in @host that is used in subsequent HTTP calls.
|
156
167
|
#
|
157
168
|
def host_agent_ready?
|
158
|
-
|
169
|
+
# Localhost
|
170
|
+
uri = URI.parse("http://#{LOCALHOST}:#{@port}/")
|
171
|
+
req = Net::HTTP::Get.new(uri)
|
172
|
+
|
173
|
+
response = make_host_agent_request(req)
|
174
|
+
|
175
|
+
if response && (response.code.to_i == 200)
|
176
|
+
@host = LOCALHOST
|
177
|
+
return true
|
178
|
+
end
|
179
|
+
|
180
|
+
return false unless @is_linux
|
181
|
+
|
182
|
+
# We are potentially running on Docker in bridged networking mode.
|
183
|
+
# Attempt to contact default gateway
|
184
|
+
uri = URI.parse("http://#{@default_gateway}:#{@port}/")
|
159
185
|
req = Net::HTTP::Get.new(uri)
|
160
186
|
|
161
187
|
response = make_host_agent_request(req)
|
162
188
|
|
163
|
-
|
189
|
+
if response && (response.code.to_i == 200)
|
190
|
+
@host = @default_gateway
|
191
|
+
return true
|
192
|
+
end
|
193
|
+
false
|
164
194
|
rescue => e
|
165
195
|
Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
166
196
|
Instana.logger.debug e.backtrace.join("\r\n")
|
@@ -202,8 +232,8 @@ module Instana
|
|
202
232
|
# of type Net::HTTP::Get|Put|Head
|
203
233
|
#
|
204
234
|
def make_host_agent_request(req)
|
205
|
-
req[
|
206
|
-
req['Content-Type'] =
|
235
|
+
req[:Accept] = MIME_JSON
|
236
|
+
req[:'Content-Type'] = MIME_JSON
|
207
237
|
|
208
238
|
response = nil
|
209
239
|
Net::HTTP.start(req.uri.hostname, req.uri.port, :open_timeout => 1, :read_timeout => 1) do |http|
|
@@ -218,7 +248,6 @@ module Instana
|
|
218
248
|
return nil
|
219
249
|
end
|
220
250
|
|
221
|
-
private
|
222
251
|
##
|
223
252
|
# take_snapshot
|
224
253
|
#
|
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: 0.8.
|
4
|
+
version: 0.8.4
|
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: 2016-11-
|
11
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|