Skip to content

Log ThreatMetrix status on IPP events#10101

Merged
n1zyy merged 12 commits intomainfrom
daphnegold/lg-12000-log-threatmetrix-status
Feb 28, 2024
Merged

Log ThreatMetrix status on IPP events#10101
n1zyy merged 12 commits intomainfrom
daphnegold/lg-12000-log-threatmetrix-status

Conversation

@daphnegold
Copy link
Contributor

@daphnegold daphnegold commented Feb 15, 2024

🎫 Ticket

Link to the relevant ticket:
LG-12000

🛠 Summary of changes

Added ThreatMetrix status logging to relevant analytics events:

  1. "GetUspsProofingResultsJob: Enrollment status updated"
  2. "USPS IPPaaS enrollment created"

Note: profile.fraud_pending_reason is an enum that contains statuses for review and reject, but not pass, which makes sense. The condition for pass is nil.

Do we like tmx_status for the log? I went with that, it was not specified in the ticket.

📜 Testing Plan

Manual testing of enrollment_helper.rb locally

  • Create a new account
  • Run through the entire account creation flow and proceed to verification
  • Fail verification to trigger the option for IPP
  • Select 'pass, review, or reject' and proceed to the last step with barcode for IPP
  • tail /log/events.log | jq
  • Search for tmx_status and review that result is appropriate

Run tests for enrollment_helper_spec.rb and get_usps_proofing_results_job_spec.rb to confirm that tmx_status log is present.

👀 Screenshots

Log tails

tmx pass
Screenshot 2024-02-12 at 11 25 17 AM

tmx review
Screenshot 2024-02-12 at 11 28 31 AM

tmx reject
Screenshot 2024-02-12 at 11 20 40 AM

@daphnegold daphnegold self-assigned this Feb 15, 2024
@daphnegold daphnegold requested review from a team and KeithNava February 15, 2024 21:18
@n1zyy
Copy link
Contributor

n1zyy commented Feb 15, 2024

I re-ran failing tests, but the test for AWS Pinpoint is still failing on an invalid country code. I think this came up previously in the past week or two and is almost uncertainly related to your PR.

The good news is that the "no PII in logs" checker didn't encounter the string "pii" in a random chunk of Base64 this time. 😆

I've got to run but will see if I can investigate the remaining error tomorrow.

@gina-yamada
Copy link
Contributor

gina-yamada commented Feb 16, 2024

This extra field on both events are not behind the feature flag (in_person_proofing_enforce_tmx) but is for an epic.
I would consider either putting it behind the flag or confirm from product that logging this field is okay now.

@n1zyy
Copy link
Contributor

n1zyy commented Feb 20, 2024

This is now only failing due to the changelog checker. I'd just make the first category "Internal" and then keep the other two and resubmit.

I had put some ramblings in Slack about the feature flag issue Gina raised. Let me know if I just made it more confusing instead of being helpful.

@gina-yamada
Copy link
Contributor

This extra field on both events are not behind the feature flag (in_person_proofing_enforce_tmx) but is for an epic. I would consider either putting it behind the flag or confirm from product that logging this field is okay now.

Hi @daphnegold
When you are back, I am happy to pair on this comment if you'd like. We can also look pipeline failures and talk about next steps and how it relates to the sprint board. Poke me on Slack else add some time on my calendar if some or all of that sounds helpful.

@daphnegold daphnegold force-pushed the daphnegold/lg-12000-log-threatmetrix-status branch from 2b359d6 to b988652 Compare February 27, 2024 01:55
Copy link
Contributor

@JackRyan1989 JackRyan1989 left a comment

Choose a reason for hiding this comment

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

Looks good! Happy to approve if you think my comment isn't worth the squeeze.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good, but I would like to see a single test where the tmx_status value is tested to be something other than nil. I think this a nice to have for completeness and not necessarily blocking since you do this kind of test in the get_usps_proofing_results_job_spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I discussed this with @n1zyy before when I asked for guidance on new tests I was considering writing and how far down the rabbit hole I should go. profile is undefined in this file. My feeling is that the issues with how profile is handled in different places, including if it can be nil, might be a larger issue and work outside the scope of this PR (if I remember correctly). I'm a bit fuzzy as the conversation happened a bit ago. Defer to whatever you both think.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point. I think it's fine to leave as is then.

Copy link
Contributor

Choose a reason for hiding this comment

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

My feeling is that the issues with how profile is handled in different places, including if it can be nil, might be a larger issue and work outside the scope of this PR (if I remember correctly). I'm a bit fuzzy as the conversation happened a bit ago. Defer to whatever you both think.

I think your read here, and above on analytics, is a good one. At some point we should make profile available here, but I agree that adding it in here would blow up the scope.

allow(IdentityConfig.store).to receive(:get_usps_proofing_results_job_reprocess_delay_minutes).
and_return(reprocess_delay_minutes)
allow(IdentityConfig.store).to receive(:in_person_proofing_enforce_tmx).
and_return(in_person_proofing_enforce_tmx)
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 we should add a test that shows tmx_status getting logged in a analytics event

Copy link
Contributor

Choose a reason for hiding this comment

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

oh oops, I see lower down there's a convo about this

Copy link
Contributor

Choose a reason for hiding this comment

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

oh wait scratch that, on re-read I think that's specifically about the enrollment_helper file. In that case my comment still stands.

Copy link
Contributor Author

@daphnegold daphnegold Feb 27, 2024

Choose a reason for hiding this comment

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

So I think what actually might be my preferred solution here, and doesn't conflate concerns, is to write some tests in profile_spec.rb that test the helper. I should have done that when pulling the logic out into a separate helper method, probably, but I overlooked it because it was getting inadvertently tested everywhere it's implemented. But if we trust that the helper method in profile works appropriately, and we trust that the model for profile works appropriately, and we trust that the the analytics helper logs things appropriately, how important is it to have separate testing for each class consuming a method for a log event to test the output specifically?

On the other hand, maybe the answer is it is important, and I should do both. Including adding logic for profile to enrollment_helper_spec. I just think if we continue to add "logs x characteristic specifically" the test files will get a lot heavier. Should we test every combination? But we already have that precedent somewhat.

Copy link
Contributor Author

@daphnegold daphnegold Feb 27, 2024

Choose a reason for hiding this comment

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

Btw the analytics event does show up in the tests. They fail unless I accommodate the new log output. The output shows tmx_status: :threatmetrix_passed in the get_usps_proofing_results_job_spec and as tmx_status: nil in enrollment_helper_spec because a profile is not defined.

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 that makes sense. Our convention has been to add the additional property to more of the analytics tests but I do agree with you that is does add a lot to the file (perhaps unnecessarily?).

Copy link
Contributor

Choose a reason for hiding this comment

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

also might be an interesting topic for eng huddle - lightening our test files by reducing some redundancy

Copy link
Contributor

@JackRyan1989 JackRyan1989 Feb 27, 2024

Choose a reason for hiding this comment

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

I'm of the opinion that if things are being tested elsewhere, then no need to duplicate the tests. I think it is good to be explicit, but if you can point to a spec that is already covering the particular thing you want to test, then maybe that's enough? But IDK, I think this warrants a broader discussion (but I mean that discussion to take place outside of the scope of this ticket). So I second @svalexander's point above

@JackRyan1989 JackRyan1989 self-requested a review February 27, 2024 15:47
Copy link
Contributor

@JackRyan1989 JackRyan1989 left a comment

Choose a reason for hiding this comment

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

LGTM!

@n1zyy
Copy link
Contributor

n1zyy commented Feb 28, 2024

Daphne is out today, so I'm going to go ahead and merge this.

@n1zyy n1zyy merged commit a295f12 into main Feb 28, 2024
@n1zyy n1zyy deleted the daphnegold/lg-12000-log-threatmetrix-status branch February 28, 2024 16:51
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