Skip to content

Commit

Permalink
Revert "VACMS-18736 Use updated Search.gov url when flipper is enabled (
Browse files Browse the repository at this point in the history
#18450)"

This reverts commit f5cd511.
  • Loading branch information
SnowboardTechie committed Sep 23, 2024
1 parent f9b9311 commit 0fb030b
Show file tree
Hide file tree
Showing 19 changed files with 14 additions and 909 deletions.
9 changes: 0 additions & 9 deletions config/betamocks/services_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -595,15 +595,6 @@
:path: "/api/v2/search/i14y"
:file_path: "search/default"

# Search GSA
- :name: 'Search GSA'
:base_uri: <%= "#{URI(Settings.search.gsa_url).host}:#{URI(Settings.search.gsa_url).port}" %>
:endpoints:
# Search results
- :method: :get
:path: "/technology/searchgov/v2/results/i14y"
:file_path: "search/default"

#GIS
- :name: 'GIS'
:base_uri: <%= "#{URI(Settings.locators.gis_base_path).host}:#{URI(Settings.locators.gis_base_path).port}" %>
Expand Down
4 changes: 0 additions & 4 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,3 @@ features:
mgib_verifications_maintenance:
actor_type: user
description: Used to show maintenance alert for MGIB Verifications
search_use_v2_gsa:
actor_type: cookie_id
description: Swaps the Search Service's configuration url with an updated api.gsa.gov address
enabled_in_development: true
24 changes: 0 additions & 24 deletions config/locales/exceptions.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -798,30 +798,6 @@ en:
code: 'SEARCH_504'
detail: 'Did not receive a timely response from Search.gov'
status: 504
SEARCH_GSA_400:
<<: *external_defaults
title: Bad Request
code: 'SEARCH_GSA_400'
detail: 'api.gsa.gov service responded with a Bad Request'
status: 400
SEARCH_GSA_429:
<<: *external_defaults
title: Exceeded rate limit
code: 'SEARCH_GSA_429'
detail: 'Exceeded api.gsa.gov rate limit'
status: 429
SEARCH_GSA_503:
<<: *external_defaults
title: Service Unavailable
code: 'SEARCH_GSA_503'
detail: 'api.gsa.gov service is currently unavailable'
status: 503
SEARCH_GSA_504:
<<: *external_defaults
title: Gateway Timeout
code: 'SEARCH_GSA_504'
detail: 'Did not receive a timely response from api.gsa.gov'
status: 504
SEARCH_TYPEAHEAD_400:
<<: *external_defaults
title: Bad Request
Expand Down
5 changes: 2 additions & 3 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -900,16 +900,15 @@ search:
access_key: SEARCH_GOV_ACCESS_KEY
affiliate: va
mock_search: false
gsa_url: https://api.gsa.gov/technology/searchgov/v2/results/i14y
url: https://search.usa.gov/api/v2/search/i14y
url: https://search.usa.gov/api/v2

# Settings for search-typeahead
search_typeahead:
api_key: API_GOV_ACCESS_KEY
name: va
url: https://api.gsa.gov/technology/searchgov/v1

# Settings for search-click-tracking
# Settings for search-click-tracking
search_click_tracking:
access_key: SEARCH_GOV_ACCESS_KEY
affiliate: va
Expand Down
3 changes: 1 addition & 2 deletions config/settings/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ directory:
search:
access_key: TESTKEY
affiliate: va
gsa_url: https://api.gsa.gov/technology/searchgov/v2/results/i14y
url: https://search.usa.gov/api/v2/search/i14y
url: https://search.usa.gov/api/v2

search_typeahead:
api_key: TEST_KEY
Expand Down
11 changes: 1 addition & 10 deletions lib/search/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ def mock_enabled?
end

def base_path
flipper_enabled? ? Settings.search.gsa_url : Settings.search.url
end

# Breakers initialization requires this configuration which means the #base_path
# is required when building the DBs in CI that flipper uses for checking toggles.
# The NoDatabaseError rescue handles times we're building new DBs.
def flipper_enabled?
Flipper.enabled?(:search_use_v2_gsa)
rescue ActiveRecord::NoDatabaseError
false
"#{Settings.search.url}/search/i14y"
end

def service_name
Expand Down
22 changes: 9 additions & 13 deletions lib/search/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
require 'search/configuration'

module Search
# This class builds a wrapper around Search.gov or api.gsa.gov web results API. Creating a new instance of class
# This class builds a wrapper around Search.gov web results API. Creating a new instance of class
# will and calling #results will return a ResultsResponse upon success or an exception upon failure.
#
# @see https://search.usa.gov/sites/7378/api_instructions
# @see https://open.gsa.gov/api/searchgov-results/
#
class Service < Common::Client::Base
include Common::Client::Concerns::Monitoring
Expand Down Expand Up @@ -49,7 +48,6 @@ def results_url
# Optional params [enable_highlighting, limit, offset, sort_by]
#
# @see https://search.usa.gov/sites/7378/api_instructions
# @see https://open.gsa.gov/api/searchgov-results/
#
def query_params
{
Expand Down Expand Up @@ -94,7 +92,7 @@ def handle_error(error)
message = parse_messages(error).first
save_error_details(message)
handle_429!(error)
raise_backend_exception(error_code_name(400), self.class, error) if error.status >= 400
raise_backend_exception('SEARCH_400', self.class, error) if error.status >= 400
else
raise error
end
Expand All @@ -116,22 +114,20 @@ def handle_429!(error)
return unless error.status == 429

StatsD.increment("#{Search::Service::STATSD_KEY_PREFIX}.exceptions", tags: ['exception:429'])
raise_backend_exception(error_code_name(error.status), self.class, error)
raise_backend_exception('SEARCH_429', self.class, error)
end

def handle_server_error!(error)
return unless [503, 504].include?(error.status)

exceptions = {
503 => 'SEARCH_503',
504 => 'SEARCH_504'
}
# Catch when the error's structure doesn't match what's usually expected.
message = error.body.is_a?(Hash) ? parse_messages(error).first : 'Search API is down'
message = error.body.is_a?(Hash) ? parse_messages(error).first : 'Search.gov is down'
save_error_details(message)
raise_backend_exception(error_code_name(error.status), self.class, error)
end

def error_code_name(error_status)
error_code_prefix = self.class.configuration.flipper_enabled? ? 'SEARCH_GSA' : 'SEARCH'

"#{error_code_prefix}_#{error_status}"
raise_backend_exception(exceptions[error.status], self.class, error)
end
end
end
32 changes: 0 additions & 32 deletions spec/lib/search/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,4 @@
expect(described_class.instance.service_name).to eq('Search/Results')
end
end

describe '#base_path' do
context 'search_use_v2_gsa Flipper is enabled' do
before do
Flipper.enable(:search_use_v2_gsa)
end

it 'provides api.gsa.gov search URL' do
expect(described_class.instance.base_path).to eq('https://api.gsa.gov/technology/searchgov/v2/results/i14y')
end
end

context 'search_use_v2_gsa Flipper is disabled' do
before do
Flipper.disable(:search_use_v2_gsa)
end

it 'provides search.usa.gov search URL' do
expect(described_class.instance.base_path).to eq('https://search.usa.gov/api/v2/search/i14y')
end
end

context 'Flipper raises a ActiveRecord::NoDatabaseError' do
before do
expect(Flipper).to receive(:enabled?).and_raise(ActiveRecord::NoDatabaseError)
end

it 'provides search.usa.gov search URL' do
expect(described_class.instance.base_path).to eq('https://search.usa.gov/api/v2/search/i14y')
end
end
end
end
79 changes: 1 addition & 78 deletions spec/lib/search/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

before do
allow_any_instance_of(described_class).to receive(:access_key).and_return('TESTKEY')
Flipper.disable(:search_use_v2_gsa)
end

describe '#results' do
Expand Down Expand Up @@ -50,18 +49,6 @@
end
end
end

it 'raises GSA exception if Flipper enabled', :aggregate_failures do
Flipper.enable(:search_use_v2_gsa)

VCR.use_cassette('search/empty_query', VCR::MATCH_EVERYTHING) do
expect { subject.results }.to raise_error do |e|
expect(e).to be_a(Common::Exceptions::BackendServiceException)
expect(e.status_code).to eq(400)
expect(e.errors.first.code).to eq('SEARCH_GSA_400')
end
end
end
end

context 'when the upstream API gives a 503' do
Expand All @@ -74,18 +61,6 @@
end
end
end

it 'raises GSA exception if Flipper enabled', :aggregate_failures do
Flipper.enable(:search_use_v2_gsa)

VCR.use_cassette('search/503', VCR::MATCH_EVERYTHING) do
expect { subject.results }.to raise_error do |e|
expect(e).to be_a(Common::Exceptions::BackendServiceException)
expect(e.status_code).to eq(503)
expect(e.errors.first.code).to eq('SEARCH_GSA_503')
end
end
end
end

context 'when the upstream API gives a 504' do
Expand All @@ -98,18 +73,6 @@
end
end
end

it 'raises GSA exception if Flipper enabled', :aggregate_failures do
Flipper.enable(:search_use_v2_gsa)

VCR.use_cassette('search/504', VCR::MATCH_EVERYTHING) do
expect { subject.results }.to raise_error do |e|
expect(e).to be_a(Common::Exceptions::BackendServiceException)
expect(e.status_code).to eq(504)
expect(e.errors.first.code).to eq('SEARCH_GSA_504')
end
end
end
end

context 'with an invalid API access key' do
Expand All @@ -124,20 +87,6 @@
end
end
end

it 'raises GSA exception if Flipper enabled', :aggregate_failures do
Flipper.enable(:search_use_v2_gsa)

VCR.use_cassette('search/invalid_access_key', VCR::MATCH_EVERYTHING) do
allow_any_instance_of(described_class).to receive(:access_key).and_return('INVALIDKEY')

expect { subject.results }.to raise_error do |e|
expect(e).to be_a(Common::Exceptions::BackendServiceException)
expect(e.status_code).to eq(400)
expect(e.errors.first.code).to eq('SEARCH_GSA_400')
end
end
end
end

context 'with an invalid affiliate' do
Expand All @@ -152,23 +101,9 @@
end
end
end

it 'raises GSA exception if Flipper enabled', :aggregate_failures do
Flipper.enable(:search_use_v2_gsa)

VCR.use_cassette('search/invalid_affiliate', VCR::MATCH_EVERYTHING) do
allow_any_instance_of(described_class).to receive(:affiliate).and_return('INVALID')

expect { subject.results }.to raise_error do |e|
expect(e).to be_a(Common::Exceptions::BackendServiceException)
expect(e.status_code).to eq(400)
expect(e.errors.first.code).to eq('SEARCH_GSA_400')
end
end
end
end

context 'when exceeding the API rate limit' do
context 'when exceeding the Search.gov rate limit' do
it 'raises an exception', :aggregate_failures do
VCR.use_cassette('search/exceeds_rate_limit', VCR::MATCH_EVERYTHING) do
expect { subject.results }.to raise_error do |e|
Expand All @@ -179,18 +114,6 @@
end
end

it 'raises GSA exception if Flipper enabled', :aggregate_failures do
Flipper.enable(:search_use_v2_gsa)

VCR.use_cassette('search/exceeds_rate_limit', VCR::MATCH_EVERYTHING) do
expect { subject.results }.to raise_error do |e|
expect(e).to be_a(Common::Exceptions::BackendServiceException)
expect(e.status_code).to eq(429)
expect(e.errors.first.code).to eq('SEARCH_GSA_429')
end
end
end

it 'increments the StatsD exception:429 counter' do
VCR.use_cassette('search/exceeds_rate_limit', VCR::MATCH_EVERYTHING) do
allow_any_instance_of(described_class).to receive(:raise_backend_exception).and_return(nil)
Expand Down
32 changes: 0 additions & 32 deletions spec/support/vcr_cassettes/search/503.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0fb030b

Please sign in to comment.