Commit 40802e2a authored by Sean McGivern's avatar Sean McGivern

Stop recording connection pool metrics for load balancing hosts

The cardinality of these is simply too high: for a single (Rails) host
on GitLab.com, we have 384 elements due to a combination of:

1. Puma threads.
2. Load balancing hosts.
3. Load balancing ports.

Realistically, the saturation for a load balancing connection pool
should never be higher than for ActiveRecord::Base anyway.
parent f96e9bf7
......@@ -193,8 +193,6 @@ They all have these labels:
1. `ActiveRecord::Base` is the main database connection.
1. `Geo::TrackingBase` is the connection to the Geo tracking database, if
enabled.
1. `Gitlab::Database::LoadBalancing::Host` is a connection used by [database
load balancing](../../database_load_balancing.md), if enabled.
1. `host` - the host name used to connect to the database.
1. `port` - the port used to connect to the database.
......
---
title: Stop recording connection pool metrics for load balancing hosts
merge_request: 33749
author:
type: removed
......@@ -6,15 +6,12 @@ module EE
module Samplers
module DatabaseSampler
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
private
override :host_stats
def host_stats
super
.concat(geo_connection_stats)
.concat(load_balancing_connection_stats)
super.concat(geo_connection_stats)
end
def geo_connection_stats
......@@ -22,23 +19,6 @@ module EE
[{ labels: labels_for_class(Geo::TrackingBase), stats: Geo::TrackingBase.connection_pool.stat }]
end
def load_balancing_connection_stats
return [] unless load_balancing_enabled?
ActiveRecord::Base.connection.load_balancer.host_list.hosts.map do |host|
{
labels: { host: host.host, port: host.port, class: 'Gitlab::Database::LoadBalancing::Host' },
stats: host.pool.stat
}
end
end
def load_balancing_enabled?
strong_memoize(:load_balancing_enabled) do
::Gitlab::Database::LoadBalancing.enable?
end
end
end
end
end
......
......@@ -45,47 +45,5 @@ describe Gitlab::Metrics::Samplers::DatabaseSampler do
end
end
end
context 'for Gitlab::Database::LoadBalancing::Host' do
let(:labels) { { class: 'Gitlab::Database::LoadBalancing::Host' } }
context 'when database load balancing is enabled' do
let(:hosts) { %w[secondary-1 secondary-2] }
let(:proxy) { ::Gitlab::Database::LoadBalancing::ConnectionProxy.new(hosts) }
before do
allow(ActiveRecord::Base).to receive(:connection).and_return(proxy)
allow(::Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
it 'samples connection pool statistics for all hosts' do
hosts.each do |host|
expected_labels = a_hash_including(host: host, **labels)
expect(subject.metrics[:size]).to receive(:set).with(expected_labels, a_value >= 1)
expect(subject.metrics[:connections]).to receive(:set).with(expected_labels, a_value >= 0)
expect(subject.metrics[:busy]).to receive(:set).with(expected_labels, a_value >= 0)
expect(subject.metrics[:dead]).to receive(:set).with(expected_labels, a_value >= 0)
expect(subject.metrics[:waiting]).to receive(:set).with(expected_labels, a_value >= 0)
end
subject.sample
end
end
context 'when database load balancing is not enabled' do
it 'records no samples' do
expect(subject.metrics[:size]).not_to receive(:set).with(a_hash_including(labels), anything)
subject.sample
end
it 'still records samples for other connections' do
expect(subject.metrics[:size]).to receive(:set)
subject.sample
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