18003: Merge branch 'main' into 18003-support-exists-contains-in-filter-groups
authorWard Vandewege <ward@curii.com>
Wed, 29 Sep 2021 19:34:29 +0000 (15:34 -0400)
committerWard Vandewege <ward@curii.com>
Wed, 29 Sep 2021 19:34:29 +0000 (15:34 -0400)
Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

services/api/app/controllers/application_controller.rb
services/api/test/integration/logging_test.rb [new file with mode: 0644]

index ff4cb88aec5a5ded76376f3d1a26b6b926bb5f7c..3750befb3fed3c1131120a79534a105fbe062ed0 100644 (file)
@@ -427,7 +427,7 @@ class ApplicationController < ActionController::Base
 
   def append_info_to_payload(payload)
     super
-    payload[:request_id] = response.headers['X-Request-Id']
+    payload[:request_id] = request.request_id
     payload[:client_ipaddr] = @remote_ip
     payload[:client_auth] = current_api_client_authorization.andand.uuid || nil
   end
diff --git a/services/api/test/integration/logging_test.rb b/services/api/test/integration/logging_test.rb
new file mode 100644 (file)
index 0000000..cbf9681
--- /dev/null
@@ -0,0 +1,28 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+require 'stringio'
+
+class LoggingTest < ActionDispatch::IntegrationTest
+  fixtures :collections
+
+  test "request_id" do
+    buf = StringIO.new
+    logcopy = ActiveSupport::Logger.new(buf)
+    logcopy.level = :info
+    begin
+      Rails.logger.extend(ActiveSupport::Logger.broadcast(logcopy))
+      get "/arvados/v1/collections/#{collections(:foo_file).uuid}",
+          params: {:format => :json},
+          headers: auth(:active).merge({ 'X-Request-Id' => 'req-aaaaaaaaaaaaaaaaaaaa' })
+      assert_response :success
+      assert_match /^{.*"request_id":"req-aaaaaaaaaaaaaaaaaaaa"/, buf.string
+    ensure
+      # We don't seem to have an "unbroadcast" option, so this is how
+      # we avoid filling buf with unlimited logs from subsequent
+      # tests.
+      logcopy.level = :fatal
+    end
+  end
+end