Add eventlogging infrastructure

- Introduce the EventLog class from BinderHub for emitting
  structured event data
- Instrument server starts and stops to emit events
- Defaults to not saving any events anywhere
This commit is contained in:
yuvipanda
2019-05-02 16:10:45 -07:00
committed by Zsailer
parent 7d9a93ab5f
commit 41b2e6e401
4 changed files with 167 additions and 0 deletions

View File

@@ -156,6 +156,10 @@ class BaseHandler(RequestHandler):
def oauth_provider(self):
return self.settings['oauth_provider']
@property
def event_log(self):
return self.settings['event_log']
def finish(self, *args, **kwargs):
"""Roll back any uncommitted transactions from the handler."""
if self.db.dirty:
@@ -846,6 +850,11 @@ class BaseHandler(RequestHandler):
SERVER_SPAWN_DURATION_SECONDS.labels(
status=ServerSpawnStatus.success
).observe(time.perf_counter() - spawn_start_time)
self.event_log.emit('hub.jupyter.org/server-action', 1, {
'action': 'start',
'username': user.name,
'servername': server_name
})
proxy_add_start_time = time.perf_counter()
spawner._proxy_pending = True
try:
@@ -1026,6 +1035,11 @@ class BaseHandler(RequestHandler):
SERVER_STOP_DURATION_SECONDS.labels(
status=ServerStopStatus.success
).observe(toc - tic)
self.event_log.emit('hub.jupyter.org/server-action', 1, {
'action': 'stop',
'username': user.name,
'servername': server_name
})
except:
SERVER_STOP_DURATION_SECONDS.labels(
status=ServerStopStatus.failure