Commit 5b6853f9 authored by Kamil Trzciński's avatar Kamil Trzciński

Skip LB and retrieve connection of model

Since LB is initialised globally in a non-decomposed
run we will receive connection of `ActiveRecord::Base`.

Ensure that `GitlabSchemasMetrics` can use FF
parent 71dfd193
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Feature, stub_feature_flags: false do
RSpec.describe Feature, stub_feature_flags: false, query_analyzers: false do
include EE::GeoHelpers
describe '.enable' do
......
......@@ -12,8 +12,9 @@ module Gitlab
#
class GitlabSchemasMetrics < Base
class << self
def enabled?(_connection)
Feature.enabled?(:query_analyzer_gitlab_schema_metrics)
def enabled?
::Feature::FlipperFeature.table_exists? &&
Feature.enabled?(:query_analyzer_gitlab_schema_metrics)
end
def analyze(parsed)
......
......@@ -2,11 +2,11 @@
require 'spec_helper'
RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics do
RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_analyzers: false do
let(:analyzer) { described_class }
before do
stub_const('Gitlab::Database::QueryAnalyzer::ANALYZERS', [analyzer])
allow(Gitlab::Database::QueryAnalyzer.instance).to receive(:all_analyzers).and_return([analyzer])
end
it 'does not increment metrics if feature flag is disabled' do
......@@ -58,6 +58,10 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics do
end
with_them do
around do |example|
Gitlab::Database::QueryAnalyzer.instance.within { example.run }
end
it do
expect(described_class.schemas_metrics).to receive(:increment)
.with(expectations).and_call_original
......@@ -68,8 +72,9 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics do
end
def process_sql(model, sql)
model.connection.load_balancer.read_write do |connection|
Gitlab::Database::QueryAnalyzer.new.process_sql(sql, connection)
Gitlab::Database::QueryAnalyzer.instance.within do
# Skip load balancer and retrieve connection assigned to model
Gitlab::Database::QueryAnalyzer.instance.process_sql(sql, model.retrieve_connection)
end
end
end
......@@ -79,7 +79,6 @@ RSpec.configure do |config|
example.run
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