Skip to content

Commit

Permalink
Try Faraday 1.x.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <dblock@amazon.com>
  • Loading branch information
dblock committed Feb 6, 2025
1 parent 77fb9c4 commit 19e13ae
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Integration with Compatibility
on:
push:
branches:
- "*"
- "x"
paths-ignore:
- '*.md'
pull_request:
branches:
- "*"
- "x"
paths-ignore:
- '*.md'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Integration
on:
push:
branches:
- "*"
- "x"
paths-ignore:
- '*.md'
pull_request:
branches:
- "*"
- "x"
paths-ignore:
- '*.md'
jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-unreleased.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
jobs:
test:
env:
FARADAY_VERSION: '~> 1'
TEST_OPENSEARCH_SERVER: http://localhost:9200
PORT: 9200
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions lib/opensearch/transport/transport/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,24 +285,30 @@ def perform_request(method, path, params = {}, body = nil, _headers = nil, opts
ignore = Array(params.delete(:ignore)).compact.map(&:to_i)

begin
puts "TRY #{tries}, getting connection ..."
tries += 1
connection = get_connection or raise(Error, 'Cannot get new connection from pool.')
puts " CONNECTION #{connection} ..."

if connection.connection.respond_to?(:params) && connection.connection.params.respond_to?(:to_hash)
params = connection.connection.params.merge(params.to_hash)
end

url = connection.full_url(path, params)
puts " URL #{url} ..."

response = block.call(connection, url)
puts " RESPONSE #{response}, #{response.status} ..."

puts " FAILURES #{connection.failures} ..."
connection.healthy! if connection.failures.positive?

# Raise an exception so we can catch it for `retry_on_status`
if response.status.to_i >= 300 && @retry_on_status.include?(response.status.to_i)
__raise_transport_error(response)
end
rescue OpenSearch::Transport::Transport::ServerError => e
puts " ERROR #{e} ..."
raise e unless response && @retry_on_status.include?(response.status)
log_warn "[#{e.class}] Attempt #{tries} to get response from #{url}"
if tries <= (max_retries || DEFAULT_MAX_RETRIES)
Expand All @@ -312,6 +318,7 @@ def perform_request(method, path, params = {}, body = nil, _headers = nil, opts
raise e
end
rescue *host_unreachable_exceptions => e
puts " DEAD #{e} ..."
log_error "[#{e.class}] #{e.message} #{connection.host.inspect}"

connection.dead!
Expand All @@ -335,6 +342,7 @@ def perform_request(method, path, params = {}, body = nil, _headers = nil, opts
end

duration = Time.now - start
puts " DURATION #{duration} ..."

if response.status.to_i >= 300
__log_response method, path, params, body, url, response, nil, 'N/A', duration
Expand Down Expand Up @@ -369,9 +377,11 @@ def perform_request(method, path, params = {}, body = nil, _headers = nil, opts

warnings(response.headers['warning']) if response.headers&.[]('warning')

puts " RESPONSE #{response.status}, done."
Response.new response.status, json || response.body, response.headers
ensure
@last_request_at = Time.now
puts " ENSURE #{@last_request_at} ..."
end

# @abstract Returns an Array of connection errors specific to the transport implementation.
Expand Down
2 changes: 2 additions & 0 deletions lib/opensearch/transport/transport/http/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts =
headers
end

puts " RUN #{connection.connection}, #{method}, #{url}, #{body}, #{headers}"
response = connection.connection.run_request(
method.downcase.to_sym,
url,
(body ? __convert_to_json(body) : nil),
headers
)

puts " RESPONSE #{response.status}, #{response.body&.size}, #{response.headers}"
Response.new response.status, decompress_response(response.body), response.headers
end
end
Expand Down

0 comments on commit 19e13ae

Please sign in to comment.