Commit a86e1774 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add more specs for tracking transactions with HTTP requests

parent 63e5197e
...@@ -135,4 +135,24 @@ RSpec.describe Gitlab::Database::Transaction::Context do ...@@ -135,4 +135,24 @@ RSpec.describe Gitlab::Database::Transaction::Context do
it_behaves_like 'logs transaction data' it_behaves_like 'logs transaction data'
end end
context 'when there are too many external HTTP requests' do
before do
allow(::Gitlab::Metrics::Subscribers::ExternalHttp)
.to receive(:request_count)
.and_return(100)
end
it_behaves_like 'logs transaction data'
end
context 'when there are too many too long external HTTP requests' do
before do
allow(::Gitlab::Metrics::Subscribers::ExternalHttp)
.to receive(:duration)
.and_return(5.5)
end
it_behaves_like 'logs transaction data'
end
end end
...@@ -57,8 +57,36 @@ RSpec.describe Gitlab::Database::Transaction::Observer do ...@@ -57,8 +57,36 @@ RSpec.describe Gitlab::Database::Transaction::Observer do
end end
end end
pending 'logs a transaction if external requests rate has been exceeded' do context 'when external HTTP requests duration has been exceeded' do
raise it 'logs transaction details including exceeding thresholds' do
expect(Gitlab::AppJsonLogger).to receive(:info).with(
hash_including(
external_http_requests_count: 2,
external_http_requests_duration: 12
)
)
ActiveRecord::Base.transaction do
User.first
perform_stubbed_external_http_request(duration: 2)
perform_stubbed_external_http_request(duration: 10)
end
end
end
context 'when external HTTP requests count has been exceeded' do
it 'logs transaction details including exceeding thresholds' do
expect(Gitlab::AppJsonLogger).to receive(:info).with(
hash_including(external_http_requests_count: 55)
)
ActiveRecord::Base.transaction do
User.first
55.times { perform_stubbed_external_http_request(duration: 0.01) }
end
end
end end
def perform_stubbed_external_http_request(duration:) def perform_stubbed_external_http_request(duration:)
......
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