gitlab-org--gitlab-foss/spec/services
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
..
applications fix specs 2017-11-02 08:49:36 +01:00
auth fix code style issues 2017-10-10 23:46:18 +02:00
boards Backport specs 2017-08-31 15:18:35 -03:00
chat_names
ci Revert back FetchKubernetesTokenService 2017-11-01 13:58:08 +01:00
clusters Add Helm InstallCommand 2017-11-07 17:12:41 +01:00
deploy_keys created services for keys 2017-09-15 15:35:24 +00:00
discussions Commenting on image diffs 2017-10-07 04:25:17 +00:00
emails Merge branch 'master' into digitalmoksha/gitlab-ce-feature/verify_secondary_emails 2017-10-05 12:48:22 +02:00
events Resolve "DashboardController#activity.json is slow due to SQL" 2017-11-06 16:52:56 +00:00
files Move GitHooksService to Gitlab::Git 2017-08-23 10:45:20 +02:00
gpg_keys Add some basic specs and refactor model and validations 2017-10-05 08:25:27 -05:00
groups Make Members with Owner and Master roles always able to create subgroups 2017-09-07 13:47:58 -05:00
issuable CE port of code changed for epics 2017-11-02 07:14:35 +01:00
issues Don't create todos for old issue assignees 2017-10-09 15:12:39 +02:00
keys Simplify a test 2017-09-21 13:19:05 +01:00
labels Enable the RSpec/HookArgument cop and auto-correct offenses 2017-08-10 19:29:42 -04:00
members Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
merge_requests Make merge_jid handling less stateful in MergeService 2017-10-27 22:33:48 +02:00
milestones Allow promoting project milestones to group milestones 2017-10-31 15:03:52 +00:00
notes Resolve "DashboardController#activity.json is slow due to SQL" 2017-11-06 16:52:56 +00:00
projects Rewrite the GitHub importer from scratch 2017-11-07 23:24:59 +01:00
protected_branches Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
protected_tags Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
quick_actions added date parameter for time tracking 2017-10-13 11:41:49 +01:00
search Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
tags Migrate Gitlab::Git::Repository#add_tag to Gitaly 2017-09-29 00:53:49 +02:00
test_hooks Fix a wrong `X-Gitlab-Event` header when testing webhooks 2017-09-07 17:40:32 +02:00
users Only cache the event for the fork-source when it exists 2017-10-22 20:24:47 +03:00
wiki_pages Merge branch 'wiki_title' into 'master' 2017-08-07 16:37:44 +00:00
access_token_validation_service_spec.rb
after_branch_delete_service_spec.rb
cohorts_service_spec.rb
compare_service_spec.rb
create_branch_service_spec.rb
create_deployment_service_spec.rb Fix more tests 2017-08-11 17:54:34 +08:00
create_release_service_spec.rb
create_snippet_service_spec.rb
delete_branch_service_spec.rb
delete_merged_branches_service_spec.rb Add a project forks spec helper 2017-10-07 11:46:23 +02:00
event_create_service_spec.rb Rework how recent push events are retrieved 2017-09-08 00:46:16 +02:00
git_push_service_spec.rb replace `is_default_branch?` with `default_branch?` 2017-08-29 11:14:42 +03:00
git_tag_push_service_spec.rb Enable the Layout/SpaceBeforeBlockBraces cop 2017-08-09 11:52:22 +02:00
gravatar_service_spec.rb
import_export_clean_up_service_spec.rb
note_summary_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
notification_service_spec.rb Merge branch '37691-subscription-fires-multiple-notifications' into 'master' 2017-10-12 14:39:51 +00:00
pages_service_spec.rb
preview_markdown_service_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
push_event_payload_service_spec.rb Migrate events into a new format 2017-08-10 17:45:44 +02:00
repair_ldap_blocked_user_service_spec.rb
repository_archive_clean_up_service_spec.rb
search_service_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
spam_service_spec.rb replace `is_spam?` with `spam?` 2017-08-29 11:14:42 +03:00
submit_usage_ping_service_spec.rb Store & use ConvDev percentages returned by Version app 2017-08-07 20:52:08 +02:00
system_hooks_service_spec.rb Add system hooks user_rename and group_rename 2017-11-03 11:26:52 +00:00
system_note_service_spec.rb Merge branch 'security-10-1' into '10-1-stable' 2017-10-17 15:58:58 -07:00
todo_service_spec.rb Refactor issuable destroy action 2017-11-06 13:02:50 +01:00
update_release_service_spec.rb
update_snippet_service_spec.rb
upload_service_spec.rb Change all `:empty_project` to `:project` 2017-08-02 17:47:31 -04:00
user_project_access_changed_service_spec.rb Move sidekiq-based project authorization refresh out of Projects::CreateService 2017-08-25 16:19:32 +01:00
web_hook_service_spec.rb Fix a wrong `X-Gitlab-Event` header when testing webhooks 2017-09-07 17:40:32 +02:00