diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb b/spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb index 1b110ab02b5..a84658780b9 100644 --- a/spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb +++ b/spec/support/shared_examples/metrics/active_record_subscriber_shared_examples.rb @@ -5,9 +5,10 @@ RSpec.shared_examples 'store ActiveRecord info in RequestStore' do |db_role| 2.times do Gitlab::WithRequestStore.with_request_store do subscriber.sql(event) + connection = event.payload[:connection] if db_role == :primary - expect(described_class.db_counter_payload).to eq( + expected = { db_count: record_query ? 1 : 0, db_write_count: record_write_query ? 1 : 0, db_cached_count: record_cached_query ? 1 : 0, @@ -18,10 +19,13 @@ RSpec.shared_examples 'store ActiveRecord info in RequestStore' do |db_role| db_replica_count: 0, db_replica_duration_s: 0.0, db_primary_wal_count: record_wal_query ? 1 : 0, + db_primary_wal_cached_count: record_wal_query && record_cached_query ? 1 : 0, + db_replica_wal_cached_count: 0, db_replica_wal_count: 0 - ) + } + expected[:"db_primary_#{::Gitlab::Database.dbname(connection)}_duration_s"] = 0.002 if record_query elsif db_role == :replica - expect(described_class.db_counter_payload).to eq( + expected = { db_count: record_query ? 1 : 0, db_write_count: record_write_query ? 1 : 0, db_cached_count: record_cached_query ? 1 : 0, @@ -32,15 +36,35 @@ RSpec.shared_examples 'store ActiveRecord info in RequestStore' do |db_role| db_replica_count: record_query ? 1 : 0, db_replica_duration_s: record_query ? 0.002 : 0, db_replica_wal_count: record_wal_query ? 1 : 0, + db_replica_wal_cached_count: record_wal_query && record_cached_query ? 1 : 0, + db_primary_wal_cached_count: 0, db_primary_wal_count: 0 - ) + } + expected[:"db_replica_#{::Gitlab::Database.dbname(connection)}_duration_s"] = 0.002 if record_query else - expect(described_class.db_counter_payload).to eq( + expected = { db_count: record_query ? 1 : 0, db_write_count: record_write_query ? 1 : 0, db_cached_count: record_cached_query ? 1 : 0 - ) + } end + + expect(described_class.db_counter_payload).to eq(expected) + end + end + end + + context 'when multiple_database_metrics is disabled' do + before do + stub_feature_flags(multiple_database_metrics: false) + end + + it 'does not include per database metrics' do + Gitlab::WithRequestStore.with_request_store do + subscriber.sql(event) + connection = event.payload[:connection] + + expect(described_class.db_counter_payload).not_to include(:"db_replica_#{::Gitlab::Database.dbname(connection)}_duration_s") end end end @@ -71,7 +95,10 @@ RSpec.shared_examples 'record ActiveRecord metrics in a metrics transaction' do end if record_wal_query - expect(transaction).to receive(:increment).with("gitlab_transaction_db_#{db_role}_wal_count_total".to_sym, 1) if db_role + if db_role + expect(transaction).to receive(:increment).with("gitlab_transaction_db_#{db_role}_wal_count_total".to_sym, 1) + expect(transaction).to receive(:increment).with("gitlab_transaction_db_#{db_role}_wal_cached_count_total".to_sym, 1) if record_cached_query + end else expect(transaction).not_to receive(:increment).with("gitlab_transaction_db_#{db_role}_wal_count_total".to_sym, 1) if db_role end |