[ARVADOS] created: 2.1.0-1882-g5e26583b1
Git user
git at public.arvados.org
Tue Feb 8 15:47:13 UTC 2022
at 5e26583b1c64dabc4181938a6826088ef2f1ddef (commit)
commit 5e26583b1c64dabc4181938a6826088ef2f1ddef
Author: Lucas Di Pentima <lucas.dipentima at curii.com>
Date: Tue Feb 8 12:44:52 2022 -0300
17492: Adds test confirming that req-id is added on exceptions.
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>
diff --git a/sdk/ruby/Gemfile b/sdk/ruby/Gemfile
index 3e300b3e5..1972df614 100644
--- a/sdk/ruby/Gemfile
+++ b/sdk/ruby/Gemfile
@@ -6,4 +6,5 @@ source 'https://rubygems.org'
gemspec
gem 'rake'
gem 'minitest', '>= 5.0.0'
+gem 'mocha', require: false
gem 'signet', '<= 0.11'
diff --git a/sdk/ruby/lib/arvados.rb b/sdk/ruby/lib/arvados.rb
index 023a1f829..a72a9f824 100644
--- a/sdk/ruby/lib/arvados.rb
+++ b/sdk/ruby/lib/arvados.rb
@@ -29,7 +29,7 @@ class Arvados
super(*args)
rescue => e
if !e.message.match(/.*req-[0-9a-zA-Z]{20}.*/)
- e.message += "\nRequest ID: #{e.headers['X-Request-Id'] or @request_id}"
+ raise $!, "#{$!} (Request ID: #{@request_id})", $!.backtrace
end
raise e
end
diff --git a/sdk/ruby/test/test_request_id.rb b/sdk/ruby/test/test_request_id.rb
new file mode 100644
index 000000000..2e25210ba
--- /dev/null
+++ b/sdk/ruby/test/test_request_id.rb
@@ -0,0 +1,22 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+require "arvados"
+require "mocha/minitest"
+
+class FakeError < StandardError; end
+class RequestIdTest < Minitest::Test
+ def test_raise_exception_with_request_id
+ arv = Arvados.new
+ clnt = arv.client
+ assert_nil clnt.request_id
+
+ Google::APIClient.any_instance.stubs(:execute).raises(FakeError.new("Uh-oh..."))
+ err = assert_raises(FakeError) do
+ arv.collection.get(uuid: "zzzzz-4zz18-zzzzzzzzzzzzzzz")
+ end
+ assert clnt.request_id != nil
+ assert_match /Uh-oh.*\(Request ID: req-[0-9a-zA-Z]{20}\)/, err.message
+ end
+end
\ No newline at end of file
commit a0dbcda78d2ce2d78d4b88ce024787a5437e3533
Author: Lucas Di Pentima <lucas.dipentima at curii.com>
Date: Fri Jan 7 18:58:54 2022 -0300
17492: Implements Arvados::ArvadosClient to set a request-id on every call.
Also, add the req-id is not present on response.
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index 9d4a60937..f20268d19 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -65,16 +65,6 @@ module Kernel
end
end
-class ArvadosClient < Google::APIClient
- def execute(*args)
- if args.last.is_a? Hash
- args.last[:headers] ||= {}
- args.last[:headers]['Accept'] ||= 'application/json'
- end
- super(*args)
- end
-end
-
def init_config
# read authentication data from arvados configuration file if present
lineno = 0
@@ -605,7 +595,7 @@ if ENV['ARVADOS_API_HOST_INSECURE']
end
begin
- client = ArvadosClient.new(:host => ENV['ARVADOS_API_HOST'], :application_name => 'arvados-cli', :application_version => '1.0')
+ client = Google::APIClient.new(:host => ENV['ARVADOS_API_HOST'], :application_name => 'arvados-cli', :application_version => '1.0')
arvados = client.discovered_api('arvados', ENV['ARVADOS_API_VERSION'])
rescue Exception => e
puts "Failed to connect to Arvados API server: #{e}"
@@ -708,14 +698,23 @@ else
})
end
+request_id = result.headers[:x_request_id]
begin
results = JSON.parse result.body
rescue JSON::ParserError => e
- abort "Failed to parse server response:\n" + e.to_s
+ err_msg = "Failed to parse server response:\n" + e.to_s
+ if request_id
+ err_msg += "\nRequest ID: #{request_id or client.request_id}"
+ end
+ abort err_msg
end
if results["errors"] then
- abort "Error: #{results["errors"][0]}"
+ err_message = results["errors"][0]
+ if request_id and !err_message.match(/.*req-[0-9a-zA-Z]{20}.*/)
+ err_message += " (#{request_id})"
+ end
+ abort "Error: #{err_message}"
end
case global_opts[:format]
diff --git a/sdk/ruby/lib/arvados.rb b/sdk/ruby/lib/arvados.rb
index d8a6be1b2..023a1f829 100644
--- a/sdk/ruby/lib/arvados.rb
+++ b/sdk/ruby/lib/arvados.rb
@@ -16,6 +16,26 @@ ActiveSupport::Inflector.inflections do |inflect|
end
class Arvados
+ class ArvadosClient < Google::APIClient
+ attr_reader :request_id
+
+ def execute(*args)
+ @request_id = "req-" + Random::DEFAULT.rand(2**128).to_s(36)[0..19]
+ if args.last.is_a? Hash
+ args.last[:headers] ||= {}
+ args.last[:headers]['X-Request-Id'] = @request_id
+ end
+ begin
+ super(*args)
+ rescue => e
+ if !e.message.match(/.*req-[0-9a-zA-Z]{20}.*/)
+ e.message += "\nRequest ID: #{e.headers['X-Request-Id'] or @request_id}"
+ end
+ raise e
+ end
+ end
+ end
+
class TransactionFailedError < StandardError
end
@@ -101,7 +121,7 @@ class Arvados
end
def client
- @client ||= Google::APIClient.
+ @client ||= ArvadosClient.
new(:host => config["ARVADOS_API_HOST"],
:application_name => @application_name,
:application_version => @application_version.to_s)
@@ -207,6 +227,9 @@ class Arvados
})
resp = JSON.parse result.body, :symbolize_names => true
if resp[:errors]
+ if !resp[:errors][0].match(/.*req-[0-9a-zA-Z]{20}.*/)
+ resp[:errors][0] += " (#{result.headers['X-Request-Id'] or client.request_id})"
+ end
raise Arvados::TransactionFailedError.new(resp[:errors])
elsif resp[:uuid] and resp[:etag]
self.new(resp)
commit d82ee3ca5711d81dbc2e3d8e97e91a4fe65408a7
Author: Lucas Di Pentima <lucas.dipentima at curii.com>
Date: Wed Jan 5 14:48:25 2022 -0300
17492: Removes unused & deprecated code.
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>
diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index 3750befb3..4625ef654 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -688,11 +688,6 @@ class ApplicationController < ActionController::Base
}
end
- def client_accepts_plain_text_stream
- (request.headers['Accept'].split(' ') &
- ['text/plain', '*/*']).count > 0
- end
-
def render *opts
if opts.first
response = opts.first[:json]
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list