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