Skip to content

Collect database host metrics for all primaries

What does this MR do and why?

Collect database host metrics for all primary databases instead of the one solely pointed to by ActiveRecord::Base.

As mentioned in the issue, we'd also like to extend this sampling to report metrics from the replicas as well, but I'll add that in a separate MR.

Related to #346909 (closed)

How to set up and validate locally

You can look at the stats locally if you are setup with multiple databases. The easiest way is from the rails console:

GITLAB_USE_MODEL_LOAD_BALANCING=true rails c

If you start also with the environment variable GITLAB_LOAD_BALANCING_REUSE_PRIMARY_ci=main to reuse the main connection in ci, the Ci::ApplicationRecord metrics will not be reported since the call to connected? returns false. I assume that's what we want anyhow, since the main connections are shared in this mode.

  1. Collect the metrics
    metrics = Gitlab::Metrics::Samplers::DatabaseSampler.new.metrics
  2. Inspect individual values, for example connection pool size. You should see a metric for each database if you have multiple running.
    metrics[:size].values

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Patrick Bair

Merge request reports