lib/instana/agent.rb in instana-1.4.9 vs lib/instana/agent.rb in instana-1.4.11
- old
+ new
@@ -42,10 +42,14 @@
@default_gateway = `/sbin/ip route | awk '/default/ { print $3 }'`.chomp
else
@default_gateway = nil
end
+ # Re-useable HTTP client for communication with
+ # the host agent.
+ @httpclient = nil
+
# Collect initial process info - repeat prior to announce
# in `announce_sensor` in case of process rename, after fork etc.
@process = ::Instana::Util.collect_process_info
# The agent UUID returned from the host agent
@@ -202,11 +206,11 @@
true
else
false
end
rescue => e
- Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
+ Instana.logger.info "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
return false
ensure
socket.close if socket
end
@@ -243,11 +247,11 @@
end
end
false
rescue => e
- Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
+ Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n")
end
# When a request is received by the host agent, it is sent here
# from processing and response.
@@ -326,11 +330,11 @@
return true
end
end
false
rescue => e
- Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
+ Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test?
return false
end
# Runs a discovery process to determine where we can contact the host agent. This is usually just
@@ -422,13 +426,15 @@
# Reset the entity timer
@entity_last_seen = Time.now
when :unannounced
@state = :unannounced
+ # Reset our HTTP client
+ @httpclient = nil
else
- ::Instana.logger.warn "Uknown agent state: #{state}"
+ ::Instana.logger.debug "Uknown agent state: #{state}"
end
::Instana.collector.reset_timer!
true
end
@@ -441,19 +447,23 @@
#
def make_host_agent_request(req)
req['Accept'] = MIME_JSON
req['Content-Type'] = MIME_JSON
- response = nil
- Net::HTTP.start(req.uri.hostname, req.uri.port, :open_timeout => 1, :read_timeout => 1) do |http|
- response = http.request(req)
+ if @state == :unannounced
+ @httpclient = Net::HTTP.new(req.uri.hostname, req.uri.port)
+ @httpclient.open_timeout = 1
+ @httpclient.read_timeout = 1
end
+
+ response = @httpclient.request(req)
::Instana.logger.agent_comm "#{req.method}->#{req.uri} body:(#{req.body}) Response:#{response} body:(#{response.body})"
+
response
rescue Errno::ECONNREFUSED
return nil
rescue => e
- Instana.logger.error "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
+ Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test?
return nil
end
# Indicates whether we are running in a pid namespace (such as