url logging

log the actual bind url (Server.bind_url),
rather than the connect url (Server.url),
which converts all-interfaces IPs to 'localhost'
This commit is contained in:
Min RK
2015-03-14 14:28:36 -06:00
parent 40ae3a5821
commit 5529774c1d
4 changed files with 30 additions and 8 deletions

View File

@@ -58,7 +58,7 @@ class ProxyAPIHandler(APIHandler):
if 'auth_token' in model: if 'auth_token' in model:
self.proxy.auth_token = model['auth_token'] self.proxy.auth_token = model['auth_token']
self.db.commit() self.db.commit()
self.log.info("Updated proxy at %s", server.url) self.log.info("Updated proxy at %s", server.bind_url)
yield self.proxy.check_routes() yield self.proxy.check_routes()

View File

@@ -705,13 +705,13 @@ class JupyterHub(Application):
if isinstance(e, HTTPError) and e.code == 403: if isinstance(e, HTTPError) and e.code == 403:
msg = "Did CONFIGPROXY_AUTH_TOKEN change?" msg = "Did CONFIGPROXY_AUTH_TOKEN change?"
else: else:
msg = "Is something else using %s?" % self.proxy.public_server.url msg = "Is something else using %s?" % self.proxy.public_server.bind_url
self.log.error("Proxy appears to be running at %s, but I can't access it (%s)\n%s", self.log.error("Proxy appears to be running at %s, but I can't access it (%s)\n%s",
self.proxy.public_server.url, e, msg) self.proxy.public_server.bind_url, e, msg)
self.exit(1) self.exit(1)
return return
else: else:
self.log.info("Proxy already running at: %s", self.proxy.public_server.url) self.log.info("Proxy already running at: %s", self.proxy.public_server.bind_url)
self.proxy_process = None self.proxy_process = None
return return
@@ -730,7 +730,7 @@ class JupyterHub(Application):
cmd.extend(['--ssl-key', self.ssl_key]) cmd.extend(['--ssl-key', self.ssl_key])
if self.ssl_cert: if self.ssl_cert:
cmd.extend(['--ssl-cert', self.ssl_cert]) cmd.extend(['--ssl-cert', self.ssl_cert])
self.log.info("Starting proxy @ %s", self.proxy.public_server.url) self.log.info("Starting proxy @ %s", self.proxy.public_server.bind_url)
self.log.debug("Proxy cmd: %s", cmd) self.log.debug("Proxy cmd: %s", cmd)
self.proxy_process = Popen(cmd, env=env) self.proxy_process = Popen(cmd, env=env)
def _check(): def _check():
@@ -978,7 +978,13 @@ class JupyterHub(Application):
# start the webserver # start the webserver
self.http_server = tornado.httpserver.HTTPServer(self.tornado_application, xheaders=True) self.http_server = tornado.httpserver.HTTPServer(self.tornado_application, xheaders=True)
self.http_server.listen(self.hub_port) try:
self.http_server.listen(self.hub_port)
except Exception:
self.log.error("Failed to bind hub to %s" % self.hub.server.bind_url)
raise
else:
self.log.info("Hub API listening on %s" % self.hub.server.bind_url)
# register cleanup on both TERM and INT # register cleanup on both TERM and INT
atexit.register(self.atexit) atexit.register(self.atexit)

View File

@@ -75,12 +75,16 @@ class Server(Base):
@property @property
def host(self): def host(self):
ip = self.ip
if ip in {'', '0.0.0.0'}:
# when listening on all interfaces, connect to localhost
ip = 'localhost'
return "{proto}://{ip}:{port}".format( return "{proto}://{ip}:{port}".format(
proto=self.proto, proto=self.proto,
ip=self.ip or 'localhost', ip=ip,
port=self.port, port=self.port,
) )
@property @property
def url(self): def url(self):
return "{host}{uri}".format( return "{host}{uri}".format(
@@ -88,6 +92,17 @@ class Server(Base):
uri=self.base_url, uri=self.base_url,
) )
@property
def bind_url(self):
"""representation of URL used for binding
Never used in APIs, only logging,
since it can be non-connectable value, such as '', meaning all interfaces.
"""
if self.ip in {'', '0.0.0.0'}:
return self.url.replace('localhost', self.ip or '*', 1)
return self.url
@gen.coroutine @gen.coroutine
def wait_up(self, timeout=10, http=False): def wait_up(self, timeout=10, http=False):
"""Wait for this server to come up""" """Wait for this server to come up"""

View File

@@ -21,6 +21,7 @@ def test_server(db):
assert isinstance(server.cookie_name, str) assert isinstance(server.cookie_name, str)
assert server.host == 'http://localhost:%i' % server.port assert server.host == 'http://localhost:%i' % server.port
assert server.url == server.host + '/' assert server.url == server.host + '/'
assert server.bind_url == 'http://*:%i/' % server.port
server.ip = '127.0.0.1' server.ip = '127.0.0.1'
assert server.host == 'http://127.0.0.1:%i' % server.port assert server.host == 'http://127.0.0.1:%i' % server.port
assert server.url == server.host + '/' assert server.url == server.host + '/'