Skip to content
Snippets Groups Projects
Commit 57a3cb6f authored by Rémy Coutable's avatar Rémy Coutable
Browse files

Merge branch 'gitlab-database-load_balancing-stub' into 'master'

Introduce `gitlab-database-load_balancing` stub

See merge request gitlab-org/gitlab!137634



Merged-by: default avatarRémy Coutable <remy@rymai.me>
Approved-by: default avatarRémy Coutable <remy@rymai.me>
Reviewed-by: default avatarRémy Coutable <remy@rymai.me>
Co-authored-by: default avatarKamil Trzciński <ayufan@ayufan.eu>
parents c4860340 a750116e
No related branches found
No related tags found
1 merge request!137634Introduce `gitlab-database-load_balancing` stub
Pipeline #1081533401 passed
Showing
with 577 additions and 2 deletions
......@@ -35,3 +35,6 @@ include:
- local: .gitlab/ci/templates/gem.gitlab-ci.yml
inputs:
gem_name: "gitlab-secret_detection"
- local: .gitlab/ci/templates/gem.gitlab-ci.yml
inputs:
gem_name: "gitlab-database-load_balancing"
......@@ -21,6 +21,7 @@ spec:
# Ensure dependency updates don't fail child pipelines: https://gitlab.com/gitlab-org/gitlab/-/issues/417428
- "Gemfile.lock"
- "gems/gem.gitlab-ci.yml"
- "gems/gem-pg.gitlab-ci.yml"
# Ensure new cop in the monolith don't break internal gems Rubocop checks: https://gitlab.com/gitlab-org/gitlab/-/issues/419915
- ".rubocop.yml"
- "rubocop/**/*"
......
......@@ -44,6 +44,7 @@ PATH
remote: gems/gitlab-rspec
specs:
gitlab-rspec (0.1.0)
activerecord (>= 6.1, < 8)
activesupport (>= 6.1, < 8)
rspec (~> 3.0)
......
# The template generates jobs for gems vendored in the main GitLab project
# under `gem_path_prefix` (defaults to `gems/`).
#
# Inputs
# - `gem_name`: The name of the gem, i.e. if the gem is located at `gems/gitlab-rspec`, `gem_name` should be set to `gitlab-rspec`.
# - `gem_path_prefix`: The prefix of the gem path, i.e. if the gem is located at `vendor/gems/gitlab-rspec`, `gem_path_prefix` should be set to `vendor/gems/`. Defaults to `gems/`.
spec:
inputs:
gem_name:
gem_path_prefix:
default: "gems/"
---
workflow:
name: '[$[[inputs.gem_name]] gem] Ruby $RUBY_VERSION pipeline'
rules:
- when: always
variables:
BUNDLE_PATH: "vendor"
BUNDLE_FROZEN: "true"
GIT_DEPTH: "20"
# 'GIT_STRATEGY: clone' optimizes the pack-objects cache hit ratio
GIT_STRATEGY: "clone"
GIT_SUBMODULE_STRATEGY: "none"
GET_SOURCES_ATTEMPTS: "3"
# Default Ruby version for jobs that don't use .ruby_matrix
RUBY_VERSION: "3.0"
default:
image: "ruby:${RUBY_VERSION}"
cache:
key: "$[[inputs.gem_name]]-${RUBY_VERSION}"
paths:
- "$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/vendor/ruby"
before_script:
- cp config/{database.yml.postgresql,database.yml}
- "sed -i 's/username: postgres$/username: gitlab/g' config/database.yml"
- "sed -i 's/password:\\s*$/password: password/g' config/database.yml"
- "sed -i 's/host: localhost$/host: postgres/g' config/database.yml"
- cd $[[inputs.gem_path_prefix]]$[[inputs.gem_name]]
- ruby -v # Print out ruby version for debugging
- bundle_version=$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1 | sed -e 's/[[:space:]]//')
- gem install bundler --version "$bundle_version" --no-document # Bundler is not installed with the image
- bundle config # Show bundler configuration
- bundle install --jobs=$(nproc) --retry=3
.ruby_matrix:
parallel:
matrix:
- RUBY_VERSION: ["3.0", "3.1", "3.2"]
.ruby_and_postgres_matrix:
services:
- name: postgres:${POSTGRES_VERSION}
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
parallel:
matrix:
- RUBY_VERSION: ["3.0", "3.1", "3.2"]
POSTGRES_VERSION: ["12", "13", "14"]
rubocop:
extends: .ruby_matrix
rules:
- exists: ["$[[inputs.gem_path_prefix]]$[[inputs.gem_name]]/.rubocop.yml"]
script:
- bundle exec rubocop
rspec:
extends: .ruby_and_postgres_matrix
variables:
POSTGRES_USER: gitlab
POSTGRES_PASSWORD: password
script:
- RAILS_ENV=test bundle exec rspec
coverage: '/LOC \((\d+\.\d+%)\) covered.$/'
artifacts:
expire_in: 31d
when: always
paths:
- coverage/
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
# rspec failure tracking
.rspec_status
include:
- local: gems/gem-pg.gitlab-ci.yml
inputs:
gem_name: "gitlab-database-load_balancing"
--format documentation
--color
--require spec_helper
inherit_from:
- ../config/rubocop.yml
Gemfile/MissingFeatureCategory:
Exclude:
- 'Gemfile'
# frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in gitlab-safe_request_store.gemspec
gemspec
group :development, :test do
gem 'gitlab-rspec', path: '../gitlab-rspec'
end
gem 'activerecord-gitlab', path: '../activerecord-gitlab'
gem 'gitlab-utils', path: '../gitlab-utils'
gem 'gitlab-safe_request_store', path: '../gitlab-safe_request_store'
PATH
remote: ../activerecord-gitlab
specs:
activerecord-gitlab (0.2.0)
activerecord (>= 7)
PATH
remote: ../gitlab-rspec
specs:
gitlab-rspec (0.1.0)
activerecord (>= 6.1, < 8)
activesupport (>= 6.1, < 8)
rspec (~> 3.0)
PATH
remote: ../gitlab-safe_request_store
specs:
gitlab-safe_request_store (0.1.0)
request_store
PATH
remote: ../gitlab-utils
specs:
gitlab-utils (0.1.0)
actionview (>= 6.1.7.2)
activesupport (>= 6.1.7.2)
addressable (~> 2.8)
nokogiri (~> 1.15.2)
rake (~> 13.0)
PATH
remote: .
specs:
gitlab-database-load_balancing (0.1.0)
gitlab-net-dns (~> 0.9.2)
pg (~> 1.5.4)
rails (~> 7.0.8)
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.8)
actionpack (= 7.0.8)
activesupport (= 7.0.8)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.8)
actionpack (= 7.0.8)
activejob (= 7.0.8)
activerecord (= 7.0.8)
activestorage (= 7.0.8)
activesupport (= 7.0.8)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.8)
actionpack (= 7.0.8)
actionview (= 7.0.8)
activejob (= 7.0.8)
activesupport (= 7.0.8)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.8)
actionview (= 7.0.8)
activesupport (= 7.0.8)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.8)
actionpack (= 7.0.8)
activerecord (= 7.0.8)
activestorage (= 7.0.8)
activesupport (= 7.0.8)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.8)
activesupport (= 7.0.8)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.8)
activesupport (= 7.0.8)
globalid (>= 0.3.6)
activemodel (7.0.8)
activesupport (= 7.0.8)
activerecord (7.0.8)
activemodel (= 7.0.8)
activesupport (= 7.0.8)
activestorage (7.0.8)
actionpack (= 7.0.8)
activejob (= 7.0.8)
activerecord (= 7.0.8)
activesupport (= 7.0.8)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
binding_of_caller (1.0.0)
debug_inspector (>= 0.0.1)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.2.2)
crass (1.0.6)
date (3.3.3)
debug_inspector (1.1.0)
diff-lcs (1.5.0)
erubi (1.12.0)
gitlab-net-dns (0.9.2)
gitlab-styles (10.1.0)
rubocop (~> 1.50.2)
rubocop-graphql (~> 0.18)
rubocop-performance (~> 1.15)
rubocop-rails (~> 2.17)
rubocop-rspec (~> 2.22)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
json (2.6.3)
loofah (2.21.4)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.17.0)
net-imap (0.4.4)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.4.0)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.22.1)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
pg (1.5.4)
proc_to_ast (0.1.0)
coderay
parser
unparser
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.3)
racc (1.6.2)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.8)
actioncable (= 7.0.8)
actionmailbox (= 7.0.8)
actionmailer (= 7.0.8)
actionpack (= 7.0.8)
actiontext (= 7.0.8)
actionview (= 7.0.8)
activejob (= 7.0.8)
activemodel (= 7.0.8)
activerecord (= 7.0.8)
activestorage (= 7.0.8)
activesupport (= 7.0.8)
bundler (>= 1.15.0)
railties (= 7.0.8)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.8)
actionpack (= 7.0.8)
activesupport (= 7.0.8)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.7.0)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.1)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-parameterized (1.0.0)
rspec-parameterized-core (< 2)
rspec-parameterized-table_syntax (< 2)
rspec-parameterized-core (1.0.0)
parser
proc_to_ast
rspec (>= 2.13, < 4)
unparser
rspec-parameterized-table_syntax (1.0.1)
binding_of_caller
rspec-parameterized-core (< 2)
rspec-rails (6.0.3)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.12)
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.0)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-graphql (0.19.0)
rubocop (>= 0.87, < 2)
rubocop-performance (1.18.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.20.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-rspec (2.22.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.11.0)
thor (1.3.0)
timeout (0.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
unparser (0.6.8)
diff-lcs (~> 1.3)
parser (>= 3.2.0)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.12)
PLATFORMS
ruby
DEPENDENCIES
activerecord-gitlab!
gitlab-database-load_balancing!
gitlab-rspec!
gitlab-safe_request_store!
gitlab-styles (~> 10.1.0)
gitlab-utils!
pg (~> 1.5.4)
pry
rspec (~> 3.0)
rspec-parameterized (~> 1.0)
rspec-rails (~> 6.0.1)
rubocop (~> 1.50)
rubocop-rspec (~> 2.22)
BUNDLED WITH
2.4.16
# GitLab Database Load Balancing
This gem is a stub for a move of all `Gitlab::Database::LoadBalancing` code.
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %i[spec rubocop]
# frozen_string_literal: true
Gem::Specification.new do |spec|
spec.name = "gitlab-database-load_balancing"
spec.version = "0.1.0"
spec.authors = ["group::database"]
spec.email = ["engineering@gitlab.com"]
spec.summary = "GitLab specific support for read-only replicas"
spec.description = "Provides a code on top of existing databases to support read-only replicas."
spec.homepage = "https://gitlab.com/gitlab-org/gitlab/-/tree/master/gems/gitlab-safe_request_store"
spec.license = 'MIT'
spec.required_ruby_version = ">= 3.0"
spec.metadata["rubygems_mfa_required"] = "true"
spec.files = Dir['lib/**/*.rb']
spec.require_paths = ["lib"]
spec.add_runtime_dependency 'gitlab-net-dns', '~> 0.9.2'
spec.add_runtime_dependency "pg", '~> 1.5.4'
spec.add_runtime_dependency 'rails', '~> 7.0.8'
spec.add_development_dependency "gitlab-styles", "~> 10.1.0"
spec.add_development_dependency "pg", '~> 1.5.4'
spec.add_development_dependency "pry"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rspec-parameterized", "~> 1.0"
spec.add_development_dependency "rspec-rails", "~> 6.0.1"
spec.add_development_dependency "rubocop", "~> 1.50"
spec.add_development_dependency "rubocop-rspec", "~> 2.22"
end
# frozen_string_literal: true
require 'rails'
require 'rspec/mocks'
require 'rspec-parameterized'
require 'gitlab/rspec/all'
require 'gitlab/utils/all'
require 'gitlab/safe_request_store'
RSpec.configure do |config|
include StubRails
include NextInstanceOf
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.around(:example, :request_store) do |example|
::Gitlab::SafeRequestStore.ensure_request_store { example.run }
end
end
......@@ -2,6 +2,7 @@ PATH
remote: ../gitlab-rspec
specs:
gitlab-rspec (0.1.0)
activerecord (>= 6.1, < 8)
activesupport (>= 6.1, < 8)
rspec (~> 3.0)
......@@ -42,6 +43,11 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activemodel (7.0.7)
activesupport (= 7.0.7)
activerecord (7.0.7)
activemodel (= 7.0.7)
activesupport (= 7.0.7)
activesupport (7.0.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
......@@ -76,11 +82,9 @@ GEM
nokogiri (>= 1.12.0)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.8.4)
minitest (5.18.1)
multi_xml (0.6.0)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.3)
......
......@@ -2,6 +2,7 @@ PATH
remote: .
specs:
gitlab-rspec (0.1.0)
activerecord (>= 6.1, < 8)
activesupport (>= 6.1, < 8)
rspec (~> 3.0)
......@@ -21,6 +22,11 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activemodel (7.0.4.3)
activesupport (= 7.0.4.3)
activerecord (7.0.4.3)
activemodel (= 7.0.4.3)
activesupport (= 7.0.4.3)
activesupport (7.0.4.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
......
......@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
spec.files = Dir["lib/**/*.rb"]
spec.require_paths = ["lib"]
spec.add_runtime_dependency "activerecord", ">= 6.1", "< 8"
spec.add_runtime_dependency "activesupport", ">= 6.1", "< 8"
spec.add_runtime_dependency "rspec", "~> 3.0"
......
......@@ -4,6 +4,7 @@
require_relative "stub_env"
require_relative "next_instance_of"
require_relative "next_found_instance_of"
require_relative "stub_rails"
require_relative "configurations/time_travel"
......
# frozen_string_literal: true
require 'active_support'
require 'active_record'
# rubocop:disable Database/MultipleDatabases -- simulate Rails environment
# rubocop:disable Database/EstablishConnection -- simulate Rails environment
module StubRails
extend ActiveSupport::Concern
included do
class RailsApp < Rails::Application # rubocop:disable Lint/ConstantDefinitionInBlock -- load only when included
end
logger = Logger.new($stdout, level: Logger::INFO, formatter: ->(_, _, _, msg) { msg })
# load timezones
begin
TZInfo::DataSource.get
rescue TZInfo::DataSourceNotFound => e
raise e.exception "tzinfo-data is not present. " \
"Please add gem 'tzinfo-data' to your Gemfile and run bundle install"
end
Time.zone_default = Time.find_zone!(Rails.application.config.time_zone)
ActiveRecord::Base.configurations = Rails.application.config.database_configuration
# Create and connect to main database
begin
rails_establish_connection(logger)
rescue ActiveRecord::NoDatabaseError
rails_create_main_database(logger)
rails_establish_connection(logger)
end
end
def rails_establish_connection(_logger)
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.execute("SELECT VERSION()")
end
def rails_create_main_database(logger)
db_config = ActiveRecord::Base.configurations.find_db_config(Rails.env)
logger.info("Creating database #{db_config.database}...")
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(
database: "postgres",
schema_search_path: "public"
))
ActiveRecord::Base.connection.create_database(
db_config.database, { encoding: 'utf8' }.merge(db_config.configuration_hash))
end
end
# rubocop:enable Database/MultipleDatabases
# rubocop:enable Database/EstablishConnection
......@@ -2,6 +2,7 @@ PATH
remote: ../gitlab-rspec
specs:
gitlab-rspec (0.1.0)
activerecord (>= 6.1, < 8)
activesupport (>= 6.1, < 8)
rspec (~> 3.0)
......@@ -31,6 +32,11 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activemodel (7.0.5)
activesupport (= 7.0.5)
activerecord (7.0.5)
activemodel (= 7.0.5)
activesupport (= 7.0.5)
activesupport (7.0.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment