[ARVADOS] updated: ff71d32328a2ca555a5c6777f2ce65db50c75247

Git user git at public.curoverse.com
Wed Sep 21 11:18:19 EDT 2016


Summary of changes:
 .../app/controllers/application_controller.rb      | 14 ++++----
 apps/workbench/app/models/arvados_api_client.rb    |  2 +-
 apps/workbench/config/initializers/lograge.rb      |  3 +-
 .../controllers/application_controller_test.rb     | 37 ++++++++++++----------
 4 files changed, 31 insertions(+), 25 deletions(-)

       via  ff71d32328a2ca555a5c6777f2ce65db50c75247 (commit)
      from  78fedce2fadbe985c5b7ec0dbe26ad8cddfb6cdb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit ff71d32328a2ca555a5c6777f2ce65db50c75247
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Wed Sep 21 12:14:13 2016 -0300

    10029: Some changes/improvements described as follows:
    * client_session_id renamed to current_request_id
    * before_filter moved to be the first one
    * request id clearing after lograge is done logging it
    * added test to check for the request being cleared correctly
    * corrected test that check for request_id being passed to the api server

diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb
index cf9f223..0da5956 100644
--- a/apps/workbench/app/controllers/application_controller.rb
+++ b/apps/workbench/app/controllers/application_controller.rb
@@ -7,6 +7,7 @@ class ApplicationController < ActionController::Base
 
   ERROR_ACTIONS = [:render_error, :render_not_found]
 
+  prepend_before_filter :set_current_request_id, except: ERROR_ACTIONS
   around_filter :thread_clear
   around_filter :set_thread_api_token
   # Methods that don't require login should
@@ -18,7 +19,6 @@ class ApplicationController < ActionController::Base
   before_filter :check_user_profile, except: ERROR_ACTIONS
   before_filter :load_filters_and_paging_params, except: ERROR_ACTIONS
   before_filter :find_object_by_uuid, except: [:create, :index, :choose] + ERROR_ACTIONS
-  before_filter :set_client_session_id, except: ERROR_ACTIONS
   theme :select_theme
 
   begin
@@ -32,12 +32,6 @@ class ApplicationController < ActionController::Base
                 with: :render_exception)
   end
 
-  def set_client_session_id
-    # Session ID format: '<timestamp>-<9_digits_random_number>'
-    client_session_id = "#{Time.new.to_i}-#{sprintf('%09d', rand(0..10**9-1))}"
-    Thread.current[:client_session_id] = client_session_id
-  end
-
   def set_cache_buster
     response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
     response.headers["Pragma"] = "no-cache"
@@ -1219,4 +1213,10 @@ class ApplicationController < ActionController::Base
   def wiselinks_layout
     'body'
   end
+
+  def set_current_request_id
+    # Request ID format: '<timestamp>-<9_digits_random_number>'
+    current_request_id = "#{Time.new.to_i}-#{sprintf('%09d', rand(0..10**9-1))}"
+    Thread.current[:current_request_id] = current_request_id
+  end
 end
diff --git a/apps/workbench/app/models/arvados_api_client.rb b/apps/workbench/app/models/arvados_api_client.rb
index df77786..fc9635b 100644
--- a/apps/workbench/app/models/arvados_api_client.rb
+++ b/apps/workbench/app/models/arvados_api_client.rb
@@ -114,7 +114,7 @@ class ArvadosApiClient
                            Thread.current[:reader_tokens] ||
                            []) +
                           [Rails.configuration.anonymous_user_token]).to_json,
-      'client_session_id' => (Thread.current[:client_session_id] || ''),
+      'current_request_id' => (Thread.current[:current_request_id] || ''),
     }
     if !data.nil?
       data.each do |k,v|
diff --git a/apps/workbench/config/initializers/lograge.rb b/apps/workbench/config/initializers/lograge.rb
index 6d3d246..fa19667 100644
--- a/apps/workbench/config/initializers/lograge.rb
+++ b/apps/workbench/config/initializers/lograge.rb
@@ -3,9 +3,10 @@ ArvadosWorkbench::Application.configure do
   config.lograge.formatter = Lograge::Formatters::Logstash.new
   config.lograge.custom_options = lambda do |event|
     exceptions = %w(controller action format id)
-    params = {client_session_id: Thread.current[:client_session_id]}.
+    params = {current_request_id: Thread.current[:current_request_id]}.
              merge(event.payload[:params].except(*exceptions))
     params_s = Oj.dump(params)
+    Thread.current[:current_request_id] = nil # Clear for next request
     if params_s.length > 1000
       { params_truncated: params_s[0..1000] + "[...]" }
     else
diff --git a/apps/workbench/test/controllers/application_controller_test.rb b/apps/workbench/test/controllers/application_controller_test.rb
index 99b80a0..2554ec3 100644
--- a/apps/workbench/test/controllers/application_controller_test.rb
+++ b/apps/workbench/test/controllers/application_controller_test.rb
@@ -335,22 +335,27 @@ class ApplicationControllerTest < ActionController::TestCase
   end
 
   test "requesting to the API server includes client_session_id param" do
-    use_token :active do
-      fixture = api_fixture("collections")["foo_collection_in_aproject"]
-      c = Collection.find(fixture['uuid'])
-
-      got_query = nil
-      stub_api_calls
-      stub_api_client.expects(:post).with do |url, query, opts={}|
-        got_query = query
-        true
-      end.returns fake_api_response('{}', 200, {})
-      c.name = "name change for testing"
-      c.save
-
-      assert_includes got_query, 'client_session_id'
-      assert_match /\d{10}-\d{9}/, got_query['client_session_id']
-    end
+    got_query = nil
+    stub_api_calls
+    stub_api_client.stubs(:post).with do |url, query, opts={}|
+      got_query = query
+      true
+    end.returns fake_api_response('{}', 200, {})
+
+    Rails.configuration.anonymous_user_token =
+      api_fixture("api_client_authorizations", "anonymous", "api_token")
+    @controller = ProjectsController.new
+    test_uuid = "zzzzz-j7d0g-zzzzzzzzzzzzzzz"
+    get(:show, {id: test_uuid})
+
+    assert_includes got_query, 'current_request_id'
+    assert_match /\d{10}-\d{9}/, got_query['current_request_id']
+  end
+
+  test "current_request_id is nil after a request" do
+    @controller = NodesController.new
+    get(:index, {}, session_for(:active))
+    assert_nil Thread.current[:current_request_id]
   end
 
   [".navbar .login-menu a",

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list