-
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] Add Filters for Downloading Logs #4673
Changes from 27 commits
386db8c
232f143
6a02466
e14e9be
761d6fe
05dc2c2
921a908
690b887
e2786a5
225b5cb
b0698af
b3e00d3
bf0df5f
7abd091
0c6c6f9
b292477
0d65512
791cda4
774614b
6a8138e
410bad0
f281e27
f35b373
575f98e
c164165
2f273e2
ef5db1a
b8a5d77
21d27c6
8a30121
0c77e33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. @jr22 - Is there a reason we don't have unit tests for this function's helpers? Should I add unit tests? 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. not a reason that im aware of, feel free to add test coverage if you want! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -747,7 +747,10 @@ type robotsLogsArgs struct { | |
Machine string | ||
Output string | ||
Format string | ||
Errors bool | ||
Keyword string | ||
Levels []string | ||
Start string | ||
End string | ||
Count int | ||
} | ||
|
||
|
@@ -758,6 +761,16 @@ func RobotsLogsAction(c *cli.Context, args robotsLogsArgs) error { | |
return err | ||
} | ||
|
||
// Check if both start time and count are provided | ||
if args.Start != "" && args.Count > 0 && args.End == "" { | ||
return errors.New("unsupported functionality: specifying both a start time and a count without an end time is not supported. " + | ||
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. do we need this? i feel like this is explaining weirdness in our code to our users which we shouldn't do. May make more sense to make this a comment rather than something user facing and just say this is unsupported to the user 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. (I know this is out of scope, but this behaviour is also counter-intuitive to me). Other logs api's support this: https://docs.aws.amazon.com/ja_jp/AmazonCloudWatchLogs/latest/APIReference/API_StartQuery.html so why don't we? 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. I agree that this functionality is something we really need to support but it will require changing the app's api to support sorting the order of the logs (currently we default to descending order for time) even though I would love to implement the sorting functionality now, it's out of the scope of the pr and I am not sure we want to prioritize more resources to this now. I think we wanted to leave this comment so that it screams out to us that it needs to be addressed 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. can you make a ticket to add this in as something in the backloig? and link this code? I agree that theres nothing to change here as part of the ticket, but wondered if there was something we could do without having to change the API 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. Good call! I have a ticket cut, I will add it to the code |
||
"This behavior can be counterintuitive because logs are currently only sorted in descending order. " + | ||
"For example, if there are 200 logs after the specified start time and you request 10 logs, it will return the 10 most recent logs, " + | ||
"rather than the 10 logs closest to the start time. " + | ||
"Please provide either a start time and an end time to define a clear range, or a count without a start time for recent logs", | ||
) | ||
} | ||
|
||
orgStr := args.Organization | ||
locStr := args.Location | ||
robotStr := args.Machine | ||
|
@@ -823,32 +836,39 @@ func (c *viamClient) streamLogsForPart(part *apppb.RobotPart, args robotsLogsArg | |
return err | ||
} | ||
|
||
startTime, err := parseTimeString(args.Start) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid start time format") | ||
} | ||
endTime, err := parseTimeString(args.End) | ||
if err != nil { | ||
return errors.Wrap(err, "invalid end time format") | ||
} | ||
|
||
// Write logs for this part | ||
var pageToken string | ||
for logsFetched := 0; logsFetched < numLogs; { | ||
remainingLogs := int64(numLogs - logsFetched) | ||
if remainingLogs > 100 { | ||
remainingLogs = int64(100) | ||
} | ||
resp, err := c.client.GetRobotPartLogs(c.c.Context, &apppb.GetRobotPartLogsRequest{ | ||
Id: part.Id, | ||
ErrorsOnly: args.Errors, | ||
PageToken: &pageToken, | ||
Id: part.Id, | ||
Filter: &args.Keyword, | ||
PageToken: &pageToken, | ||
Levels: args.Levels, | ||
Start: startTime, | ||
End: endTime, | ||
Limit: &remainingLogs, | ||
}) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to fetch logs") | ||
} | ||
|
||
pageToken = resp.NextPageToken | ||
// Break in the event of no logs in GetRobotPartLogsResponse or when | ||
// page token is empty (no more pages). | ||
if resp.Logs == nil || pageToken == "" { | ||
if len(resp.Logs) == 0 { | ||
break | ||
} | ||
|
||
// Truncate this intermediate slice of resp.Logs based on how many logs | ||
// are still required by numLogs. | ||
remainingLogsNeeded := numLogs - logsFetched | ||
if remainingLogsNeeded < len(resp.Logs) { | ||
resp.Logs = resp.Logs[:remainingLogsNeeded] | ||
} | ||
|
||
for _, log := range resp.Logs { | ||
formattedLog, err := formatLog(log, part.Name, args.Format) | ||
if err != nil { | ||
|
@@ -861,6 +881,12 @@ func (c *viamClient) streamLogsForPart(part *apppb.RobotPart, args robotsLogsArg | |
} | ||
|
||
logsFetched += len(resp.Logs) | ||
pageToken = resp.NextPageToken | ||
|
||
if pageToken == "" { | ||
// End of pages | ||
break | ||
} | ||
} | ||
|
||
return nil | ||
|
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.
nit: may be nice to give an example of what that is for both this and the one below