Skip to content
Snippets Groups Projects
Unverified Commit 9fe70d02 authored by Matt Kasa's avatar Matt Kasa
Browse files

Merge branch 'stomlinson/less-load-balancer-host-online-logs' into 'master'

Only log host online events if host was offline

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/131080



Merged-by: default avatarMatt Kasa <mkasa@gitlab.com>
Approved-by: default avatarStan Hu <stanhu@gmail.com>
Approved-by: default avatarMatt Kasa <mkasa@gitlab.com>
Co-authored-by: default avatarSimon Tomlinson <stomlinson@gitlab.com>
parents 62b4442e dc582e0b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -119,16 +119,19 @@ def offline!
def online?
return @online unless check_replica_status?
 
was_online = @online
refresh_status
 
if @online
# Log that the host came back online if it was previously offline
if @online && !was_online
::Gitlab::Database::LoadBalancing::Logger.info(
event: :host_online,
message: 'Host is online after replica status check',
db_host: @host,
db_port: @port
)
else
# Always log if the host goes offline
elsif !@online
::Gitlab::Database::LoadBalancing::Logger.warn(
event: :host_offline,
message: 'Host is offline after replica status check',
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@
 
require 'spec_helper'
 
RSpec.describe Gitlab::Database::LoadBalancing::Host do
RSpec.describe Gitlab::Database::LoadBalancing::Host, feature_category: :database do
let(:load_balancer) do
Gitlab::Database::LoadBalancing::LoadBalancer
.new(Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base))
Loading
Loading
@@ -124,13 +124,36 @@ def wrapped_exception(wrapper, original)
end
 
it 'refreshes the status' do
expect(Gitlab::Database::LoadBalancing::Logger).to receive(:info)
.with(hash_including(event: :host_online))
.and_call_original
expect(host).to be_online
end
 
context 'and the host was previously online' do
# Hosts are online by default
it 'does not log the online event' do
expect(Gitlab::Database::LoadBalancing::Logger)
.not_to receive(:info)
.with(hash_including(event: :host_online))
expect(host).to be_online
end
end
context 'and the host was previously offline' do
before do
host.offline!
end
it 'logs the online event' do
expect(Gitlab::Database::LoadBalancing::Logger)
.to receive(:info)
.with(hash_including(event: :host_online))
.and_call_original
expect(host).to be_online
end
end
context 'and replica is not up to date' do
before do
expect(host).to receive(:replica_is_up_to_date?).and_return(false)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment