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
background_migration
backup
badge
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
cache
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
cycle_analytics
data_builder
database Fix TRIGGER checks for MySQL 2017-11-06 23:34:07 +01:00
dependency_linker
diff
downtime_check
email
etag_caching
fogbugz_import
gfm
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
google_code_import
gpg
graphs
health_checks
hook_data fix the failing spec 2017-11-03 11:29:06 -04:00
i18n
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
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
prometheus
quick_actions
redis
saml
sanitizers
serializer
sherlock
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
sql
template
utils
view/presenter
allowable_spec.rb
app_logger_spec.rb
asciidoc_spec.rb
auth_spec.rb Add sudo API scope 2017-11-02 11:39:03 +01:00
background_migration_spec.rb
blame_spec.rb
changes_list_spec.rb
chat_name_token_spec.rb
ci_access_spec.rb
closing_issue_extractor_spec.rb
color_schemes_spec.rb
contributions_calendar_spec.rb
current_settings_spec.rb
daemon_spec.rb
database_spec.rb Add returning IDs to Gitlab::Database.bulk_insert 2017-11-07 22:28:57 +01:00
dependency_linker_spec.rb
downtime_check_spec.rb
encoding_helper_spec.rb
exclusive_lease_spec.rb
fake_application_settings_spec.rb
file_detector_spec.rb
file_finder_spec.rb
git_access_spec.rb
git_access_wiki_spec.rb
git_ref_validator_spec.rb
git_spec.rb
gitaly_client_spec.rb
github_import_spec.rb Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
gl_repository_spec.rb
gpg_spec.rb
group_hierarchy_spec.rb
highlight_spec.rb
i18n_spec.rb
identifier_spec.rb
import_sources_spec.rb Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
incoming_email_spec.rb
issuable_metadata_spec.rb
issuable_sorter_spec.rb
issuables_count_for_state_spec.rb
job_waiter_spec.rb
kubernetes_spec.rb
lazy_spec.rb
lfs_token_spec.rb
markup_helper_spec.rb
metrics_spec.rb Tests for Web transaction and remove simple transacton 2017-11-02 18:11:44 +01:00
multi_collection_paginator_spec.rb
optimistic_locking_spec.rb
other_markup_spec.rb
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
popen_spec.rb
project_authorizations_spec.rb
project_search_results_spec.rb
project_template_spec.rb
project_transfer_spec.rb
prometheus_client_spec.rb
reference_counter_spec.rb
reference_extractor_spec.rb
regex_spec.rb
repo_path_spec.rb
request_context_spec.rb
request_forgery_protection_spec.rb
request_profiler_spec.rb
route_map_spec.rb
routing_spec.rb
search_results_spec.rb
sentry_spec.rb
shell_spec.rb
sidekiq_status_spec.rb
sidekiq_throttler_spec.rb
snippet_search_results_spec.rb
ssh_public_key_spec.rb
string_range_marker_spec.rb
string_regex_marker_spec.rb
themes_spec.rb
untrusted_regexp_spec.rb
upgrader_spec.rb
uploads_transfer_spec.rb
url_blocker_spec.rb
url_builder_spec.rb
url_sanitizer_spec.rb
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
user_activities_spec.rb
utils_spec.rb
version_info_spec.rb
visibility_level_spec.rb
workhorse_spec.rb