diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-19 09:10:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-19 09:10:05 +0300 |
commit | 7f12b2dc7406ceb8a9b1bbd730b38ad70fc88405 (patch) | |
tree | c858f594d572c4eafc741425ad04e88eae95269e | |
parent | 7747c98443fd19821e89b3107fd784b417fe6216 (diff) |
Add latest changes from gitlab-org/gitlab@master
27 files changed, 156 insertions, 72 deletions
diff --git a/app/assets/javascripts/vue_merge_request_widget/components/extensions/status_icon.vue b/app/assets/javascripts/vue_merge_request_widget/components/extensions/status_icon.vue index 25b7e652657..dc748ba44f2 100644 --- a/app/assets/javascripts/vue_merge_request_widget/components/extensions/status_icon.vue +++ b/app/assets/javascripts/vue_merge_request_widget/components/extensions/status_icon.vue @@ -49,7 +49,7 @@ export default { <div :class="[ $options.EXTENSION_ICON_CLASS[iconName], - { 'mr-widget-extension-icon': !isLoading && level === 1 }, + { 'mr-widget-extension-icon gl-w-6': !isLoading && level === 1 }, { 'gl-p-2': isLoading || level === 1 }, ]" class="gl-rounded-full gl-mr-3 gl-relative gl-p-2" diff --git a/app/workers/loose_foreign_keys/cleanup_worker.rb b/app/workers/loose_foreign_keys/cleanup_worker.rb index 0d04c503fbf..0a3a834578a 100644 --- a/app/workers/loose_foreign_keys/cleanup_worker.rb +++ b/app/workers/loose_foreign_keys/cleanup_worker.rb @@ -34,7 +34,7 @@ module LooseForeignKeys # If two DBs are configured (Main, CI): minute 1 -> Main, minute 2 -> CI def current_connection_name_and_base_model minutes_since_epoch = Time.current.to_i / 60 - connections_with_name = Gitlab::Database.database_base_models.to_a # this will never be empty + connections_with_name = Gitlab::Database.database_base_models_with_gitlab_shared.to_a # this will never be empty connections_with_name[minutes_since_epoch % connections_with_name.count] end end diff --git a/doc/development/database/multiple_databases.md b/doc/development/database/multiple_databases.md index 7991043625e..9641ea37002 100644 --- a/doc/development/database/multiple_databases.md +++ b/doc/development/database/multiple_databases.md @@ -26,6 +26,7 @@ Each table of GitLab needs to have a `gitlab_schema` assigned: - `gitlab_main`: describes all tables that are being stored in the `main:` database (for example, like `projects`, `users`). - `gitlab_ci`: describes all CI tables that are being stored in the `ci:` database (for example, `ci_pipelines`, `ci_builds`). +- `gitlab_geo`: describes all Geo tables that are being stored in the `geo:` database (for example, like `project_registry`, `secondary_usage_data`). - `gitlab_shared`: describe all application tables that contain data across all decomposed databases (for example, `loose_foreign_keys_deleted_records`) for models that inherit from `Gitlab::Database::SharedModel`. - `gitlab_internal`: describe all internal tables of Rails and PostgreSQL (for example, `ar_internal_metadata`, `schema_migrations`, `pg_*`). - `...`: more schemas to be introduced with additional decomposed databases @@ -34,6 +35,7 @@ The usage of schema enforces the base class to be used: - `ApplicationRecord` for `gitlab_main` - `Ci::ApplicationRecord` for `gitlab_ci` +- `Geo::TrackingBase` for `gitlab_geo` - `Gitlab::Database::SharedModel` for `gitlab_shared` ### The impact of `gitlab_schema` diff --git a/doc/update/package/convert_to_ee.md b/doc/update/package/convert_to_ee.md index e47e1d49927..9f8e56c460c 100644 --- a/doc/update/package/convert_to_ee.md +++ b/doc/update/package/convert_to_ee.md @@ -63,6 +63,12 @@ The steps can be summed up to: piped script, you can first [check its contents](https://packages.gitlab.com/gitlab/gitlab-ee/install). + NOTE: + If you want to use `dpkg`/`rpm` instead of `apt-get`/`yum`, go through the first + step to find the current GitLab version, then follow + [Update using a manually-downloaded package](index.md#upgrade-using-a-manually-downloaded-package), + and then [add your license](../../user/admin_area/license.md). + 1. Install the `gitlab-ee` package. The install automatically uninstalls the `gitlab-ce` package on your GitLab server. `reconfigure` Omnibus right after the `gitlab-ee` package is installed. **Make sure that you @@ -91,8 +97,7 @@ The steps can be summed up to: sudo gitlab-ctl reconfigure ``` -1. Now go to the GitLab Admin Area of your server (`/admin/subscription`) and - [add your license](../../user/admin_area/license.md). +1. Now activate GitLab Enterprise Edition by [adding your license](../../user/admin_area/license.md). 1. After you confirm that GitLab is working as expected, you may remove the old Community Edition repository: @@ -111,8 +116,3 @@ The steps can be summed up to: That's it! You can now use GitLab Enterprise Edition! To update to a newer version, follow [Update using the official repositories](index.md#upgrade-using-the-official-repositories). - -NOTE: -If you want to use `dpkg`/`rpm` instead of `apt-get`/`yum`, go through the first -step to find the current GitLab version and then follow -[Update using a manually-downloaded package](index.md#upgrade-using-a-manually-downloaded-package). diff --git a/doc/user/admin_area/index.md b/doc/user/admin_area/index.md index f8867638be1..5fd44cf8697 100644 --- a/doc/user/admin_area/index.md +++ b/doc/user/admin_area/index.md @@ -372,14 +372,16 @@ The following topics document the **Monitoring** section of the Admin Area. ### System Information +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/341248) in GitLab 15.2, support for relative time. "Uptime" statistic was renamed to "System started". + The **System Info** page provides the following statistics: -| Field | Description | -|:-------------|:------------| -| CPU | Number of CPU cores available | -| Memory Usage | Memory in use, and total memory available | -| Disk Usage | Disk space in use, and total disk space available | -| Uptime | Approximate uptime of the GitLab instance | +| Field | Description | +|:---------------|:--------------------------------------------------| +| CPU | Number of CPU cores available | +| Memory Usage | Memory in use, and total memory available | +| Disk Usage | Disk space in use, and total disk space available | +| System started | When the system hosting GitLab was started. In GitLab 15.1 and earlier, this was an uptime statistic. | These statistics are updated only when you navigate to the **System Info** page, or you refresh the page in your browser. diff --git a/doc/user/project/merge_requests/drafts.md b/doc/user/project/merge_requests/drafts.md index 13cc68f02dd..4bb6034c0bd 100644 --- a/doc/user/project/merge_requests/drafts.md +++ b/doc/user/project/merge_requests/drafts.md @@ -75,12 +75,10 @@ draft merge requests: ## Pipelines for drafts -When the [merged results pipelines](../../../ci/pipelines/merged_results_pipelines.md) -feature is enabled, draft merge requests run -[merge request pipelines](../../../ci/pipelines/merge_request_pipelines.md) only. +Draft merge requests run the same pipelines as merge request that are marked as ready. -To run merged results pipelines, you must -[mark the merge request as ready](#mark-merge-requests-as-ready). +In GitLab 15.0 and older, you must [mark the merge request as ready](#mark-merge-requests-as-ready) +if you want to run [merged results pipelines](../../../ci/pipelines/merged_results_pipelines.md). <!-- ## Troubleshooting diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 68df2282df6..8703365b678 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -63,13 +63,45 @@ module Gitlab }.compact.with_indifferent_access.freeze end + # This returns a list of databases that contains all the gitlab_shared schema + # tables. We can't reuse database_base_models because Geo does not support + # the gitlab_shared tables yet. + def self.database_base_models_with_gitlab_shared + @database_base_models_with_gitlab_shared ||= { + # Note that we use ActiveRecord::Base here and not ApplicationRecord. + # This is deliberate, as we also use these classes to apply load + # balancing to, and the load balancer must be enabled for _all_ models + # that inher from ActiveRecord::Base; not just our own models that + # inherit from ApplicationRecord. + main: ::ActiveRecord::Base, + ci: ::Ci::ApplicationRecord.connection_class? ? ::Ci::ApplicationRecord : nil + }.compact.with_indifferent_access.freeze + end + + # This returns a list of databases whose connection supports database load + # balancing. We can't reuse the database_base_models method because the Geo + # database does not support load balancing yet. + # + # TODO: https://gitlab.com/gitlab-org/geo-team/discussions/-/issues/5032 + def self.database_base_models_using_load_balancing + @database_base_models_with_gitlab_shared ||= { + # Note that we use ActiveRecord::Base here and not ApplicationRecord. + # This is deliberate, as we also use these classes to apply load + # balancing to, and the load balancer must be enabled for _all_ models + # that inher from ActiveRecord::Base; not just our own models that + # inherit from ApplicationRecord. + main: ::ActiveRecord::Base, + ci: ::Ci::ApplicationRecord.connection_class? ? ::Ci::ApplicationRecord : nil + }.compact.with_indifferent_access.freeze + end + # This returns a list of base models with connection associated for a given gitlab_schema def self.schemas_to_base_models @schemas_to_base_models ||= { gitlab_main: [self.database_base_models.fetch(:main)], gitlab_ci: [self.database_base_models[:ci] || self.database_base_models.fetch(:main)], # use CI or fallback to main - gitlab_shared: self.database_base_models.values, # all models - gitlab_internal: self.database_base_models.values # all models + gitlab_shared: database_base_models_with_gitlab_shared.values, # all models + gitlab_internal: database_base_models.values # all models }.with_indifferent_access.freeze end @@ -168,7 +200,7 @@ module Gitlab # can potentially upgrade from read to read-write mode (using a different connection), we specify # up-front that we'll explicitly use the primary for the duration of the operation. Gitlab::Database::LoadBalancing::Session.current.use_primary do - base_models = database_base_models.values + base_models = database_base_models_using_load_balancing.values base_models.reduce(block) { |blk, model| -> { model.uncached(&blk) } }.call end end diff --git a/lib/gitlab/database/each_database.rb b/lib/gitlab/database/each_database.rb index 0d876f5124f..02f008abf85 100644 --- a/lib/gitlab/database/each_database.rb +++ b/lib/gitlab/database/each_database.rb @@ -36,8 +36,7 @@ module Gitlab private def select_base_models(names) - base_models = Gitlab::Database.database_base_models - + base_models = Gitlab::Database.database_base_models_with_gitlab_shared return base_models if names.empty? names.each_with_object(HashWithIndifferentAccess.new) do |name, hash| @@ -48,7 +47,7 @@ module Gitlab end def with_shared_model_connections(shared_model, selected_databases, &blk) - Gitlab::Database.database_base_models.each_pair do |connection_name, connection_model| + Gitlab::Database.database_base_models_with_gitlab_shared.each_pair do |connection_name, connection_model| if shared_model.limit_connection_names next unless shared_model.limit_connection_names.include?(connection_name.to_sym) end diff --git a/lib/gitlab/database/gitlab_schema.rb b/lib/gitlab/database/gitlab_schema.rb index baf4cc48424..365a4283d4c 100644 --- a/lib/gitlab/database/gitlab_schema.rb +++ b/lib/gitlab/database/gitlab_schema.rb @@ -13,6 +13,8 @@ module Gitlab module Database module GitlabSchema + GITLAB_SCHEMAS_FILE = 'lib/gitlab/database/gitlab_schemas.yml' + # These tables are deleted/renamed, but still referenced by migrations. # This is needed for now, but should be removed in the future DELETED_TABLES = { @@ -93,7 +95,7 @@ module Gitlab end def self.tables_to_schema - @tables_to_schema ||= YAML.load_file(Rails.root.join('lib/gitlab/database/gitlab_schemas.yml')) + @tables_to_schema ||= YAML.load_file(Rails.root.join(GITLAB_SCHEMAS_FILE)) end def self.schema_names @@ -102,3 +104,5 @@ module Gitlab end end end + +Gitlab::Database::GitlabSchema.prepend_mod diff --git a/lib/gitlab/database/load_balancing.rb b/lib/gitlab/database/load_balancing.rb index 6517923d23e..5f9416fb4db 100644 --- a/lib/gitlab/database/load_balancing.rb +++ b/lib/gitlab/database/load_balancing.rb @@ -19,7 +19,7 @@ module Gitlab ].freeze def self.base_models - @base_models ||= ::Gitlab::Database.database_base_models.values.freeze + @base_models ||= ::Gitlab::Database.database_base_models_using_load_balancing.values.freeze end def self.each_load_balancer diff --git a/lib/gitlab/diff/highlight_cache.rb b/lib/gitlab/diff/highlight_cache.rb index f950d01fdf0..8e9dc3a305f 100644 --- a/lib/gitlab/diff/highlight_cache.rb +++ b/lib/gitlab/diff/highlight_cache.rb @@ -193,6 +193,8 @@ module Gitlab results = redis.hmget(key, file_paths) end + record_hit_ratio(results) + results.map! do |result| Gitlab::Json.parse(gzip_decompress(result), symbolize_names: true) unless result.nil? end @@ -215,6 +217,11 @@ module Gitlab def current_transaction ::Gitlab::Metrics::WebTransaction.current end + + def record_hit_ratio(results) + current_transaction&.increment(:gitlab_redis_diff_caching_requests_total) + current_transaction&.increment(:gitlab_redis_diff_caching_hits_total) if results.any?(&:present?) + end end end end diff --git a/lib/gitlab/metrics/subscribers/active_record.rb b/lib/gitlab/metrics/subscribers/active_record.rb index c1ecbe994cd..e3756a8c9f6 100644 --- a/lib/gitlab/metrics/subscribers/active_record.rb +++ b/lib/gitlab/metrics/subscribers/active_record.rb @@ -186,7 +186,10 @@ module Gitlab end ::Gitlab::Database.database_base_models.keys.each do |config_name| - counters << compose_metric_key(metric, nil, config_name) # main / ci + counters << compose_metric_key(metric, nil, config_name) # main / ci / geo + end + + ::Gitlab::Database.database_base_models_using_load_balancing.keys.each do |config_name| counters << compose_metric_key(metric, nil, config_name + ::Gitlab::Database::LoadBalancing::LoadBalancer::REPLICA_SUFFIX) # main_replica / ci_replica end end diff --git a/lib/gitlab/usage_data_counters/hll_redis_counter.rb b/lib/gitlab/usage_data_counters/hll_redis_counter.rb index 92d23a053c0..40581bda81b 100644 --- a/lib/gitlab/usage_data_counters/hll_redis_counter.rb +++ b/lib/gitlab/usage_data_counters/hll_redis_counter.rb @@ -37,9 +37,18 @@ module Gitlab ].freeze CATEGORIES_COLLECTED_FROM_METRICS_DEFINITIONS = %w[ + ci_users error_tracking ide_edit + importer + incident_management_alerts + pipeline_authoring + secure + snippets + source_code + terraform testing + work_items ].freeze # Track event on entity_id diff --git a/lib/gitlab/usage_data_counters/known_events/work_items.yml b/lib/gitlab/usage_data_counters/known_events/work_items.yml index 5930e711aa2..0c9c6026c46 100644 --- a/lib/gitlab/usage_data_counters/known_events/work_items.yml +++ b/lib/gitlab/usage_data_counters/known_events/work_items.yml @@ -9,8 +9,3 @@ redis_slot: users aggregation: weekly feature_flag: track_work_items_activity -- name: users_updating_weight_estimate - category: work_items - redis_slot: users - aggregation: weekly - feature_flag: track_work_items_activity diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index 84de21ea102..5ed54bb6921 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -94,7 +94,7 @@ namespace :gitlab do connection = Gitlab::Database.database_base_models['main'].connection databases_loaded << configure_database(connection) else - Gitlab::Database.database_base_models.each do |name, model| + Gitlab::Database.database_base_models_with_gitlab_shared.each do |name, model| next unless databases_with_tasks.any? { |db_with_tasks| db_with_tasks.name == name } databases_loaded << configure_database(model.connection, database_name: name) diff --git a/lib/tasks/gitlab/db/lock_writes.rake b/lib/tasks/gitlab/db/lock_writes.rake index b57c2860fe3..3a083036781 100644 --- a/lib/tasks/gitlab/db/lock_writes.rake +++ b/lib/tasks/gitlab/db/lock_writes.rake @@ -11,6 +11,9 @@ namespace :gitlab do schemas_for_connection = Gitlab::Database.gitlab_schemas_for_connection(connection) Gitlab::Database::GitlabSchema.tables_to_schema.each do |table_name, schema_name| + # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834 + next if schema_name == :gitlab_geo + if schemas_for_connection.include?(schema_name.to_sym) drop_write_trigger(database_name, connection, table_name) else @@ -24,6 +27,9 @@ namespace :gitlab do task unlock_writes: :environment do Gitlab::Database::EachDatabase.each_database_connection do |connection, database_name| Gitlab::Database::GitlabSchema.tables_to_schema.each do |table_name, schema_name| + # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834 + next if schema_name == :gitlab_geo + drop_write_trigger(database_name, connection, table_name) end drop_write_trigger_function(connection) diff --git a/spec/db/docs_spec.rb b/spec/db/docs_spec.rb index 20746e107fb..ad3705c3dbe 100644 --- a/spec/db/docs_spec.rb +++ b/spec/db/docs_spec.rb @@ -4,8 +4,11 @@ require 'spec_helper' RSpec.describe 'Database Documentation' do context 'for each table' do + # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834 + let(:database_base_models) { Gitlab::Database.database_base_models.select { |k, _| k != 'geo' } } + let(:all_tables) do - Gitlab::Database.database_base_models.flat_map { |_, m| m.connection.tables }.sort.uniq + database_base_models.flat_map { |_, m| m.connection.tables }.sort.uniq end let(:metadata_required_fields) do diff --git a/spec/lib/gitlab/database/each_database_spec.rb b/spec/lib/gitlab/database/each_database_spec.rb index 8345cdfb8fb..2a6eb8f779d 100644 --- a/spec/lib/gitlab/database/each_database_spec.rb +++ b/spec/lib/gitlab/database/each_database_spec.rb @@ -4,9 +4,10 @@ require 'spec_helper' RSpec.describe Gitlab::Database::EachDatabase do describe '.each_database_connection', :add_ci_connection do + let(:database_base_models) { { main: ActiveRecord::Base, ci: Ci::ApplicationRecord }.with_indifferent_access } + before do - allow(Gitlab::Database).to receive(:database_base_models) - .and_return({ main: ActiveRecord::Base, ci: Ci::ApplicationRecord }.with_indifferent_access) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(database_base_models) end it 'yields each connection after connecting SharedModel' do @@ -60,12 +61,20 @@ RSpec.describe Gitlab::Database::EachDatabase do end context 'when shared connections are not included' do + def clear_memoization(key) + Gitlab::Database.remove_instance_variable(key) if Gitlab::Database.instance_variable_defined?(key) + end + + before do + allow(Gitlab::Database).to receive(:database_base_models).and_return(database_base_models) + + # Clear the memoization because the return of Gitlab::Database#schemas_to_base_models depends stubbed value + clear_memoization(:@schemas_to_base_models) + clear_memoization(:@schemas_to_base_models_ee) + end + it 'only yields the unshared connections' do - if Gitlab::Database.has_config?(:ci) - expect(Gitlab::Database).to receive(:db_config_share_with).exactly(3).times.and_return(nil, 'main', 'main') - else - expect(Gitlab::Database).to receive(:db_config_share_with).twice.and_return(nil, 'main') - end + expect(Gitlab::Database).to receive(:db_config_share_with).exactly(3).times.and_return(nil, 'main', 'main') expect { |b| described_class.each_database_connection(include_shared: false, &b) } .to yield_successive_args([ActiveRecord::Base.connection, 'main']) @@ -79,7 +88,7 @@ RSpec.describe Gitlab::Database::EachDatabase do let(:model2) { Class.new(Gitlab::Database::SharedModel) } before do - allow(Gitlab::Database).to receive(:database_base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared) .and_return({ main: ActiveRecord::Base, ci: Ci::ApplicationRecord }.with_indifferent_access) end @@ -136,7 +145,7 @@ RSpec.describe Gitlab::Database::EachDatabase do let(:ci_model) { Class.new(Ci::ApplicationRecord) } before do - allow(Gitlab::Database).to receive(:database_base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared) .and_return({ main: ActiveRecord::Base, ci: Ci::ApplicationRecord }.with_indifferent_access) allow(main_model).to receive_message_chain('connection_db_config.name').and_return('main') diff --git a/spec/lib/gitlab/database/gitlab_schema_spec.rb b/spec/lib/gitlab/database/gitlab_schema_spec.rb index 611b2fbad72..72950895022 100644 --- a/spec/lib/gitlab/database/gitlab_schema_spec.rb +++ b/spec/lib/gitlab/database/gitlab_schema_spec.rb @@ -3,26 +3,27 @@ require 'spec_helper' RSpec.describe Gitlab::Database::GitlabSchema do describe '.tables_to_schema' do - subject { described_class.tables_to_schema } - it 'all tables have assigned a known gitlab_schema' do - is_expected.to all( - match([be_a(String), be_in([:gitlab_internal, :gitlab_shared, :gitlab_main, :gitlab_ci])]) + expect(described_class.tables_to_schema).to all( + match([be_a(String), be_in(Gitlab::Database.schemas_to_base_models.keys.map(&:to_sym))]) ) end # This being run across different databases indirectly also tests # a general consistency of structure across databases - Gitlab::Database.database_base_models.each do |db_config_name, db_class| - let(:db_data_sources) { db_class.connection.data_sources } - + Gitlab::Database.database_base_models.select { |k, _| k != 'geo' }.each do |db_config_name, db_class| context "for #{db_config_name} using #{db_class}" do + let(:db_data_sources) { db_class.connection.data_sources } + + # The Geo database does not share the same structure as all decomposed databases + subject { described_class.tables_to_schema.select { |_, v| v != :gitlab_geo } } + it 'new data sources are added' do missing_tables = db_data_sources.to_set - subject.keys expect(missing_tables).to be_empty, \ "Missing table(s) #{missing_tables.to_a} not found in #{described_class}.tables_to_schema. " \ - "Any new tables must be added to lib/gitlab/database/gitlab_schemas.yml." + "Any new tables must be added to #{described_class::GITLAB_SCHEMAS_FILE}." end it 'non-existing data sources are removed' do @@ -30,7 +31,7 @@ RSpec.describe Gitlab::Database::GitlabSchema do expect(extra_tables).to be_empty, \ "Extra table(s) #{extra_tables.to_a} found in #{described_class}.tables_to_schema. " \ - "Any removed or renamed tables must be removed from lib/gitlab/database/gitlab_schemas.yml." + "Any removed or renamed tables must be removed from #{described_class::GITLAB_SCHEMAS_FILE}." end end end diff --git a/spec/lib/gitlab/database/migrations/reestablished_connection_stack_spec.rb b/spec/lib/gitlab/database/migrations/reestablished_connection_stack_spec.rb index d197f39be40..c6327de98d1 100644 --- a/spec/lib/gitlab/database/migrations/reestablished_connection_stack_spec.rb +++ b/spec/lib/gitlab/database/migrations/reestablished_connection_stack_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Gitlab::Database::Migrations::ReestablishedConnectionStack do end describe '#with_restored_connection_stack' do - Gitlab::Database.database_base_models.each do |db_config_name, _| + Gitlab::Database.database_base_models_with_gitlab_shared.each do |db_config_name, _| context db_config_name do it_behaves_like "reconfigures connection stack", db_config_name do it 'does restore connection hierarchy' do diff --git a/spec/lib/gitlab/database/reindexing_spec.rb b/spec/lib/gitlab/database/reindexing_spec.rb index 0c576505e07..976b9896dfa 100644 --- a/spec/lib/gitlab/database/reindexing_spec.rb +++ b/spec/lib/gitlab/database/reindexing_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Gitlab::Database::Reindexing do include Database::DatabaseHelpers describe '.invoke' do - let(:databases) { Gitlab::Database.database_base_models } + let(:databases) { Gitlab::Database.database_base_models_with_gitlab_shared } let(:databases_count) { databases.count } it 'cleans up any leftover indexes' do diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index 064613074cd..452a662bdcb 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -337,7 +337,7 @@ RSpec.describe Gitlab::Database do let(:model2) { Class.new(base_model) } before do - allow(described_class).to receive(:database_base_models) + allow(described_class).to receive(:database_base_models_using_load_balancing) .and_return({ model1: model1, model2: model2 }.with_indifferent_access) end diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb index e643b58ee32..5350dda5fb2 100644 --- a/spec/lib/gitlab/diff/highlight_cache_spec.rb +++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb @@ -3,7 +3,8 @@ require 'spec_helper' RSpec.describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do - let(:merge_request) { create(:merge_request_with_diffs) } + let_it_be(:merge_request) { create(:merge_request_with_diffs) } + let(:diff_hash) do { ".gitignore-false-false-false" => [{ line_code: nil, rich_text: nil, text: "@@ -17,3 +17,4 @@ rerun.txt", type: "match", index: 0, old_pos: 17, new_pos: 17 }, @@ -229,10 +230,10 @@ RSpec.describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do end describe 'metrics' do - let(:transaction) { Gitlab::Metrics::WebTransaction.new({} ) } + let(:transaction) { Gitlab::Metrics::WebTransaction.new({}) } before do - allow(cache).to receive(:current_transaction).and_return(transaction) + allow(::Gitlab::Metrics::WebTransaction).to receive(:current).and_return(transaction) end it 'observes :gitlab_redis_diff_caching_memory_usage_bytes' do @@ -241,6 +242,18 @@ RSpec.describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do cache.write_if_empty end + + it 'records hit ratio metrics' do + expect(transaction) + .to receive(:increment).with(:gitlab_redis_diff_caching_requests_total).exactly(5).times + expect(transaction) + .to receive(:increment).with(:gitlab_redis_diff_caching_hits_total).exactly(4).times + + 5.times do + cache = described_class.new(merge_request.diffs) + cache.write_if_empty + end + end end describe '#key' do diff --git a/spec/services/work_items/task_list_reference_removal_service_spec.rb b/spec/services/work_items/task_list_reference_removal_service_spec.rb index 88fabe5fe40..91b7814ae92 100644 --- a/spec/services/work_items/task_list_reference_removal_service_spec.rb +++ b/spec/services/work_items/task_list_reference_removal_service_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe WorkItems::TaskListReferenceRemovalService do let_it_be(:developer) { create(:user) } let_it_be(:project) { create(:project, :repository).tap { |project| project.add_developer(developer) } } - let_it_be(:task) { create(:work_item, project: project) } + let_it_be(:task) { create(:work_item, project: project, title: 'Task title') } let_it_be(:single_line_work_item, refind: true) do create(:work_item, project: project, description: "- [ ] #{task.to_reference}+ single line") end @@ -82,7 +82,7 @@ RSpec.describe WorkItems::TaskListReferenceRemovalService do let(:line_number_end) { 1 } let(:work_item) { single_line_work_item } - it_behaves_like 'successful work item task reference removal service', '- [ ] My title 1 single line' + it_behaves_like 'successful work item task reference removal service', '- [ ] Task title single line' context 'when description does not contain a task' do let_it_be(:no_matching_work_item) { create(:work_item, project: project, description: 'no matching task') } @@ -103,7 +103,7 @@ RSpec.describe WorkItems::TaskListReferenceRemovalService do context 'when task mardown spans multiple lines' do it_behaves_like 'successful work item task reference removal service', - "Any text\n\n* [ ] Item to be converted\n My title 1 second line\n third line\n* [x] task\n\nMore text" + "Any text\n\n* [ ] Item to be converted\n Task title second line\n third line\n* [x] task\n\nMore text" end context 'when updating the work item fails' do diff --git a/spec/tasks/dev_rake_spec.rb b/spec/tasks/dev_rake_spec.rb index 41728faa0e0..14a5ccfa323 100644 --- a/spec/tasks/dev_rake_spec.rb +++ b/spec/tasks/dev_rake_spec.rb @@ -23,7 +23,7 @@ RSpec.describe 'dev rake tasks' do subject(:setup_task) { run_rake_task('dev:setup') } - let(:connections) { Gitlab::Database.database_base_models.values.map(&:connection) } + let(:connections) { Gitlab::Database.database_base_models_with_gitlab_shared.values.map(&:connection) } it 'sets up the development environment', :aggregate_failures do expect(Rake::Task['gitlab:setup']).to receive(:invoke) @@ -55,7 +55,7 @@ RSpec.describe 'dev rake tasks' do end let(:connections) do - Gitlab::Database.database_base_models.values.filter_map do |model| + Gitlab::Database.database_base_models_with_gitlab_shared.values.filter_map do |model| model.connection if Gitlab::Database.db_config_share_with(model.connection_db_config).nil? end end diff --git a/spec/tasks/gitlab/db_rake_spec.rb b/spec/tasks/gitlab/db_rake_spec.rb index d8199c09ca1..74bec406947 100644 --- a/spec/tasks/gitlab/db_rake_spec.rb +++ b/spec/tasks/gitlab/db_rake_spec.rb @@ -45,7 +45,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_unless_ci_uses_database_tasks - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'marks the migration complete on each database' do @@ -90,7 +90,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do let(:base_models) { { 'main' => main_model } } before do - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'prints a warning message' do @@ -110,7 +110,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do let(:base_models) { { 'main' => main_model } } before do - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'prints an error and exits' do @@ -136,6 +136,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do context 'when geo is not configured' do before do allow(ActiveRecord::Base).to receive_message_chain('configurations.configs_for').and_return([main_config]) + allow(Gitlab::Database).to receive(:has_config?).with(:geo).and_return(false) end context 'when the schema is already loaded' do @@ -260,7 +261,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_unless_ci_uses_database_tasks - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end context 'when geo is not configured' do @@ -444,7 +445,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_unless_ci_uses_database_tasks - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) allow(main_model.connection).to receive(:table_exists?).with('schema_migrations').and_return(true) allow(ci_model.connection).to receive(:table_exists?).with('schema_migrations').and_return(true) @@ -574,7 +575,7 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do before do skip_if_multiple_databases_not_setup - allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(base_models) end it 'delegates to Gitlab::Database::Reindexing without a specific database' do diff --git a/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb b/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb index 632e4fb3071..77190dc49d9 100644 --- a/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb +++ b/spec/workers/loose_foreign_keys/cleanup_worker_spec.rb @@ -169,7 +169,7 @@ RSpec.describe LooseForeignKeys::CleanupWorker do let(:expected_connection) { expected_connection_model.constantize.connection } before do - allow(Gitlab::Database).to receive(:database_base_models).and_return(database_base_models) + allow(Gitlab::Database).to receive(:database_base_models_with_gitlab_shared).and_return(database_base_models) if database_base_models.has_key?(:ci) Gitlab::Database::SharedModel.using_connection(database_base_models[:ci].connection) do |