Commit 90cca776 authored by Sean McGivern's avatar Sean McGivern

Memoise database load balancing status

This sampler runs every few seconds, and in development mode, it can
flood the console with license load messages. This value can only change
during the lifetime of the sampler if someone uploads a new license, or
a license expires, but those are both pretty rare (and would need
associated configuration changes anyway).
parent 14822a68
...@@ -5,8 +5,12 @@ module EE ...@@ -5,8 +5,12 @@ module EE
module Metrics module Metrics
module Samplers module Samplers
module DatabaseSampler module DatabaseSampler
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
private private
override :host_stats
def host_stats def host_stats
super super
.concat(geo_connection_stats) .concat(geo_connection_stats)
...@@ -20,7 +24,7 @@ module EE ...@@ -20,7 +24,7 @@ module EE
end end
def load_balancing_connection_stats def load_balancing_connection_stats
return [] unless ::Gitlab::Database::LoadBalancing.enable? return [] unless load_balancing_enabled?
ActiveRecord::Base.connection.load_balancer.host_list.hosts.map do |host| ActiveRecord::Base.connection.load_balancer.host_list.hosts.map do |host|
{ {
...@@ -29,6 +33,12 @@ module EE ...@@ -29,6 +33,12 @@ module EE
} }
end end
end end
def load_balancing_enabled?
strong_memoize(:load_balancing_enabled) do
::Gitlab::Database::LoadBalancing.enable?
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