Skip to content

Add script to build narratives from event logs#11691

Merged
matthinz merged 29 commits intomainfrom
login-hackathon-2024-user-narrative
Jan 8, 2025
Merged

Add script to build narratives from event logs#11691
matthinz merged 29 commits intomainfrom
login-hackathon-2024-user-narrative

Conversation

@matthinz
Copy link
Contributor

This script is the output of the #login-hackathon-2024-build-user-narratives team.

The idea is that, given a UUID, we can scan event logs and try to build a human-readable narrative for what happened to that user.

Here's an example invocation with the resulting output (UUID replaced with a random one):

❯ aws-vault exec prod-analytics -- bin/summarize-user-events -u e6c0a764-dced-4de3-8de7-32d737830989 -s '2024-12-01' -e '2024-12-30' -z 'America/New_York'
Querying log slices 100% [29/29] |=================================================================================| Time: 00:00:39
## Processed some events
* Processed 92 event(s)

## Identity verification started (December 17, 2024 at 02:06 PM EST)
* (02:11 PM) TrueID request failed. The document type could not be determined
* (02:11 PM) User abandoned identity verification

## Identity verification started (December 20, 2024 at 01:12 PM EST)
* (01:13 PM) TrueID request failed. The document type could not be determined
* (01:15 PM) User abandoned identity verification

The output is rendered as Markdown to the terminal.

Extensibility

The script relies on a set of Matcher instances, which are classes that provide two methods:

  • handle_cloudwatch_event(event) is called for every event in the user's event stream (in order).
  • finish is called at the end of processing all events, and allows the Matcher to provide structure summarizing what it thinks happened

mdiarra3 and others added 17 commits December 10, 2024 11:00
* Allow sourcing events from stdin

It may be useful sometimes to take a local cache of cloudwatch events and pipe them into this command.

[skip changelog]

* Add 'limit: 10000' to CW query

This is required for `complete` to work
* Add ExampleMatcher

Add an example matcher that just counts events and outputs how many it saw.

[skip changelog]

* Remove excess whitespace

* Add frozen_string_literal: true
* Initial crack at an IdV matcher

Matcher is a state machine that collects IDV "attempts" as they happen and tries to suss out interesting things about them.

[skip changelog]

* removed unused method

---------

Co-authored-by: Douglas Price <douglas.price@gsa.gov>
* Normalize @timestamp to UTC for each event

Pre-parse it in the script so that matchers don't have to worry about it

* Slightly improve output

- Include timestamps where possible

[skip changelog]
* Don't crash if no events found

* Tweak handling of --end-date

- Use a dash rather than underscore
- Make sure we respect it if it's passed in

* Sort events on stdin before processing

Events from Cloudwatch queries will be sorted, but stdin is not guaranteed.

Processing unsorted events can lead to weird, weird, outcomes
If the user:

- Has not completed the initial workflow and
- Does not have an idv-related event new that 1 hour

Call their attempt abandoned
* include timestamp

* add account deletion narrative matcher

* remove unneeded matcher requirement

* add deletion matcher

* lint

* rename account deletion
[HACKATHON] Enable user narrative script to work with `binding.pry`
matthinz and others added 2 commits December 30, 2024 15:21
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Add some specs around option parsing, time parsing, and actually running the program
@matthinz matthinz force-pushed the login-hackathon-2024-user-narrative branch from b59136d to 93b9b3e Compare January 7, 2025 22:10
Copy link
Contributor

@solipet solipet left a comment

Choose a reason for hiding this comment

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

What we came up with a great start that is already useful in its initial state. Plenty of room to build on in future PRs.

@matthinz matthinz merged commit ae56c01 into main Jan 8, 2025
@matthinz matthinz deleted the login-hackathon-2024-user-narrative branch January 8, 2025 19:47
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.

5 participants