instana 0.8.3 → 0.8.4

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
  SHA1:
3
- metadata.gz: cf63c6985d10b3ce5403036d809fb7bf7aff1e25
4
- data.tar.gz: 790c3025b8282144f1acd64d4bdf5afb5ad011c9
3
+ metadata.gz: 4cb7dba41c21a606e4cdbfa46abe2f365235cd6a
4
+ data.tar.gz: 45236a2a90db9f2b559808febe3bd03007c35bc3
5
5
  SHA512:
6
- metadata.gz: e132178b3619e5c16a954dec186d771e8606a78156f4c8c8ebddab3b2ba10d46d78a444b81f07497948362888e33face1e6a401f52fbf8f98c9492e3bfa9c95a
7
- data.tar.gz: 5bc7cf25c2deeb665b3a71a2202df5911783501727f5df174ff605ab72c2278560897c0b785f3d5e66801d219fe560ef4e78c8a2e7b4cbe53874a0f8dddc8089
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
- @request_timeout = 5000
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
- path = 'com.instana.plugin.ruby.discovery'
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
- uri = URI.parse("http://#{@host}:#{@port}/")
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
- (response && response.code.to_i == 200) ? true : false
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['Accept'] = 'application/json'
206
- req['Content-Type'] = 'application/json'
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
  #
@@ -1,3 +1,3 @@
1
1
  module Instana
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
3
3
  end
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.3
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-14 00:00:00.000000000 Z
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler