Commit 1526964e authored by Thong Kuah's avatar Thong Kuah

Move LB-related specs to Core

This was missed from earlier moves
parent faa85a41
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'lograge', type: :request do
context 'with a log subscriber' do
include_context 'parsed logs'
include_context 'clear DB Load Balancing configuration'
let(:subscriber) { Lograge::LogSubscribers::ActionController.new }
let(:event) do
ActiveSupport::Notifications::Event.new(
'process_action.action_controller',
Time.now,
Time.now,
2,
status: 200,
controller: 'HomeController',
action: 'index',
format: 'application/json',
method: 'GET',
path: '/home?foo=bar',
params: {},
db_runtime: 0.02,
view_runtime: 0.01
)
end
let(:logging_keys) do
%w[db_primary_wal_count
db_replica_wal_count
db_replica_count
db_replica_cached_count
db_primary_count
db_primary_cached_count
db_primary_duration_s
db_replica_duration_s]
end
context 'when load balancing is enabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
context 'with db payload' do
context 'when RequestStore is enabled', :request_store do
it 'includes db counters' do
subscriber.process_action(event)
expect(log_data).to include(*logging_keys)
end
end
context 'when RequestStore is disabled' do
it 'does not include db counters' do
subscriber.process_action(event)
expect(log_data).not_to include(*logging_keys)
end
end
end
end
context 'when load balancing is disabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(false)
end
it 'does not include db counters' do
subscriber.process_action(event)
expect(log_data).not_to include(*logging_keys)
end
end
end
end
...@@ -120,6 +120,7 @@ RSpec.describe 'lograge', type: :request do ...@@ -120,6 +120,7 @@ RSpec.describe 'lograge', type: :request do
context 'with a log subscriber' do context 'with a log subscriber' do
include_context 'parsed logs' include_context 'parsed logs'
include_context 'clear DB Load Balancing configuration'
let(:subscriber) { Lograge::LogSubscribers::ActionController.new } let(:subscriber) { Lograge::LogSubscribers::ActionController.new }
...@@ -195,9 +196,25 @@ RSpec.describe 'lograge', type: :request do ...@@ -195,9 +196,25 @@ RSpec.describe 'lograge', type: :request do
end end
context 'with db payload' do context 'with db payload' do
let(:db_load_balancing_logging_keys) do
%w[
db_primary_wal_count
db_replica_wal_count
db_replica_count
db_replica_cached_count
db_primary_count
db_primary_cached_count
db_primary_duration_s
db_replica_duration_s
]
end
before do
ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
end
context 'when RequestStore is enabled', :request_store do context 'when RequestStore is enabled', :request_store do
it 'includes db counters' do it 'includes db counters' do
ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
subscriber.process_action(event) subscriber.process_action(event)
expect(log_data).to include("db_count" => a_value >= 1, "db_write_count" => 0, "db_cached_count" => 0) expect(log_data).to include("db_count" => a_value >= 1, "db_write_count" => 0, "db_cached_count" => 0)
...@@ -206,12 +223,47 @@ RSpec.describe 'lograge', type: :request do ...@@ -206,12 +223,47 @@ RSpec.describe 'lograge', type: :request do
context 'when RequestStore is disabled' do context 'when RequestStore is disabled' do
it 'does not include db counters' do it 'does not include db counters' do
ActiveRecord::Base.connection.execute('SELECT pg_sleep(0.1);')
subscriber.process_action(event) subscriber.process_action(event)
expect(log_data).not_to include("db_count", "db_write_count", "db_cached_count") expect(log_data).not_to include("db_count", "db_write_count", "db_cached_count")
end end
end end
context 'when load balancing is enabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
context 'with db payload' do
context 'when RequestStore is enabled', :request_store do
it 'includes db counters for load balancing' do
subscriber.process_action(event)
expect(log_data).to include(*db_load_balancing_logging_keys)
end
end
context 'when RequestStore is disabled' do
it 'does not include db counters for load balancing' do
subscriber.process_action(event)
expect(log_data).not_to include(*db_load_balancing_logging_keys)
end
end
end
end
context 'when load balancing is disabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(false)
end
it 'does not include db counters for load balancing' do
subscriber.process_action(event)
expect(log_data).not_to include(*db_load_balancing_logging_keys)
end
end
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