Skip to content

Commit

Permalink
Add additional logging into the websocket proxy for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Jun 26, 2017
1 parent ed1af7c commit 73163cd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions 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:'
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/websocket_server.rb
Expand Up @@ -62,7 +62,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
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/websocket_proxy_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 73163cd

Please sign in to comment.