Skip to content

LG-12075: Rename attempt properties in analytics for clarity#10011

Merged
night-jellyfish merged 12 commits intomainfrom
brittany/lg-12075-rename-attempt-properties
Feb 3, 2024
Merged

LG-12075: Rename attempt properties in analytics for clarity#10011
night-jellyfish merged 12 commits intomainfrom
brittany/lg-12075-rename-attempt-properties

Conversation

@night-jellyfish
Copy link
Contributor

@night-jellyfish night-jellyfish commented Jan 31, 2024

🎫 Ticket

LG-12075

🛠 Summary of changes

We had a few attributes in analytics events named very similarly (attempt, attempts, remaining_attempts), despite meaning different things. Sometimes they meant the submission attempt, and sometimes they meant the document capture attempt.

This PR renames the attributes to clarify what kind of attempt they're pointing to.

📜 Testing Plan

  • Go through the flow locally
  • Look at your local copy of log/events.log and search for the word "attempts"
    • You should see changes to the attempts attributes reflecting the events changed on this branch in app/services/analytics_events.rb
      • Frontend: IdV: back image added
      • IdV: doc auth exception visited
      • IdV: doc auth image upload form submitted
      • IdV: doc auth image upload vendor submitted
      • IdV: doc auth image upload vendor pii validation
      • IdV: doc auth warning visited
      • Frontend: IdV: front image added
      • IdV: phone error visited
      • idv_sdk_selfie_image_added
      • idv_selfie_image_file_uploaded
      • IdV: session error visited
      • IdV: enter verify by mail code submitted
      • Frontend: IdV: warning shown

Alternatively:

  • Run make watch_events
  • Do the action needed to cause a few of the events listed above
  • Make sure the output contains the expected version of the attributes

Notes

This PR is easiest to review in stages by commit (each commit is self contained).

  1. Rename image_added + opened event attrs
  2. Rename image_submitted + validated attrs
  3. Rename IdV: warning shown event attr
  4. Rename idv_doc_auth_warning_visited attrs
  5. Rename idv_doc_auth_exception_visited attrs
  6. Rename idv_session_error_visited attrs
  7. Rename idv_verify_by_mail_enter_code_submitted attrs
  8. Rename idv_phone_error_visited attrs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A little unsure if this should be "code entry attempts" or something
instead...but the definition of this attribute seems to be from the
same areas I have renamed submit_attempts, so that's why I chose that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The controller did have a method that was remaining_step, but as it was defined the exact same way as others in this file named remaining_attempt, I changed it to be consistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

@night-jellyfish , can you point to where is the method?

Copy link
Contributor Author

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. It doesn't seem like it's ever called, outside of the spec files. Perhaps it can just be removed then?

Copy link
Contributor

@dawei-nava dawei-nava Feb 1, 2024

Choose a reason for hiding this comment

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

@night-jellyfish , i think like job_fail, the reading of rate_limiter.remaining_count may have side effects that needed, like updating the expiry time of underlying Redis entry, otherwise the RateLimiter will not be refreshed though these urls are visisted.

That raises another question why we create a new RateLimiter instance every time here? It works since we only use it once in one request/response conversation, and also it's backed by Redis with the same key.

Anyway, interesting details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh interesting! I don't fully understand the ins and outs of Redis, but that sounds plausible. Do you think it's worth a refactoring ticket to only create a new instance once?

Copy link
Contributor

Choose a reason for hiding this comment

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

@night-jellyfish , i think it's fine to leave it as is, for Redis, just treat it as a database.

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 see. Just for my own understanding then - are you saying it'd be better to re-use the same RateLimiter instance because we could just reuse a single row in the Redis DB vs creating a new row each time?

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 tried creating a private method in the controller so that the method
could be used as the definition, instead of the same code 3x in this file. But I
found doing so broke tests in an off-by-one sort of way - I think
somehow the private method held onto the value and was not updated the
same way as when it's defined each time. So I left the definition the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

@night-jellyfish , which test failed? I changed to private method and the spec and feature test for phone_errors_controller seems fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strange! I just tried again. When I try I get 2 failures:

 expected: ("IdV: phone error visited", {:remaining_submit_attempts=>4, :sample_bucket1=>:sample_value1, :sample_bucket2=>:sample_value2, :type=>:jobfail})
              got: ("IdV: phone error visited", {:remaining_submit_attempts=>5, :sample_bucket1=>:sample_value1, :sample_bucket2=>:sample_value2, :type=>:jobfail})

from

rspec ./spec/controllers/idv/phone_errors_controller_spec.rb:158 # Idv::PhoneErrorsController#warning with rate limit attempts logs an event
rspec ./spec/controllers/idv/phone_errors_controller_spec.rb:211 # Idv::PhoneErrorsController#jobfail with rate limit attempts logs an event

When I stop using the private method, they pass again.

@night-jellyfish night-jellyfish requested review from a team and dawei-nava and removed request for a team January 31, 2024 19:33
@night-jellyfish night-jellyfish force-pushed the brittany/lg-12075-rename-attempt-properties branch from f4498d1 to 24b089a Compare January 31, 2024 20:03
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this attribut/property is used in ui erb file? If we renamed it, we will need rename there if used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's correct! I renamed it here.

The var we talked about above in the timeout method, I can't find in use anywhere outside the spec. It should be in use by app/views/idv/phone_errors/timeout.html.erb, but it isn't, even in main.

That's why I think maybe that one could be deleted entirely? But it does seem outside the scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@night-jellyfish , how about here?

<p>
<%= t('idv.failure.phone.warning.attempts_html', count: @remaining_attempts) %>
</p>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! That's the one I changed in the first link in my previous comment.

Copy link
Contributor

@dawei-nava dawei-nava left a comment

Choose a reason for hiding this comment

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

LGTM.

Brittany Greaner and others added 12 commits February 2, 2024 15:25
These values permeated through a lot of the code, so this ended up
having a lot of ripple effects.
A little unsure if this should be "code entry attempts" or something
instead...but the definition of this attribute seems to be from the
same areas I have renamed submit attempts, so that's why I chose that.
The controller did have a method that was `remaining_step`, but as it
was defined the exact same way as others named `remaining_attempt`, I
changed it to be consistent.

I tried creating a private method in the controller so that the method
could be used as the definition, instead of the same code 3x. But I
found doing so broke tests in an off-by-one sort of way - I think
somehow the private method held onto the value and was not updated the
same way as when it's defined each time.
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
@night-jellyfish night-jellyfish force-pushed the brittany/lg-12075-rename-attempt-properties branch from 90fe3b5 to 9ee83f3 Compare February 2, 2024 23:43
@night-jellyfish night-jellyfish merged commit 6f8c676 into main Feb 3, 2024
@night-jellyfish night-jellyfish deleted the brittany/lg-12075-rename-attempt-properties branch February 3, 2024 00:05
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