[ARVADOS] created: 810f32f306534bf9f16798608e550ef6e0b8025e
git at public.curoverse.com
git at public.curoverse.com
Tue Jan 7 23:22:56 EST 2014
at 810f32f306534bf9f16798608e550ef6e0b8025e (commit)
commit 810f32f306534bf9f16798608e550ef6e0b8025e
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Jan 7 20:22:04 2014 -0800
Show profile data in log if config.profiling_enabled. refs #1815
diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb
index 0ee4c99..a457efa 100644
--- a/apps/workbench/app/models/arvados_api_client.rb
+++ b/apps/workbench/app/models/arvados_api_client.rb
@@ -9,8 +9,11 @@ class ArvadosApiClient
@@client_mtx = Mutex.new
@@api_client = nil
+ @@profiling_enabled = Rails.configuration.profiling_enabled rescue false
def api(resources_kind, action, data=nil)
+ profile_checkpoint
+
@@client_mtx.synchronize do
if not @@api_client
@@api_client = HTTPClient.new
@@ -41,13 +44,18 @@ class ArvadosApiClient
end
else
query["_method"] = "GET"
- end
+ end
+ if @@profiling_enabled
+ query["_profile"] = "true"
+ end
header = {"Accept" => "application/json"}
+ profile_checkpoint { "Prepare request #{url}" }
msg = @@api_client.post(url,
query,
header: header)
+ profile_checkpoint 'API transaction'
if msg.status_code == 401
raise NotLoggedInException.new
@@ -68,6 +76,11 @@ class ArvadosApiClient
errors = errors.join("\n\n") if errors.is_a? Array
raise "API error #{msg.status_code}:\n\n#{errors}\n"
end
+ if resp[:_profile]
+ Rails.logger.info "API client: " \
+ "#{resp.delete(:_profile)[:request_time]} request_time"
+ end
+ profile_checkpoint 'Parse response'
resp
end
@@ -129,4 +142,14 @@ class ArvadosApiClient
def class_kind(resource_class)
resource_class.to_s.underscore
end
+
+ protected
+ def profile_checkpoint label=nil
+ label = yield if block_given?
+ t = Time.now
+ if label and @profile_t0
+ Rails.logger.info "API client: #{t - @profile_t0} #{label}"
+ end
+ @profile_t0 = t
+ end
end
diff --git a/apps/workbench/config/environments/development.rb.example b/apps/workbench/config/environments/development.rb.example
index e93ba6d..835d8fb 100644
--- a/apps/workbench/config/environments/development.rb.example
+++ b/apps/workbench/config/environments/development.rb.example
@@ -35,6 +35,9 @@ ArvadosWorkbench::Application.configure do
# Expands the lines which load the assets
config.assets.debug = true
+ # Log timing data for API transactions
+ config.profiling_enabled = true
+
config.arvados_login_base = 'http://arvados.local/login'
config.arvados_v1_base = 'http://arvados.local/arvados/v1'
config.arvados_insecure_https = true # true = do not check server certificate
diff --git a/apps/workbench/config/environments/production.rb.example b/apps/workbench/config/environments/production.rb.example
index 6c1569e..7dc2b00 100644
--- a/apps/workbench/config/environments/production.rb.example
+++ b/apps/workbench/config/environments/production.rb.example
@@ -65,6 +65,9 @@ ArvadosWorkbench::Application.configure do
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
+ # Log timing data for API transactions
+ config.profiling_enabled = false
+
config.arvados_login_base = 'https://arvados.local/login'
config.arvados_v1_base = 'https://arvados.local/arvados/v1'
config.arvados_insecure_https = false # true = do not check server certificate
diff --git a/apps/workbench/config/environments/test.rb.example b/apps/workbench/config/environments/test.rb.example
index e357702..e130ffc 100644
--- a/apps/workbench/config/environments/test.rb.example
+++ b/apps/workbench/config/environments/test.rb.example
@@ -35,6 +35,9 @@ ArvadosWorkbench::Application.configure do
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
+ # Log timing data for API transactions
+ config.profiling_enabled = false
+
config.arvados_login_base = 'http://arvados.local/login'
config.arvados_v1_base = 'https://arvados.local/arvados/v1'
config.arvados_insecure_https = true # true = do not check server certificate
commit 597fa321274909eb32af0c49a540f9fc07f13f7f
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Jan 7 13:07:33 2014 -0800
Provide response[_profile][request_time] if requested by client. refs #1815
diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index c6e7da0..13ee6ab 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -241,6 +241,7 @@ class ApplicationController < ActionController::Base
end
def thread_with_auth_info
+ Thread.current[:request_starttime] = Time.now
Thread.current[:api_url_base] = root_url.sub(/\/$/,'') + '/arvados/v1'
begin
user = nil
@@ -363,4 +364,17 @@ class ApplicationController < ActionController::Base
(request.headers['Accept'].split(' ') &
['text/plain', '*/*']).count > 0
end
+
+ def render *opts
+ response = opts.first[:json]
+ if response &&
+ params[:_profile] &&
+ response.respond_to?(:[]) &&
+ Thread.current[:request_starttime]
+ response[:_profile] = {
+ request_time: Time.now - Thread.current[:request_starttime]
+ }
+ end
+ super *opts
+ end
end
commit ea12358e131b3528e101720edf896f074197dc1c
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Jan 7 13:04:16 2014 -0800
Ask API server for profile information. refs #1815
diff --git a/sdk/cli/bin/arv b/sdk/cli/bin/arv
index 7ce2fbe..e7d70d8 100755
--- a/sdk/cli/bin/arv
+++ b/sdk/cli/bin/arv
@@ -283,6 +283,7 @@ when
exit 0
else
request_body[:api_token] = ENV['ARVADOS_API_TOKEN']
+ request_body[:_profile] = true
result = client.execute(:api_method => eval(api_method),
:parameters => request_parameters,
:body => request_body,
commit e3d7eac7aa7067e32c0c8de26e66d84f370a7de8
Author: Tom Clegg <tom at curoverse.com>
Date: Tue Jan 7 12:56:11 2014 -0800
Check HTTP status before using API responses.
diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb
index 9c5fab9..0ee4c99 100644
--- a/apps/workbench/app/models/arvados_api_client.rb
+++ b/apps/workbench/app/models/arvados_api_client.rb
@@ -63,14 +63,10 @@ class ArvadosApiClient
if not resp.is_a? Hash
raise InvalidApiResponseException.new json
end
- if resp[:errors]
- #if resp[:errors][0] == 'Not logged in'
- # raise NotLoggedInException.new
- #else
- # errors = resp[:errors]
- # errors = errors.join("\n\n") if errors.is_a? Array
- # raise "API errors:\n\n#{errors}\n"
- #end
+ if msg.status_code != 200
+ errors = resp[:errors]
+ errors = errors.join("\n\n") if errors.is_a? Array
+ raise "API error #{msg.status_code}:\n\n#{errors}\n"
end
resp
end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list