-
Notifications
You must be signed in to change notification settings - Fork 111
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
[APP-6612] Support downloading logs #4660
base: main
Are you sure you want to change the base?
Conversation
9e3765b
to
2274d7a
Compare
2274d7a
to
788f538
Compare
788f538
to
c7849be
Compare
c7849be
to
0d596a6
Compare
0d596a6
to
386db8c
Compare
Dumb question -- were you aware we already had a way to download logs?
It's admittedly a bit unwieldy to discover that. |
@dgottlieb - I’m aware that we already have a way to download logs, but the current method prints them directly to the console. The new feature addresses interest in being able to save logs as a file (e.g., in text or JSON formats) for easier consumption, sharing, or further processing. I think this enhances the usability of the tool. |
Ah got it! The ticket wasn't clear on exactly what functionality was missing. I'm going to (strongly) recommend not adding another command altogether. And instead add this functionality to the existing From what you said, this adds to bits of functionality:
If you really* want to add an option for downloading, that's fine. But it is (very) typical to turn text output into a file with shell redirection, e.g:
But certainly for some commands (like curl) they default to stdout, but can additionally write to a file (using The other bit you mentioned -- giving the user a choice between text and json is very cool! I think you already went with |
@dgottlieb - Great point! I agree with your suggestion to extend the current functionality of the logs command rather than introducing a new command - it ensures consistency and avoids redundancy in the CLI. I'll proceed to modify the logs command to support saving logs to a file. |
cli/utils.go
Outdated
switch format { | ||
case "json": | ||
var err error | ||
output, err = json.MarshalIndent(logs, "", " ") |
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.
When outputting data as json, I think it's customary to output:
{"ts": 123, "message": "log line 1"}
{"ts": 124, "message": "log line 2"}
IIUC, this will instead output an array with 2 items:
[
{"ts": 123, "message": "log line 1"},
{"ts": 124, "message": "log line 2"}
]
Related to the above, the reason is because it is often difficult for json parsers/utilities to work with large lists efficiently/ergonomically.
This feels like a recipe to OOM. I've downloaded multi-GB log files
Haven't looked at the code yet but adding my own context on the work-- ideally this would bring the |
72c0738
to
921a908
Compare
removing myself since dan is already reviewing. if there is anything core specific that you want my opinion on, please retag me in a comment. my one request is that we do a follow up pr to include things that i mentioned in my comment above such as filters and time span. thanks joseph! |
I am going to stack another pr onto this one. |
…t arguments to be paired - either both are provided, or an error will be displated
…ds called on the *viamClient
cli/client.go
Outdated
@@ -619,6 +624,14 @@ func RobotsLogsAction(c *cli.Context, args robotsLogsArgs) error { | |||
return err | |||
} | |||
|
|||
// Validate required arguments | |||
if args.Output != "" && args.Format == "" { |
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.
[todo] remove
cli/client.go
Outdated
} | ||
|
||
// fetchAndSaveLogs fetches logs for all parts incrementally and saves them to a file. | ||
func (c *viamClient) fetchAndSaveLogs(parts []*apppb.RobotPart, args robotsLogsArgs) error { |
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.
[todo] have fetchAndSaveLogs io.writer, determine the formatting accordingly, and then write the formatted log to io.writer using fmt.fPrintln. Combine fetchAndSaveLogs and printLogsToConsole (essentially removing printLogsToConsole).
cli/client.go
Outdated
if args.Format == formatJSON { | ||
// Each log as a standalone JSON object | ||
if _, err := file.WriteString(formattedLog + "\n"); err != nil { | ||
return errors.Wrap(err, "failed to write log to file") |
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.
[todo] Change to fmt.fPrintln and accept a io.writter. [In order to do this we will need to change the signature of the function]
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.
Nice!
logsFlagOutputFile = "output" | ||
logsFlagErrors = "errors" | ||
logsFlagTail = "tail" | ||
logsFlagCount = "count" |
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.
Are we still limited to 10k log fetch at once? /Is a future ticket adding date ranges for log-grabbing?
This PR implements enhancements to the machines logs CLI command, including support for writing logs to a file in text or json format, while maintaining the ability to print logs to stdout. Below are the details and test cases for the command:
See ticket here
Print text format to console (stdout)
Command
Output
Print json format to console (stdout)
Command
Output
Write logs to a file in text format
Command
Output
Write logs to a file in json format
Command
Output
Invalid: Without any arguments
Command
Output
Missing
format
args, will default to text format and print logs to consoleCommand
Output
Invalid format - will print error to console
Command
Output