DEV: Include message-bus request type in HTTP request data (#19762)

This commit is contained in:
David Taylor 2023-01-06 11:26:18 +00:00 committed by GitHub
parent 1ee9356a54
commit 66e8a35b4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View File

@ -125,13 +125,26 @@ class Middleware::RequestTracker
is_api: is_api, is_api: is_api,
is_user_api: is_user_api, is_user_api: is_user_api,
is_background: is_message_bus || is_topic_timings, is_background: is_message_bus || is_topic_timings,
background_type: is_message_bus ? "message-bus" : "topic-timings",
is_mobile: helper.is_mobile?, is_mobile: helper.is_mobile?,
track_view: track_view, track_view: track_view,
timing: timing, timing: timing,
queue_seconds: env['REQUEST_QUEUE_SECONDS'] queue_seconds: env['REQUEST_QUEUE_SECONDS']
} }
if h[:is_background]
h[:background_type] = if is_message_bus
if request.query_string.include?("dlp=t")
"message-bus-dlp"
elsif env["HTTP_DONT_CHUNK"]
"message-bus-dontchunk"
else
"message-bus"
end
else
"topic-timings"
end
end
if h[:is_crawler] if h[:is_crawler]
user_agent = env['HTTP_USER_AGENT'] user_agent = env['HTTP_USER_AGENT']
if user_agent && (user_agent.encoding != Encoding::UTF_8) if user_agent && (user_agent.encoding != Encoding::UTF_8)

View File

@ -2,10 +2,10 @@
RSpec.describe Middleware::RequestTracker do RSpec.describe Middleware::RequestTracker do
def env(opts = {}) def env(opts = {})
create_request_env.merge( path = opts.delete(:path) || "/path?bla=1"
create_request_env(path: path).merge(
"HTTP_HOST" => "http://test.com", "HTTP_HOST" => "http://test.com",
"HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36", "HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36",
"REQUEST_URI" => "/path?bla=1",
"REQUEST_METHOD" => "GET", "REQUEST_METHOD" => "GET",
"HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"rack.input" => StringIO.new "rack.input" => StringIO.new
@ -666,5 +666,21 @@ RSpec.describe Middleware::RequestTracker do
expect(headers["X-Runtime"].to_f).to be > 0 expect(headers["X-Runtime"].to_f).to be > 0
end end
it "can correctly log messagebus request types" do
tracker = Middleware::RequestTracker.new(app([200, {}, []]))
tracker.call(env(path: "/message-bus/abcde/poll"))
expect(@data[:is_background]).to eq(true)
expect(@data[:background_type]).to eq("message-bus")
tracker.call(env(path: "/message-bus/abcde/poll?dlp=t"))
expect(@data[:is_background]).to eq(true)
expect(@data[:background_type]).to eq("message-bus-dlp")
tracker.call(env("HTTP_DONT_CHUNK" => "True", path: "/message-bus/abcde/poll"))
expect(@data[:is_background]).to eq(true)
expect(@data[:background_type]).to eq("message-bus-dontchunk")
end
end end
end end