Skip to content
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

Merged
merged 31 commits into from
Jan 15, 2025

Conversation

JosephBorodach
Copy link
Contributor

@JosephBorodach JosephBorodach commented Jan 3, 2025

This PR implements additional filters to the machines logs CLI command, specifically: keyword, start time, end time and log level. Below are the details and test cases for the command:

See ticket here

Invalid: Without any arguments

go run cli/viam/main.go machines logs

Screenshot 2025-01-13 at 4 44 15 PM




With Keyword Filter

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --keyword="stack"

Screenshot 2025-01-08 at 1 31 09 PM




With Error Level

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --levels="error"

Screenshot 2025-01-08 at 1 34 51 PM




Start Time

Start from after the last log

go run cli/viam/main.go machines logs --machine="1" --organization="viam-dev" --location="office temp" --start="2025-01-10T21:30:00Z"

Screenshot 2025-01-09 at 9 29 32 AM

The most recent few logs

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --start="2025-01-13T07:20:31.000Z"

Screenshot 2025-01-13 at 10 12 35 AM

Logs from a slightly earlier start time

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --start="2025-01-12T17:37:26.985Z"

Screenshot 2025-01-13 at 10 17 02 AM

Invalid: Cannot use start and count without end.

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --start="2025-01-12T17:37:26.985Z" --count=10

Screenshot 2025-01-13 at 4 50 38 PM




End Time

Notice how in the second screenshot, we skip the logs passed 15:16.
Screenshot 2025-01-09 at 10 19 46 AM




Start & End Time

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --start="2025-01-12T17:37:26.985Z" --end="2025-01-13T04:24:08.928Z"

Screenshot 2025-01-13 at 10 19 22 AM




Start + Count + End Time

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --start="2025-01-13T08:19:18.865Z" --end="2025-01-13T21:03:37.372Z" --count=5

Screenshot 2025-01-13 at 4 51 34 PM




Edge Case

Do we not want to output something prettier if there are no logs to display?
Screenshot 2025-01-09 at 10 56 03 AM




Without providing count, defaults to 100 logs

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --output="logs.txt" --format="text"

Screenshot 2025-01-13 at 5 43 52 PM

count of 10,000 works

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --output="logs.txt" --format="text" --count=10000

Screenshot 2025-01-13 at 5 57 19 PM

count of 10,001 does not work

go run cli/viam/main.go machines logs -machine="1" --organization="viam-dev" --location="office temp" --output="logs.txt" --format="text" --count=10001

Screenshot 2025-01-13 at 5 54 59 PM

@jr22 - I personally do not love that when surpassing the maxLogs we still display the following:
Screenshot 2025-01-13 at 5 55 58 PM

@JosephBorodach JosephBorodach requested a review from a team as a code owner January 3, 2025 17:57
@JosephBorodach JosephBorodach requested review from stuqdog and purplenicole730 and removed request for a team January 3, 2025 17:57
Base automatically changed from APP-6612-Support-Downloading-Logs to main January 7, 2025 14:17
Copy link
Member

@purplenicole730 purplenicole730 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! There were some changes in flag names that were recently merged in, but I don't suspect it should affect your PR too much

cli/app.go Outdated
Comment on lines 1557 to 1564
&cli.StringFlag{
Name: logsFlagOutputFile,
Usage: "path to output file",
},
&cli.StringFlag{
Name: logsFlagFormat,
Usage: "file format (text or json)",
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mention needs format flag, needs output flag for the users in the usage text? Not sure if necessary, but a suggestion, since I feel like I would read that as being able to format it when printing to console as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can decide the format when printing to the console! The command will default to text if the format flag is not included. Are you suggesting something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you can also format it for the console! Ignore me then :)

Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small things but generally lgtm

cli/app.go Outdated
Comment on lines 32 to 40
logsFlagFormat = "format"
logsFlagOutputFile = "output"
logsFlagKeyword = "keyword"
logsFlagLevels = "levels"
logsFlagStartTime = "start"
logsFlagEndTime = "end"
logsFlagErrors = "errors"
logsFlagTail = "tail"
logsFlagCount = "count"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like some of these were added in a separate PR already. Would you mind pulling down main so we can get a more up-to-date look at what the diff is precisely?

cli/app.go Outdated
Comment on lines 36 to 37
logsFlagStartTime = "start"
logsFlagEndTime = "end"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) I'm gonna ask you to do a bit of bookkeeping for us here if you don't mind! We already have a "start" flag and an "end" flag (dataFlagStart and dataFlagEnd). Would you be willing to rename those to generalFlagStart and generalFlagEnd and then update call sites so that there's only the single instance of a --start or --end flag?

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Jan 8, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 8, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 8, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 8, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 14, 2025
@JosephBorodach JosephBorodach force-pushed the APP-6612-Add-Filters-For-Downloading-Logs branch from 0b85f4e to b8a5d77 Compare January 14, 2025 16:42
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 14, 2025
@JosephBorodach JosephBorodach requested review from RoxyFarhad and removed request for jr22 January 15, 2025 14:27
cli/client.go Outdated
if remainingLogsNeeded < len(resp.Logs) {
resp.Logs = resp.Logs[:remainingLogsNeeded]
}

// Write the logs to the output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this comment and the one below

cli/app.go Outdated
},
&cli.StringFlag{
Name: generalFlagStart,
Usage: "ISO-8601 timestamp in RFC3339 format indicating the start of the interval filter",
Copy link
Member

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

@@ -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. " +
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@JosephBorodach JosephBorodach Jan 15, 2025

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

…omment regarding why a limit is not passed to the APP GetRobotPartLogs call
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 15, 2025
@JosephBorodach JosephBorodach force-pushed the APP-6612-Add-Filters-For-Downloading-Logs branch from b892bb9 to 21d27c6 Compare January 15, 2025 15:26
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 15, 2025
@JosephBorodach JosephBorodach requested review from RoxyFarhad and removed request for RoxyFarhad January 15, 2025 15:32
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 15, 2025
// We do not request the exact limit specified by the user in the `count` argument because the API enforces a maximum
// limit of 100 logs per batch fetch. To keep the RDK independent of specific limits imposed by the app API,
// we always request the next full batch of logs as allowed by the API (currently 100). This approach
// ensures that if the API limit changes in the future, only the app API logic needs to be updated without requiring
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 much better

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 15, 2025
@JosephBorodach JosephBorodach merged commit 2b2ad24 into main Jan 15, 2025
16 checks passed
@JosephBorodach JosephBorodach deleted the APP-6612-Add-Filters-For-Downloading-Logs branch January 15, 2025 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants