Skip to content

LG-8410 po search logging#7763

Merged
svalexander merged 19 commits intomainfrom
shannon/lg-8410-po-search-logging
Feb 14, 2023
Merged

LG-8410 po search logging#7763
svalexander merged 19 commits intomainfrom
shannon/lg-8410-po-search-logging

Conversation

@svalexander
Copy link
Contributor

@svalexander svalexander commented Feb 3, 2023

🎫 Ticket

Lg-8410

🛠 Summary of changes

Add analytics event for po search.

Addition in address_search_controller calls analytics event for arcgis api when no addresses are found and when errors other than TimeoutError and ConnectionFailed.

Addition in usps_locations_controller calls analytics event for usps api when response successfully returns addresses and when response has no locations.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • To test a success: Enter a working address, ex 10421 Motor City Dr, Bethesda, MD 20817
  • To test a usps no addresses failure: Enter an address that fails for usps, ex Mile 20 I-83 North, Glen Rock, PA
  • To test when arcgis has a successful response with an error code: Enter an address that have 200+ characters, ex 1000 mainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmain boulevard, staten island, massachussetts 10001-12341
  • To test a timeout error, edit ArcgisApi::Geocoder.handle_api_errors to raise Faraday::TimeoutError
  • To test a failed connection error, edit ArcgisApi::Geocoder.handle_api_errors to raise Faraday::ConnectionFailed
  • To test an arcgis no candidates failure: after api call reassign addresses to []
  • To test an arcgis standarderror: after api call reassign addresses to an int

@svalexander svalexander requested review from a team and sheldon-b February 3, 2023 00:50
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.

This looks awesome! I just have a few comments but am happy to approve after that.


context 'no addresses found by usps' do
before do
allow(proofer).to receive(:request_facilities).with(address).and_return(empty_locations)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is nit picky, but it seems like the pattern between this test and the address_controller_spec.rb are different, but essentially doing the same thing. Is there a reason why we're not doing something simple likelet(:addresses) do [] end in address_search_controller.spec.rb?

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 thought it might be a bit easier to read the test like this

Copy link
Contributor

Choose a reason for hiding this comment

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

Totally agree. I was more just wondering if there was any value in remaining consistent?

@svalexander svalexander changed the title Shannon/lg 8410 po search logging LG-8410 po search logging Feb 3, 2023
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.

Tests pass in dev. Looks good to me!

Copy link
Contributor

@tomas-nava tomas-nava left a comment

Choose a reason for hiding this comment

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

I think we're missing AC#4 (first bullet) from LG-8410:

ArcGIS' service returns 200 OK HTTP responses but indicates that there were errors when the response bodies include an "error" key.

I think the right place to capture these is in the find_address_candidates method of ArcgisApi::Geocoder; something like

response = faraday.get(ADDRESS_CANDIDATES_ENDPOINT, params, dynamic_headers) do |req|
  req.options.context = { service_name: 'arcgis_geocoder_find_address_candidates' }
end

if response['error_code'].present?
  # log an error analytics event
 return []
end

return parse_address_candidates(response.body)

This is very pseudocodey, because I'm not sure what an error response will look like; I couldn't find good examples in the documentation @allthesignals linked to in the ticket. Maybe you two could pair on this part?

Copy link
Contributor

@tomas-nava tomas-nava left a comment

Choose a reason for hiding this comment

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

approve!

I suggested some additional small changes that should be made before merging

error_code = response_body.dig('error', 'code')
# response_body is in this format:
# {"error"=>{"code"=>400, "message"=>"", "details"=>[""]}}
error_message = response_body.dig('error', 'message') || "Received error code #{error_code}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
error_message = response_body.dig('error', 'message') || "Received error code #{error_code}"
error_code = response_body.dig('error', 'code')
error_message = response_body.dig('error', 'message') || "Received error code #{error_code}"

This is a mistake I made when I suggested this change... we need to define error_code here.

response_body,
RuntimeError.new(error_message),
{
status: response_body.dig('error', 'code'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
status: response_body.dig('error', 'code'),
status: error_code,

...and we can use the variable defined in my last suggestion here

analytics.idv_arcgis_request_failure(
api_status_code: 422,
exception_class: err.class,
exception_message: err.message,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
exception_message: err.message,
exception_message: exception_message,

Comment on lines +41 to +43
else
response = proofer.request_pilot_facilities
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
else
response = proofer.request_pilot_facilities
end
else
response = proofer.request_pilot_facilities
end

@svalexander svalexander merged commit 4a7c606 into main Feb 14, 2023
@svalexander svalexander deleted the shannon/lg-8410-po-search-logging branch February 14, 2023 14:53
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.

4 participants