The `Gitlab::Metrics::Samplers::DatabaseSampler` does not sample all databases
Today the Gitlab::Metrics::Samplers::DatabaseSampler
only samples the ActiveRecord::Base
and Geo::TrackingBase
.
This should be extended and improved to sample all Gitlab::Database.database_base_models
and attach as a label db_config_name
. The db_config_name
is a label used in all other metrics to indicate a connection as seen by config/database.yml
.
def host_stats
return [] unless ActiveRecord::Base.connected?
[{ labels: labels_for_class(ActiveRecord::Base), stats: ActiveRecord::Base.connection_pool.stat }]
end
There is one additional deficiency: This samples only primary connection, but does not sample any of replicas. We should consider sampling replicas as well.
@pbair Is this something that someone from groupdatabase takeover? This might be useful for Phase 4 and maybe have the ~"sharding-blocker::phase4" as a way to better observe utilisation of connection pools to ensure that we don't run in connection starving mode.
cc @pbair