Skip to content

Commit

Permalink
Use different naming convention & add test for it
Browse files Browse the repository at this point in the history
Experiments here informed the schema naming
recommendations in jupyter/telemetry#11
  • Loading branch information
yuvipanda authored and Zsailer committed May 19, 2020
1 parent 96bf2f0 commit 06b91e0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
2 changes: 1 addition & 1 deletion jupyter_server/event-schemas/contentsmanager-actions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "jupyter.org/contentsmanager-actions",
"$id": "eventlogging.jupyter.org/notebook/contentsmanager-actions",
"version": 1,
"title": "Contents Manager activities",
"description": "Notebook Server emits this event whenever a contentsmanager action happens",
Expand Down
30 changes: 30 additions & 0 deletions jupyter_server/event-schemas/contentsmanager-actions/v1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$id": "eventlogging.jupyter.org/notebook/contentsmanager-actions",
"version": 1,
"title": "Contents Manager activities",
"description": "Notebook Server emits this event whenever a contentsmanager action happens",
"type": "object",
"required": ["action", "path"],
"properties": {
"action": {
"enum": [
"get",
"create",
"save",
"upload",
"rename",
"create",
"copy"
],
"description": "Action performed by contents manager"
},
"path": {
"type": "string",
"description": "Logical path the action was performed in"
},
"source_path": {
"type": "string",
"description": "If action is 'copy', this specifies the source path"
}
}
}
17 changes: 8 additions & 9 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,15 +1765,14 @@ def _init_asyncio_patch():
def init_eventlog(self):
self.eventlog = EventLog(parent=self)

schemas_glob = os.path.join(
os.path.dirname(__file__),
'event-schemas',
'*.json'
)

for schema_file in glob(schemas_glob):
with open(schema_file) as f:
self.eventlog.register_schema(json.load(f))
event_schemas_dir = os.path.join(os.path.dirname(__file__), 'event-schemas')
# Recursively register all .json files under event-schemas
for dirname, _, files in os.walk(event_schemas_dir):
for file in files:
if file.endswith('.json'):
file_path = os.path.join(dirname, file)
with open(file_path) as f:
self.eventlog.register_schema(json.load(f))

@catch_config_error
def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
Expand Down
22 changes: 13 additions & 9 deletions jupyter_server/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
import json

from tornado import web

from jupyter_server.utils import url_path_join, url_escape, ensure_async
from jupyter_client.jsonutil import date_default

from jupyter_server.utils import (
url_path_join,
url_escape,
ensure_async,
eventlogging_schema_fqn
)
from jupyter_server.base.handlers import (
JupyterHandler, APIHandler, path_regex,
)
Expand Down Expand Up @@ -113,7 +117,7 @@ async def get(self, path=''):
validate_model(model, expect_content=content)
self._finish_model(model, location=False)
self.eventlog.record_event(
'jupyter.org/contentsmanager-actions', 1,
eventlogging_schema_fqn('contentsmanager-actions'), 1,
{ 'action': 'get', 'path': model['path'] }
)

Expand All @@ -130,7 +134,7 @@ async def patch(self, path=''):
self._finish_model(model)
self.log.info(model)
self.eventlog.record_event(
'jupyter.org/contentsmanager-actions', 1,
eventlogging_schema_fqn('contentsmanager-actions'), 1,
# FIXME: 'path' always has a leading slash, while model['path'] does not.
# What to do here for source_path? path munge manually? Eww
{ 'action': 'rename', 'path': model['path'], 'source_path': path }
Expand All @@ -148,7 +152,7 @@ async def _copy(self, copy_from, copy_to=None):
validate_model(model, expect_content=False)
self._finish_model(model)
self.eventlog.record_event(
'jupyter.org/contentsmanager-actions', 1,
eventlogging_schema_fqn('contentsmanager-actions'), 1,
{ 'action': 'copy', 'path': model['path'], 'source_path': copy_from }
)

Expand All @@ -160,7 +164,7 @@ async def _upload(self, model, path):
validate_model(model, expect_content=False)
self._finish_model(model)
self.eventlog.record_event(
'jupyter.org/contentsmanager-actions', 1,
eventlogging_schema_fqn('contentsmanager-actions'), 1,
{ 'action': 'upload', 'path': model['path'] }
)

Expand All @@ -172,7 +176,7 @@ async def _new_untitled(self, path, type='', ext=''):
validate_model(model, expect_content=False)
self._finish_model(model)
self.eventlog.record_event(
'jupyter.org/contentsmanager-actions', 1,
eventlogging_schema_fqn('contentsmanager-actions'), 1,
# Set path to path of created object, not directory it was created in
{ 'action': 'create', 'path': model['path'] }
)
Expand All @@ -187,7 +191,7 @@ async def _save(self, model, path):
self._finish_model(model)

self.eventlog.record_event(
'jupyter.org/contentsmanager-actions', 1,
eventlogging_schema_fqn('contentsmanager-actions'), 1,
{ 'action': 'save', 'path': model['path'] }
)

Expand Down Expand Up @@ -260,7 +264,7 @@ async def delete(self, path=''):
self.set_status(204)
self.finish()
self.eventlog.record_event(
'jupyter.org/contentsmanager-actions', 1,
eventlogging_schema_fqn('contentsmanager-actions'), 1,
{ 'action': 'delete', 'path': path }
)

Expand Down
9 changes: 9 additions & 0 deletions jupyter_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,12 @@ def wrapped():
result = asyncio.ensure_future(maybe_async)
return result
return wrapped()


def eventlogging_schema_fqn(name):
"""
Return fully qualified event schema name
Matches convention for this particular repo
"""
return 'eventlogging.jupyter.org/notebook/{}'.format(name)

0 comments on commit 06b91e0

Please sign in to comment.