Skip to content

Analytics: Compact event properties#10987

Merged
aduth merged 11 commits intomainfrom
aduth-analytics-compact-event-properties
Aug 9, 2024
Merged

Analytics: Compact event properties#10987
aduth merged 11 commits intomainfrom
aduth-analytics-compact-event-properties

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Jul 26, 2024

🛠 Summary of changes

Updates Analytics to avoid tracking nil values for event_properties.

Why?

  • They're effectively ignored by CloudWatch, so there's not a meaningful difference between sending nil and not sending anything at all
  • May reduce log storage costs, since we're storing less
  • Dealing with nil creates a lot of noise in specs, particularly when adding a new optional property to an existing analytics methods (currently dealing with this in Document all analytics logged through sign_in_spec #10966)
  • Simplifies methods in AnalyticsEvents which currently call .compact manually, which is usually added as a workaround to the issued described in the point above

Related Slack discussion: https://gsa-tts.slack.com/archives/C0NGESUN5/p1706906370684589

📜 Testing Plan

Verify that the build passes.

Use make watch_events to verify that any event which may log a nil value (either defaulted or explicit from calling an analytics method) does not include the property in the logged output.

@aduth
Copy link
Contributor Author

aduth commented Jul 26, 2024

For posterity, a terminal command I used to automate the removal of unnecessary nil values from have_logged_event specs:

find spec -type f -name '*.rb' -exec perl -i -p0e 's/have_logged_event\((([^)]|\n)+?),\n\s+(\w+):\ nil,/have_logged_event(\1,/g' {} \;

@aduth
Copy link
Contributor Author

aduth commented Jul 30, 2024

Some of the spec assertion revisions here are made challenging by differences in how we assert logging:

expect(@analytics).to receive(:track_event).with('...', kwargs)

vs.

expect(@analytics).to have_logged_event('...', kwargs)

The former is outdated in that it doesn't benefit from all of the features of our FakeAnalytics helper class, which now notably includes nil compact-ing.

It might be easier for me to do a separate pass at converting everything over to have_logged_event before continuing with this.

Edit: This has been addressed separately in #11001 and #11010.

@aduth aduth force-pushed the aduth-analytics-compact-event-properties branch 2 times, most recently from 57b174b to 0c421d5 Compare July 31, 2024 14:48
@aduth aduth marked this pull request as ready for review July 31, 2024 16:19
@aduth
Copy link
Contributor Author

aduth commented Jul 31, 2024

The build is passing here now, so it's ready for review.

A couple related notes:

  • I'll plan to bring this up in today's engineering huddle meeting to get some final buy-in for the change
  • This doesn't deeply compact nil values so certain nil values can still show up in logs, usually in cases where we pass through some vendor result (e.g. proofing results, reCAPTCHA result). I think it could make sense to compact these as well, but I decided to save that for a follow-on effort if there's interest. I could also see the case being made that it's better to leave those "as-is", since we're essentially passing through a vendor result verbatim anyways.

@aduth
Copy link
Contributor Author

aduth commented Jul 31, 2024

Nevermind, the build showed as green, but I think GitLab hadn't actually run. There's still some more errors to work through.

@aduth aduth marked this pull request as draft July 31, 2024 17:24
@aduth aduth marked this pull request as ready for review August 2, 2024 13:17
@aduth
Copy link
Contributor Author

aduth commented Aug 2, 2024

Most of the spec changes involved simply dropping any nil value assertions that might have existed.

A few were more complicated, particularly with shared examples where sometimes an analytics value is logged and sometimes it's not. In those cases, often I could call .compact within the assertion itself if the value was known in scope. For some, I resorted to using hash_including and omitting the properties which were sometimes nil, if that value wasn't known in scope (e.g. spec/jobs/get_usps_proofing_results_job_spec.rb). Often these used the "anything" matcher. I think this ought to be improved to assert the specific value we expect, but I don't see this as fundamentally worse than matching with anything.

@aduth aduth force-pushed the aduth-analytics-compact-event-properties branch from 5846c53 to 28fe8a8 Compare August 2, 2024 13:40
@aduth
Copy link
Contributor Author

aduth commented Aug 2, 2024

This will need to wait on a few revisions to dependent log metric queries before being able to merge (as discussed during this week's engineering huddle).

@aduth aduth force-pushed the aduth-analytics-compact-event-properties branch from 5993668 to 71b5c98 Compare August 9, 2024 11:51
@aduth
Copy link
Contributor Author

aduth commented Aug 9, 2024

This is unblocked now as of DevOps RC v388.

@aduth aduth force-pushed the aduth-analytics-compact-event-properties branch from 71b5c98 to d815f0a Compare August 9, 2024 12:08
@aduth aduth merged commit 0d5759a into main Aug 9, 2024
@aduth aduth deleted the aduth-analytics-compact-event-properties branch August 9, 2024 12:24
amirbey added a commit that referenced this pull request May 14, 2025
amirbey added a commit that referenced this pull request May 19, 2025
…ID (#12177)

* doc auth pass if transaction status passes

changelog: Internal, Document Authentication, TrueIDReponse successful if transaction status passes

* update spec response transaction status

* update true id response spec

* update fixtures product status for failed transactions

* update product status

* selfie must past

* revert fixture changes

* resolve rebase conflict

* attention barcode does not have to be only error

* update doc_auth_success to remove selfie in mock result response

* happy linting

* allow mock proofer to have multiple errors with barcode attn

* remove dup test

* add an error barcode fixture to barcode error trueid response

* ensure attention_with_barcode? returns a boolean

* update spec attention with barcode

* error generator use transaction status to determine if doc auth passed when counting errors

* consolidate checking if doc auth passed in error generator

* doc_auth_passed not in scope for DocAuthErrorHandler

* update mock to include transaction_status

* rename error generator tests from 'DocAuthResult is ...' to 'TransactionStatus is ...'

* resolve rebase conflict

* resolve rebase conflict

* resolve rebase conflict

* resolve rebase conflict

* update transaction_stauts in mock to reflect doc auth only

* check transaction status to determine if doc auth is sucess for mock

* assist with correcting case for transaction status and doc auth result in yml files

* do not correct case

* add transaction status to yml

* add transaction status to yml

* add transaction status to yml

* add transaction result to inline yaml files

* update yml fixtures to have transaction_status

* update image upload presenter to use transaction status

* resolve rebase conflict

* remove stale comment

* remove props as per PR #10987

* happy linting

* TransactionCodes

* happy linting

* fix namespacing

* remove billed attribute from transactin status

* fix typo
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.

3 participants