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
def log_multipart_warning(req)
content_length = req.content_length.to_i
return unless content_length > 500_000_000
return unless content_length > log_threshold
message = {
message: "Large multipart body detected",
......@@ -32,6 +32,10 @@ module Rack
def log_large_multipart?
Gitlab::Utils.to_boolean(ENV['ENABLE_RACK_MULTIPART_LOGGING'], default: true) && Gitlab.com?
end
def log_threshold
ENV.fetch('RACK_MULTIPART_LOGGING_BYTES', 100_000_000).to_i
end
end
prepend MultipartPatch
......
......@@ -42,20 +42,38 @@ EOF
end
context 'with Content-Length over the limit' do
it 'extracts multipart message' do
env = Rack::MockRequest.env_for("/", multipart_fixture(:text, 500_000_001))
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)
shared_examples 'logs multipart message' do
it 'extracts multipart message' do
env = Rack::MockRequest.env_for("/", multipart_fixture(:text, length))
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
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