Dont use DB connection in GlobalSearchSampler
As discovered in https://gitlab.com/gitlab-org/gitlab/-/issues/231248 the `GlobalSearchSampler` which invokes this `Elastic::MetricsUpdateService` is using an extra DB connection since it runs in it's own thread. This extra DB connection is not accounted for and can cause issues with the connection pool. We could account for this extra connection but it turns out the 2 database queries happening in here aren't really necessary anyway. The first checks if the Elasticsearch integration is enabled. Skipping this is safe since it will just set `0` for these metrics which is not a problem. The 2nd checks to see if prometheus monitoring is enabled. But this check was already happening before spawning the `GlobalSearchSampler` in [`config/initializers/7_prometheus_metrics.rb`]( https://gitlab.com/gitlab-org/gitlab/-/blob/17ab3d1634f5f1ca82334f270cf8239d7170b0a2/config/initializers/7_prometheus_metrics.rb#L41 ) so we can safely skip that too. The only other things happening now in this class are requests to Redis and don't require a DB connection.
Showing
Please register or sign in to comment