Commit 20b571c1 authored by allison.browne's avatar allison.browne

Limit amount of sentry data requested

Sentry client will now return an error if the amount
of data requested in list_issues is too large
parent de1d9ec4
...@@ -25,6 +25,12 @@ module Gitlab ...@@ -25,6 +25,12 @@ module Gitlab
!too_big? && !too_deep? !too_big? && !too_deep?
end end
def self.human_default_max_size
ActiveSupport::NumberHelper.number_to_human_size(
Gitlab::Utils::DeepSize::DEFAULT_MAX_SIZE
)
end
private private
def evaluate def evaluate
......
...@@ -4,6 +4,7 @@ module Sentry ...@@ -4,6 +4,7 @@ module Sentry
class Client class Client
Error = Class.new(StandardError) Error = Class.new(StandardError)
MissingKeysError = Class.new(StandardError) MissingKeysError = Class.new(StandardError)
ResponseTooBigError = Class.new(StandardError)
attr_accessor :url, :token attr_accessor :url, :token
...@@ -15,6 +16,8 @@ module Sentry ...@@ -15,6 +16,8 @@ module Sentry
def list_issues(issue_status:, limit:) def list_issues(issue_status:, limit:)
issues = get_issues(issue_status: issue_status, limit: limit) issues = get_issues(issue_status: issue_status, limit: limit)
check_valid_size(issues)
handle_mapping_exceptions do handle_mapping_exceptions do
map_to_errors(issues) map_to_errors(issues)
end end
...@@ -30,6 +33,16 @@ module Sentry ...@@ -30,6 +33,16 @@ module Sentry
private private
def check_valid_size(issues)
return if valid_size?(issues)
raise Client::ResponseTooBigError, "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."
end
def valid_size?(issues)
Gitlab::Utils::DeepSize.new(issues).valid?
end
def handle_mapping_exceptions(&block) def handle_mapping_exceptions(&block)
yield yield
rescue KeyError => e rescue KeyError => e
......
...@@ -42,4 +42,10 @@ describe Gitlab::Utils::DeepSize do ...@@ -42,4 +42,10 @@ describe Gitlab::Utils::DeepSize do
end end
end end
end end
describe '.human_default_max_size' do
it 'returns 1 MB' do
expect(described_class.human_default_max_size).to eq('1 MB')
end
end
end end
...@@ -192,6 +192,14 @@ describe Sentry::Client do ...@@ -192,6 +192,14 @@ describe Sentry::Client do
end end
end end
context 'sentry api response too large' do
it 'raises exception' do
allow(client).to receive(:valid_size?).and_return(false)
expect { subject }.to raise_error(Sentry::Client::ResponseTooBigError, "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}.")
end
end
it_behaves_like 'maps exceptions' it_behaves_like 'maps exceptions'
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