Commit 554c583e authored by Stan Hu's avatar Stan Hu Committed by Robert Speicher

Lower multipart log threshold from 500 MB to 100 MB

This also makes the threshold configurable via an environment variable
`RACK_MULTIPART_LOGGING_BYTES`.

This will help identify uploads in
https://gitlab.com/gitlab-com/gl-infra/infrastructure/-/issues/12802.
parent 0f600368
...@@ -13,7 +13,7 @@ module Rack ...@@ -13,7 +13,7 @@ module Rack
def log_multipart_warning(req) def log_multipart_warning(req)
content_length = req.content_length.to_i content_length = req.content_length.to_i
return unless content_length > 500_000_000 return unless content_length > log_threshold
message = { message = {
message: "Large multipart body detected", message: "Large multipart body detected",
...@@ -32,6 +32,10 @@ module Rack ...@@ -32,6 +32,10 @@ module Rack
def log_large_multipart? def log_large_multipart?
Gitlab::Utils.to_boolean(ENV['ENABLE_RACK_MULTIPART_LOGGING'], default: true) && Gitlab.com? Gitlab::Utils.to_boolean(ENV['ENABLE_RACK_MULTIPART_LOGGING'], default: true) && Gitlab.com?
end end
def log_threshold
ENV.fetch('RACK_MULTIPART_LOGGING_BYTES', 100_000_000).to_i
end
end end
prepend MultipartPatch prepend MultipartPatch
......
...@@ -42,20 +42,38 @@ EOF ...@@ -42,20 +42,38 @@ EOF
end end
context 'with Content-Length over the limit' do context 'with Content-Length over the limit' do
it 'extracts multipart message' do shared_examples 'logs multipart message' do
env = Rack::MockRequest.env_for("/", multipart_fixture(:text, 500_000_001)) it 'extracts multipart message' do
env = Rack::MockRequest.env_for("/", multipart_fixture(:text, length))
expect(described_class).to receive(:log_large_multipart?).and_return(true)
expect(described_class).to receive(:log_multipart_warning).and_call_original
expect(described_class).to receive(:log_warn).with({
message: 'Large multipart body detected',
path: '/',
content_length: anything,
correlation_id: anything
})
params = described_class.parse_multipart(env)
expect(params.keys).to include(*%w(reply fileupload)) expect(described_class).to receive(:log_large_multipart?).and_return(true)
expect(described_class).to receive(:log_multipart_warning).and_call_original
expect(described_class).to receive(:log_warn).with({
message: 'Large multipart body detected',
path: '/',
content_length: anything,
correlation_id: anything
})
params = described_class.parse_multipart(env)
expect(params.keys).to include(*%w(reply fileupload))
end
end
context 'from environment' do
let(:length) { 1001 }
before do
stub_env('RACK_MULTIPART_LOGGING_BYTES', 1000)
end
it_behaves_like 'logs multipart message'
end
context 'default limit' do
let(:length) { 100_000_001 }
it_behaves_like 'logs multipart message'
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment