-
Notifications
You must be signed in to change notification settings - Fork 166
Proof of Concept: Document analytics events via YARD (LG-5590) #6014
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
Changes from all commits
77c4e9c
78a13b0
1085051
cbe37c2
dd75757
a28fc64
0b54508
2d4f2c6
b9b5740
778eeaa
5cfb746
75dd072
d562814
cdeca15
7cb3951
13da56d
531b95d
24ba2bc
1c8a239
7377ed0
e872498
fb3a914
698e2c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ node_modules | |
| public | ||
| vendor | ||
| coverage | ||
| doc | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -786,6 +786,7 @@ DEPENDENCIES | |
| webmock | ||
| xmldsig (~> 0.6) | ||
| xmlenc (~> 0.7, >= 0.7.1) | ||
| yard | ||
| zonebie | ||
| zxcvbn (= 0.1.7) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Serve a static file from Rails so that the CORS middleware can add the correct headers | ||
| class AnalyticsEventsController < ApplicationController | ||
| prepend_before_action :skip_session_load | ||
| prepend_before_action :skip_session_expiration | ||
| skip_before_action :disable_caching | ||
|
|
||
| JSON_FILE = Rails.root.join('public', 'api', '_analytics-events.json') | ||
|
|
||
| def index | ||
| if File.exist?(JSON_FILE) | ||
| expires_in 15.minutes, public: true | ||
|
|
||
| send_file JSON_FILE, type: 'application/json', disposition: 'inline' | ||
| else | ||
| render_not_found | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| module AnalyticsEvents | ||
| # @identity.idp.event_name Account Reset | ||
|
Contributor
Author
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. 👀 custom tag! we can make a form of the script that errors when this is absent as a lint, maybe even try to make sure that the string is present in the method body |
||
| # @param [Boolean] success | ||
| # @param ["cancel", "delete", "cancel token validation", "granted token validation", | ||
| # "notifications"] event | ||
| # @param [String] message_id from AWS Pinpoint API | ||
| # @param [String] request_id from AWS Pinpoint API | ||
| # @param [Boolean] sms_phone | ||
| # @param [Boolean] totp does the user have an authentication app as a 2FA option? | ||
| # @param [Boolean] piv_cac does the user have PIV/CAC as a 2FA option? | ||
| # @param [Integer] count number of notifications sent | ||
| # @param [Hash] errors | ||
| # @param [Hash] error_details | ||
| # @param [String] user_id | ||
| # @param [Integer] account_age_in_days | ||
| # @param [Hash] mfa_method_counts | ||
| # @param [Integer] email_addresses number of email addresses the user has | ||
| # Tracks events related to a user requesting to delete their account during the sign in process | ||
| # (because they have no other means to sign in). | ||
| def account_reset( | ||
| success: nil, | ||
| event: nil, | ||
| message_id: nil, | ||
| piv_cac: nil, | ||
| request_id: nil, | ||
| sms_phone: nil, | ||
| totp: nil, | ||
| count: nil, | ||
| errors: nil, | ||
| user_id: nil, | ||
| account_age_in_days: nil, | ||
| mfa_method_counts: nil, | ||
| pii_like_keypaths: nil, | ||
| error_details: nil, | ||
| email_addresses: nil | ||
| ) | ||
| track_event( | ||
| 'Account Reset', | ||
| { | ||
| success: success, | ||
|
Contributor
Author
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. One of the cons of this approach is each key needs to be written 3 times in this file (YARD, param, and then when it's passed over to Thanks to #6012, we can be sure that if we forget to pass a param, we will error because it's unused |
||
| event: event, | ||
| message_id: message_id, | ||
| piv_cac: piv_cac, | ||
| request_id: request_id, | ||
| sms_phone: sms_phone, | ||
| totp: totp, | ||
| count: count, | ||
| errors: errors, | ||
| user_id: user_id, | ||
| account_age_in_days: account_age_in_days, | ||
| mfa_method_counts: mfa_method_counts, | ||
| pii_like_keypaths: pii_like_keypaths, | ||
| error_details: error_details, | ||
| email_addresses: email_addresses, | ||
| }.compact, | ||
| ) | ||
| end | ||
|
|
||
| # @identity.idp.event_name Account Delete submitted | ||
| # @param [Boolean] success | ||
| # When a user submits a form to delete their account | ||
| def account_delete_submitted(success:) | ||
| track_event('Account Delete submitted', success: success) | ||
| end | ||
|
|
||
| # @identity.idp.event_name Account Delete visited | ||
| # When a user visits the page to delete their account | ||
| def account_delete_visited | ||
|
Contributor
Author
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. Turns out there are a lot of these events with no params, which would make for a super easy migration if we wanted
Full list of events without params
|
||
| track_event('Account Delete visited') | ||
| end | ||
|
|
||
| # @identity.idp.event_name Account Deletion Requested | ||
| # @param [String] request_came_from the controller/action the request came from | ||
| # When a user deletes their account | ||
| def account_deletion(request_came_from:) | ||
| track_event('Account Deletion Requested', request_came_from: request_came_from) | ||
| end | ||
| end | ||
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.
I picked this one because it was first on the list. It turned out to be super verbose to document because it is essentially 5 different events (it has its own
eventkey 🤦 )I will take some time and try migrating other events to see how much typing they result in
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.
Maybe this is a good thing as it uncovers a smell where this should have separate event names for those events?
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.
Created a ticket to track splitting it up: https://cm-jira.usa.gov/browse/LG-5910
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.
Does splitting it up mean splitting up each event (like this one would be for Account Reset) into a separate document, or does this happen currently? I think with the number of events we have, the documentation can get rather large.
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.
Not 100% sure what you're asking? The goal is to have a lot of documentation, so we can better explain what the events in our logs mean, so when we query events, we query them confidently.
But yes, this
analytics_events.rbfile would be expected to get pretty bigThere 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.
So the file analytics_events.rb will have all of the events going forward not just account reset such as all the events in analytics.rb?
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.
Yeah next steps would be:
analytics_events.rb