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

Implement a "User Initiated" filter option for the rain logs command #236

Open
Tommes-M opened this issue Jan 8, 2024 · 7 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Tommes-M
Copy link

Tommes-M commented Jan 8, 2024

Dear rain maintainers,

I propose a feature for the rain logs command to improve log readability in CI/CD environments. The idea is to add an option that filters logs to only those after the last "User Initiated" CloudFormation event. While the --days parameter exists, it's not precise enough, often including logs from multiple updates within the timeframe.

Proposed Solution:

Introduce something like a --since-user-initiated flag to filter logs effectively.
This targets logs post the most recent "User Initiated" event, avoiding the clutter of unrelated entries.
Challenge:

The current --days parameter often captures logs from several updates if multiple deployments occur in the specified period.

I'm keen to contribute to implementing this feature. However, I completely lack expertise in the language "Go".
So I would be very grateful if someone else could handle the implementation. I don't think this requires much effort?

This feature would significantly enhance log management efficiency in busy CI/CD pipelines.

Thanks for considering this request. I look forward to any feedback.

Best regards,
Tommes

@ericzbeard ericzbeard added enhancement New feature or request good first issue Good for newcomers labels Jan 8, 2024
@ericzbeard
Copy link
Contributor

What would the filter look like if you were doing this with the CLI/API?

@Tommes-M
Copy link
Author

Tommes-M commented Jan 9, 2024

Hello Eric,

unfortunately, as far as I know, there is no direct parameter provided by the AWS API that allows all CloudFormation event entries from the last "User initiated" to be output. Nevertheless, it is possible to extract the whole thing from the CloudFormation event entries with a few combined API commands. For example, the workflow in Python would look like this:

Step 1: Fetching All Stack Events

We start by retrieving all the events associated with a specific CloudFormation stack:

import boto3

# Initialize the boto3 client for CloudFormation
cloudformation_client = boto3.client('cloudformation')

# This line calls the AWS CloudFormation API to get a detailed list of all events for the specified stack.
response = cloudformation_client.describe_stack_events(StackName="example")

Step 2: Identifying the Last 'User Initiated' Event

Next, we find the last "User Initiated" event from these stack events:

# This loop iterates through the stack events to find the event where the ResourceStatusReason contains 'User Initiated', which marks the start of relevant logs.
for event in response['StackEvents']:
    if 'User Initiated' in event.get('ResourceStatusReason', ''):
        return event

Step 3: Displaying Events Since the Last 'User Initiated' Event

Once we have identified the last "User Initiated" event, we display all subsequent events:

# Here, we calculate the index of the last "User Initiated" event in the list of events and then print all events up to and including this index. The +1 ensures that the "User Initiated" event itself is included in the output.
last_event_index = response['StackEvents'].index(event)
print(response['StackEvents'][:last_event_index+1])

As I explained above, this is just an example of how the whole thing could be implemented in Python. However, "rain" already has the "rain logs" command. You can certainly modify this so that the workflow described above runs in the background using a filter such as "rain logs --since-user-initiated", but the logs are then output in the format that is currently the case when I retrieve them with "rain logs". I think the format in which the logs are currently displayed is very good to look at. However, as I said, I have no experience in "Go", so unfortunately I can't edit the code directly to incorporate the logic I explained into the "rain logs" command/function.

I hope this clarifies the approach. If you have any further questions or need additional details, please let me know.

Best regards,
Tommes

@ericzbeard
Copy link
Contributor

Thanks Tommes, this looks to be fairly straightforward.

@Tommes-M
Copy link
Author

You're welcome Eric 😃.
If you have any more questions or need further assistance, just let me know.

I'm looking forward to the result!

@RuiHirano
Copy link

Is this Issue already being worked on by others?
If not, I would like to work on adding this feature.

@RuiHirano
Copy link

I created a PR for this issue.
This is my first PR so please let me know if there are any problems.

@Tommes-M
Copy link
Author

Is this Issue already being worked on by others? If not, I would like to work on adding this feature.

Hello.

as far as I know this issue is not solved yet. So first of all thank you for your help and effort :)

@ericzbeard Can you please look into the PR and accept it, if its okay?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants