-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add activity watching to kernels #1827
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b472c55
add activity watching to kernels
minrk d45cb2a
track active kernel connections
minrk 9f55a85
use Z isoformat in UTC timestamps
minrk bec3963
add connections to sessions API tests
minrk 8b76de8
move tz utils to top-level private module ._tz
minrk 32a3533
track REST API activity
minrk 75a0d71
give the server a second to notice that the websocket closed
minrk 2a5f8d2
add token auth to kernel websocket test
minrk dc873f1
use self.request in status test
minrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# encoding: utf-8 | ||
""" | ||
Timezone utilities | ||
|
||
Just UTC-awareness right now | ||
""" | ||
|
||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
from datetime import tzinfo, timedelta, datetime | ||
|
||
# constant for zero offset | ||
ZERO = timedelta(0) | ||
|
||
class tzUTC(tzinfo): | ||
"""tzinfo object for UTC (zero offset)""" | ||
|
||
def utcoffset(self, d): | ||
return ZERO | ||
|
||
def dst(self, d): | ||
return ZERO | ||
|
||
UTC = tzUTC() | ||
|
||
def utc_aware(unaware): | ||
"""decorator for adding UTC tzinfo to datetime's utcfoo methods""" | ||
def utc_method(*args, **kwargs): | ||
dt = unaware(*args, **kwargs) | ||
return dt.replace(tzinfo=UTC) | ||
return utc_method | ||
|
||
utcfromtimestamp = utc_aware(datetime.utcfromtimestamp) | ||
utcnow = utc_aware(datetime.utcnow) | ||
|
||
def isoformat(dt): | ||
"""Return iso-formatted timestamp | ||
|
||
Like .isoformat(), but uses Z for UTC instead of +00:00 | ||
""" | ||
return dt.isoformat().replace('+00:00', 'Z') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Test the basic /api endpoints""" | ||
|
||
import requests | ||
|
||
from notebook._tz import isoformat | ||
from notebook.utils import url_path_join | ||
from notebook.tests.launchnotebook import NotebookTestBase | ||
|
||
|
||
class KernelAPITest(NotebookTestBase): | ||
"""Test the kernels web service API""" | ||
|
||
def _req(self, verb, path, **kwargs): | ||
r = self.request(verb, url_path_join('api', path)) | ||
r.raise_for_status() | ||
return r | ||
|
||
def get(self, path, **kwargs): | ||
return self._req('GET', path) | ||
|
||
def test_get_spec(self): | ||
r = self.get('spec.yaml') | ||
assert r.text | ||
|
||
def test_get_status(self): | ||
r = self.get('status') | ||
data = r.json() | ||
assert data['connections'] == 0 | ||
assert data['kernels'] == 0 | ||
assert data['last_activity'].endswith('Z') | ||
assert data['started'].endswith('Z') | ||
assert data['started'] == isoformat(self.notebook.web_app.settings['started']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this explicitly be UTC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are explicitly timezone-aware, and UTC as an implementation detail. I'll add that detail, though.