From 7ab4ecd7324dc5f5d3f0c9ddf58eeed1625590de Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Tue, 4 Jul 2017 13:15:41 +0200 Subject: [PATCH] Merge pull request #15428 from skateman/websocket-logging Add additional logging into the websocket proxy for easier debugging (cherry picked from commit f2d73802fef77276405aa5eaa2acfd2df31fb230) https://bugzilla.redhat.com/show_bug.cgi?id=1468613 --- lib/websocket_proxy.rb | 6 ++++-- lib/websocket_server.rb | 2 +- spec/lib/websocket_proxy_spec.rb | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/websocket_proxy.rb b/lib/websocket_proxy.rb index c4ba4c6d934..941f33c7848 100644 --- a/lib/websocket_proxy.rb +++ b/lib/websocket_proxy.rb @@ -1,10 +1,11 @@ class WebsocketProxy attr_reader :env, :url, :error - def initialize(env, console) + def initialize(env, console, logger) @env = env @id = SecureRandom.uuid @console = console + @logger = logger secure = Rack::Request.new(env).ssl? scheme = secure ? 'wss:' : 'ws:' @@ -17,7 +18,8 @@ def initialize(env, console) # Set up the socket client for the proxy @sock = TCPSocket.open(@console.host_name, @console.port) init_ssl if @console.ssl - rescue + rescue => ex + @logger.error(ex) @error = true end diff --git a/lib/websocket_server.rb b/lib/websocket_server.rb index a432f33bf62..e5602740e3b 100644 --- a/lib/websocket_server.rb +++ b/lib/websocket_server.rb @@ -64,7 +64,7 @@ def healthy? def init_proxy(env, url) console = SystemConsole.find_by!(:url_secret => url) - proxy = WebsocketProxy.new(env, console) + proxy = WebsocketProxy.new(env, console, logger) return proxy.cleanup if proxy.error logger.info("Starting websocket proxy for VM #{console.vm_id}") proxy.start diff --git a/spec/lib/websocket_proxy_spec.rb b/spec/lib/websocket_proxy_spec.rb index 6ec0c100108..8414ff25ffb 100644 --- a/spec/lib/websocket_proxy_spec.rb +++ b/spec/lib/websocket_proxy_spec.rb @@ -2,9 +2,10 @@ let(:console) { FactoryGirl.create(:system_console) } let(:host) { '127.0.0.1:8080' } let(:uri) { '/ws/console/123456789' } + let(:logger) { double } let(:env) { {'HTTP_HOST' => host, 'REQUEST_URI' => uri, 'rack.hijack' => -> {}} } - subject { described_class.new(env, console) } + subject { described_class.new(env, console, logger) } describe '#initialize' do it 'sets the URL' do