gitlab-org--gitlab-foss/spec/lib/gitlab
Yorick Peterse 4dfe26cd8b
Rewrite the GitHub importer from scratch
Prior to this MR there were two GitHub related importers:

* Github::Import: the main importer used for GitHub projects
* Gitlab::GithubImport: importer that's somewhat confusingly used for
  importing Gitea projects (apparently they have a compatible API)

This MR renames the Gitea importer to Gitlab::LegacyGithubImport and
introduces a new GitHub importer in the Gitlab::GithubImport namespace.
This new GitHub importer uses Sidekiq for importing multiple resources
in parallel, though it also has the ability to import data sequentially
should this be necessary.

The new code is spread across the following directories:

* lib/gitlab/github_import: this directory contains most of the importer
  code such as the classes used for importing resources.
* app/workers/gitlab/github_import: this directory contains the Sidekiq
  workers, most of which simply use the code from the directory above.
* app/workers/concerns/gitlab/github_import: this directory provides a
  few modules that are included in every GitHub importer worker.

== Stages

The import work is divided into separate stages, with each stage
importing a specific set of data. Stages will schedule the work that
needs to be performed, followed by scheduling a job for the
"AdvanceStageWorker" worker. This worker will periodically check if all
work is completed and schedule the next stage if this is the case. If
work is not yet completed this worker will reschedule itself.

Using this approach we don't have to block threads by calling `sleep()`,
as doing so for large projects could block the thread from doing any
work for many hours.

== Retrying Work

Workers will reschedule themselves whenever necessary. For example,
hitting the GitHub API's rate limit will result in jobs rescheduling
themselves. These jobs are not processed until the rate limit has been
reset.

== User Lookups

Part of the importing process involves looking up user details in the
GitHub API so we can map them to GitLab users. The old importer used
an in-memory cache, but this obviously doesn't work when the work is
spread across different threads.

The new importer uses a Redis cache and makes sure we only perform
API/database calls if absolutely necessary.  Frequently used keys are
refreshed, and lookup misses are also cached; removing the need for
performing API/database calls if we know we don't have the data we're
looking for.

== Performance & Models

The new importer in various places uses raw INSERT statements (as
generated by `Gitlab::Database.bulk_insert`) instead of using Rails
models. This allows us to bypass any validations and callbacks,
drastically reducing the number of SQL queries and Gitaly RPC calls
necessary to import projects.

To ensure the code produces valid data the corresponding tests check if
the produced rows are valid according to the model validation rules.
2017-11-07 23:24:59 +01:00
..
auth current_application_settings belongs on Gitlab::CurrentSettings 2017-08-31 13:38:33 +01:00
background_migration Handle null serialised commits in background migration 2017-10-17 12:15:40 +01:00
backup Stub ENV in the backup task spec file 2017-10-18 18:42:09 +02:00
badge Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
bare_repository_import Improve GitLab Import rake task to work with Hashed Storage and Subgroups 2017-11-07 19:11:42 +00:00
bitbucket_import Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
cache Add a Circuitbreaker for storage paths 2017-08-04 15:38:48 +02:00
checks Replaced subject with subject.exec in spec/lib/gitlab/checks/change_access_spec.rb 2017-11-06 14:33:10 +00:00
ci Fixed Status Warning Icon 2017-11-06 15:59:07 +01:00
conflict Create a Gitlab::Git submodule for conlict-related files 2017-10-12 22:03:15 -03:00
cycle_analytics Enable Layout/TrailingWhitespace cop and auto-correct offenses 2017-08-15 13:44:37 -04:00
data_builder Resolve "Error 500 in non-UTF8 branch names" 2017-09-12 14:07:31 +00:00
database Fix TRIGGER checks for MySQL 2017-11-06 23:34:07 +01:00
dependency_linker Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
diff Fix 500 error for old (somewhat) MRs 2017-10-30 12:30:31 +00:00
downtime_check
email Prevent new / renamed project from using a repository path that already exists on disk 2017-08-25 20:06:06 +02:00
etag_caching
fogbugz_import Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
gfm Fix rewriting issue references with group milestones 2017-09-20 09:55:54 +00:00
git Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
gitaly_client Incorporate Gitaly's OperationService.UserFFBranch RPC 2017-10-31 16:28:09 -03:00
github_import Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
gitlab_import Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
google_code_import Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
gpg Add more specs. 2017-10-05 22:43:44 -05:00
graphs Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
health_checks Replaces tag: true into :tag in the specs 2017-10-07 13:57:54 +02:00
hook_data fix the failing spec 2017-11-03 11:29:06 -04:00
i18n Only require simple_po_parser in rake task that needs it 2017-09-04 08:30:10 +02:00
import_export Merge branch 'master' into 38464-k8s-apps 2017-11-08 01:46:53 +09:00
kubernetes Add Helm InstallCommand 2017-11-07 17:12:41 +01:00
ldap Normalize LDAP DN when looking up identity 2017-10-31 17:13:50 +01:00
legacy_github_import Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
metrics Only enable unicorn metrics when not in sidekiq mode. 2017-11-02 21:27:28 +01:00
middleware Make subscriber tests pass, after refactoring metrics 2017-11-02 18:18:16 +01:00
o_auth Normalize LDAP DN when looking up identity 2017-10-31 17:13:50 +01:00
prometheus Enable Layout/TrailingWhitespace cop and auto-correct offenses 2017-08-15 13:44:37 -04:00
quick_actions added date parameter for time tracking 2017-10-13 11:41:49 +01:00
redis Don't depend on Rails for Redis configuration file paths 2017-08-15 15:08:56 -04:00
saml Normalize LDAP DN when looking up identity 2017-10-31 17:13:50 +01:00
sanitizers
serializer
sherlock Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
sidekiq_middleware Send SIGSTP before SIGTERM to actually give Sidekiq jobs 30s to finish when the memory killer kicks in 2017-11-02 15:33:19 +01:00
sidekiq_status
slash_commands Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
sql Don't break when building unions on empty collections 2017-10-04 22:49:41 +02:00
template Sort templates when fetching them 2017-08-31 15:45:48 +02:00
utils Move merging of Hashes out of the GroupDescendant concern 2017-10-04 22:49:42 +02:00
view/presenter Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
allowable_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
app_logger_spec.rb Memoize GitLab logger to reduce open file descriptors 2017-10-24 14:06:23 +03:00
asciidoc_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
auth_spec.rb Add sudo API scope 2017-11-02 11:39:03 +01:00
background_migration_spec.rb
blame_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
changes_list_spec.rb
chat_name_token_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
ci_access_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
closing_issue_extractor_spec.rb Add "implements" to the default issue closing message regex 2017-10-02 12:02:38 +00:00
color_schemes_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
contributions_calendar_spec.rb Merge branch '27616-fix-contributions-graph-utc-offset-mysql' into 'master' 2017-08-06 05:57:49 +00:00
current_settings_spec.rb Fix failure in current_settings_spec.rb 2017-10-20 18:33:00 +00:00
daemon_spec.rb Enable the RSpec/HookArgument cop and auto-correct offenses 2017-08-10 19:29:42 -04:00
database_spec.rb Add returning IDs to Gitlab::Database.bulk_insert 2017-11-07 22:28:57 +01:00
dependency_linker_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
downtime_check_spec.rb
encoding_helper_spec.rb Avoind unnecesary force_encoding operations 2017-10-18 21:30:29 -03:00
exclusive_lease_spec.rb Adds exclusive lease to Git garbage collect worker. 2017-09-07 18:52:04 +01:00
fake_application_settings_spec.rb
file_detector_spec.rb Cache issuable template names 2017-10-12 13:26:03 +01:00
file_finder_spec.rb Fix searching for files by path 2017-08-25 10:36:32 +01:00
git_access_spec.rb Replaces tag: true into :tag in the specs 2017-10-07 13:57:54 +02:00
git_access_wiki_spec.rb Create idea of read-only database 2017-10-06 22:37:40 +02:00
git_ref_validator_spec.rb Prevent branches or tags from starting with invalid characters (e.g. -, .) 2017-10-05 14:56:36 -07:00
git_spec.rb Resolve "Error 500 in non-UTF8 branch names" 2017-09-12 14:07:31 +00:00
gitaly_client_spec.rb Fix for Gitaly nil encoding issue 2017-10-03 08:03:19 +00:00
github_import_spec.rb Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
gl_repository_spec.rb Ensure all project factories use :repository trait or :empty_project 2017-08-01 14:51:52 -04:00
gpg_spec.rb Add more specs. 2017-10-05 22:43:44 -05:00
group_hierarchy_spec.rb Make it possible to limit ancestors in a GroupHierarchy 2017-10-04 22:49:42 +02:00
highlight_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
i18n_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
identifier_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
import_sources_spec.rb Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
incoming_email_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
issuable_metadata_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
issuable_sorter_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
issuables_count_for_state_spec.rb Re-use issue/MR counts for the pagination system 2017-09-05 11:53:45 +02:00
job_waiter_spec.rb Use event-based waiting in Gitlab::JobWaiter 2017-08-22 09:54:46 +01:00
kubernetes_spec.rb
lazy_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
lfs_token_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
markup_helper_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
metrics_spec.rb Tests for Web transaction and remove simple transacton 2017-11-02 18:11:44 +01:00
multi_collection_paginator_spec.rb Always use the same order specs for MultiCollectionPaginator 2017-10-11 11:27:59 +02:00
optimistic_locking_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
other_markup_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
otp_key_rotator_spec.rb
path_regex_spec.rb Ignore routes matching legacy_*_redirect in route specs 2017-11-06 11:20:23 +00:00
performance_bar_spec.rb
polling_interval_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
popen_spec.rb Resolve "Precompiled assets with digest strings are ignored in CI" 2017-10-03 14:47:56 +00:00
project_authorizations_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
project_search_results_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
project_template_spec.rb Simplify project page 2017-10-11 09:07:19 +00:00
project_transfer_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
prometheus_client_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
reference_counter_spec.rb Implement /internal/post_receive unified endpoint for PostReceive tasks 2017-08-31 11:31:45 -03:00
reference_extractor_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
regex_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
repo_path_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
request_context_spec.rb Enable the RSpec/HookArgument cop and auto-correct offenses 2017-08-10 19:29:42 -04:00
request_forgery_protection_spec.rb
request_profiler_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
route_map_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
routing_spec.rb
search_results_spec.rb Add a project forks spec helper 2017-10-07 11:46:23 +02:00
sentry_spec.rb Track the locale in Sentry so we know which ones are failing 2017-08-31 14:10:04 +02:00
shell_spec.rb Replaces tag: true into :tag in the specs 2017-10-07 13:57:54 +02:00
sidekiq_status_spec.rb Simplify check for running job on Redis 2017-10-13 10:17:41 +02:00
sidekiq_throttler_spec.rb Only require sidekiq-limit_fetch when enabled in settings 2017-08-21 12:56:22 +01:00
snippet_search_results_spec.rb
ssh_public_key_spec.rb Rework the permissions model for SSH key restrictions 2017-08-30 20:50:44 +01:00
string_range_marker_spec.rb Don't escape html entities when rich == raw line 2017-08-17 19:55:07 +02:00
string_regex_marker_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
themes_spec.rb Revert "Merge branch 'revert-f2421b2b' into 'master'" 2017-09-11 15:44:42 +00:00
untrusted_regexp_spec.rb
upgrader_spec.rb Use described_class when possible 2017-07-27 14:31:53 +02:00
uploads_transfer_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
url_blocker_spec.rb Merge branch 'rs-alphanumeric-ssh-params' into 'security-9-4' 2017-08-10 20:47:28 +01:00
url_builder_spec.rb Change all :empty_project to :project 2017-08-02 17:47:31 -04:00
url_sanitizer_spec.rb Remove those tests as they're not needed anymore 2017-10-03 23:06:55 +08:00
usage_data_spec.rb Fix spec. Fix usage ping. Fix warnings by adding new models and attributes. 2017-11-01 16:12:44 +09:00
user_access_spec.rb Ensure all project factories use :repository trait or :empty_project 2017-08-01 14:51:52 -04:00
user_activities_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
utils_spec.rb Add a linter for PO files 2017-08-31 14:10:04 +02:00
version_info_spec.rb Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
visibility_level_spec.rb Remove superfluous lib: true, type: redis, service: true, models: true, services: true, no_db: true, api: true 2017-07-27 14:31:53 +02:00
workhorse_spec.rb Support show-all-refs for git over HTTP 2017-10-30 15:20:36 +00:00