-
Notifications
You must be signed in to change notification settings - Fork 22
feat(notebooks): support logs PS-13712 #296
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,7 +11,8 @@ | |
| from gradient.api_sdk import sdk_exceptions | ||
| from gradient.cli_constants import CLI_PS_CLIENT_NAME | ||
| from gradient.cliutils import get_terminal_lines | ||
| from gradient.commands.common import BaseCommand, ListCommandMixin, DetailsCommandMixin, StreamMetricsCommand | ||
| from gradient.commands.common import BaseCommand, ListCommandMixin, DetailsCommandMixin, StreamMetricsCommand, \ | ||
| LogsCommandMixin | ||
|
|
||
|
|
||
| @six.add_metaclass(abc.ABCMeta) | ||
|
|
@@ -156,49 +157,6 @@ class StreamNotebookMetricsCommand(StreamMetricsCommand, BaseNotebookCommand): | |
| pass | ||
|
|
||
|
|
||
| class NotebookLogsCommand(BaseNotebookCommand): | ||
|
|
||
| def execute(self, notebook_id, line, limit, follow): | ||
| if follow: | ||
| self.logger.log("Awaiting logs...") | ||
| self._log_logs_continuously(notebook_id, line, limit) | ||
| else: | ||
| self._log_table_of_logs(notebook_id, line, limit) | ||
|
|
||
| def _log_table_of_logs(self, notebook_id, line, limit): | ||
| logs = self.client.logs(notebook_id, line, limit) | ||
| if not logs: | ||
| self.logger.log("No logs found") | ||
| return | ||
|
|
||
| table_str = self._make_table(logs, notebook_id) | ||
| if len(table_str.splitlines()) > get_terminal_lines(): | ||
| pydoc.pager(table_str) | ||
| else: | ||
| self.logger.log(table_str) | ||
|
|
||
| def _log_logs_continuously(self, notebook_id, line, limit): | ||
| logs_gen = self.client.yield_logs(notebook_id, line, limit) | ||
| for log in logs_gen: | ||
| log_msg = "{}\t{}".format(*self._format_row(log)) | ||
| self.logger.log(log_msg) | ||
|
|
||
| @staticmethod | ||
| def _format_row(log_row): | ||
| return (style(fg="red", text=str(log_row.line)), | ||
| log_row.message) | ||
|
|
||
| def _make_table(self, logs, notebook_id): | ||
| table_title = "Notebook %s logs" % notebook_id | ||
| table_data = [("LINE", "MESSAGE")] | ||
| table = terminaltables.AsciiTable(table_data, title=table_title) | ||
|
|
||
| for log in logs: | ||
| table_data.append(self._format_row(log)) | ||
|
|
||
| return table.table | ||
|
|
||
|
|
||
| class ArtifactsListCommand(BaseNotebookCommand): | ||
| WAITING_FOR_RESPONSE_MESSAGE = "Waiting for data..." | ||
|
|
||
|
|
@@ -249,3 +207,7 @@ def _make_table(table_data): | |
| ascii_table = terminaltables.AsciiTable(table_data) | ||
| table_string = ascii_table.table | ||
| return table_string | ||
|
|
||
|
|
||
| class NotebookLogsCommand(LogsCommandMixin, BaseNotebookCommand): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again: Why is this class moved to the end of the file? |
||
| ENTITY = "Notebook" | ||
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.
Why is this moved to the end of the class? You could have implemented those methods without moving them around.
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.
Doing changes this way makes it harder to read git file history