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

added log filters to filter the log output #209

Merged

Conversation

hariprakash-j
Copy link
Collaborator

*Issue #192 *

Description of changes:
Added two flags to rain log command --length or -l for limiting the length of logs and --days or -d for limiting logs output by number of days

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@hariprakash-j
Copy link
Collaborator Author

hariprakash-j commented Nov 12, 2023

I did an upgrade on all dependencies, mainly for cobracli. The mutually exclusive feature of the new cobraCli is great as it lets us restrict which flags can be used together. It seems there was a change in the aws sdk which caused an issue, a small fix solved that.

@r-heimann
Copy link

r-heimann commented Nov 13, 2023

Thank you very much for this PR. Would it be possible to add another filter which only displays the logs after the newest CloudFormation entry User Initiated? This would allow the user to only see the relevant logs that have been created after deploying/updating/removing a stack.

@@ -59,4 +61,7 @@ func init() {
Cmd.Flags().BoolVarP(&allLogs, "all", "a", false, "include uninteresting logs")
Cmd.Flags().BoolVarP(&chart, "chart", "c", false, "Output a gantt chart of the most recent action as an html file")
Cmd.Flags().BoolVar(&config.Debug, "debug", false, "Output debugging information")
Cmd.Flags().IntVarP(&logsLength, "length", "l", 0, "Number of logs to display")
Cmd.Flags().IntVarP(&logsDays, "days", "d", 0, "Age of the logs to display in days")
Cmd.MarkFlagsMutuallyExclusive("days", "length")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these exclusive? What if a single day has a large number of log entries?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just did not test those things together, will add tests and remove that exclusive option, they should work like you said a test till solidify it.

@@ -34,7 +34,38 @@ func (e events) Less(i, j int) bool {
return ptr.ToTime(e[i].Timestamp).Unix() < ptr.ToTime(e[j].Timestamp).Unix()
}

func printLogs(logs events) {
func reduceLogsByLength(logsRange int, logs *events) *events {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think reduceLogsToLength would be a better name. "By length" to me implies that you will subtract that much from it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed, will change it to that

duration := time.Duration(time.Hour * time.Duration(logsDays*-24))
logs = *reduceLogsByDuration(duration, time.Now(), &logs)
}
if logsRange > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will just work as expected if you remove the mutually exclusive flag.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, I will also add tests to make sure the combination works

func printLogs(logsRange int, logsDays int, logs events) {
if logsDays > 0 {
duration := time.Duration(time.Hour * time.Duration(logsDays*-24))
logs = *reduceLogsByDuration(duration, time.Now(), &logs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why time.Now() here? Why does this need to be a param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did it for the tests, but on second thought I could have done it better, I'll redo the way i handle time and testing and remove that param

@hariprakash-j
Copy link
Collaborator Author

added a commit addressing all the above issues mentioned above

@ericzbeard ericzbeard merged commit 82d0829 into aws-cloudformation:main Nov 15, 2023
1 check passed
@ericzbeard
Copy link
Contributor

added a commit addressing all the above issues mentioned above

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants