63 Commits
Author SHA1 Message Date
Lin Jen-Shin 5174d6c146 Merge remote-tracking branch 'upstream/master' into feature/runner-lock-on-project
* upstream/master: (337 commits)
  Update CHANGELOG for !4659
  Center the header logo for all Devise emails
  Add previews for all customized Devise emails
  Customize the Devise `unlock_instructions` email
  Customize the Devise `reset_password_instructions` email
  Customize the Devise `password_change` emails
  Use gitlab-git 10.2.0
  Use Git cached counters on project show page
  Fix indentation scss-lint errors
  Added title attribute to enties in tree view Closes #18353
  Banzai::Filter::ExternalLinkFilter use XPath
  Reduce queries in IssueReferenceFilter
  Use gitlab_git 10.1.4
  Fixed ordering in Project.find_with_namespace
  Fix images in emails
  Banzai::Filter::UploadLinkFilter use XPath
  Turn Group#owners into a has_many association
  Make project_id nullable
  CHANGELOG [ci skip]
  CHANGELOG [ci skip]
  ...
2016-06-17 19:52:55 +08:00
Rémy Coutable 46bba4e758 Merge branch 'fix/status-of-pipeline-without-builds' into 'master'
Improve pipeline status in case that pipeline has no jobs

## What does this MR do?

This MR resolves problem with pipeline status when there are no build in pipeline.

This can happen when builds were skipped - for example - by using `only`/`except` keyword in `.gitlab-ci.yml`.

## What are the relevant issue numbers?

Closes #17977

See merge request !4403
2016-06-16 11:48:36 +00:00
Stan Hu 919e3ed273 Merge branch 'fair-usage-of-shared-runners' into 'master'
Fair usage of Shared Runners

## What does this MR do?

Introduces a fair usage scheduler for shared runners.

It tries to assign builds to shared runner from projects that have the lowest number of builds currently running on shared runners.

**Example 1**:
```
We have following builds in queue:
build 1 for project 1
build 2 for project 1
build 3 for project 1
build 4 for project 2
build 5 for project 2
build 6 for project 3

With the new algorithm we will assign builds in following order:
- We choose build 1, because project 1 doesn't run currently any builds and has the lowest build number from projects that doesn't run builds,
- We choose build 4, because project 2 doesn't run currently any builds and has the lowest build number from projects that doesn't run builds,
- We choose build 6, because project 3 doesn't run currently any builds and has the lowest build number from projects that doesn't run builds,
- We choose build 2, because project 1 as other it runs 1 build,
- We choose build 5, because project 2 runs 1 build, where project 1 runs 2 builds now,
- We choose build 3, because project 1 and runs 2 builds.
```

 
**Example 2**:
```
We have following builds in queue:
build 1 for project 1
build 2 for project 1
build 3 for project 1
build 4 for project 2
build 5 for project 2
build 6 for project 3

With the new algorithm we will assign builds in following order:
- We choose build 1, because project 1 doesn't run currently any builds and has the lowest build number from projects that doesn't run builds,
- We finish build 1,
- We choose build 2, because project 1 doesn't run currently any builds and has the lowest build number from projects that doesn't run builds,
- We choose build 4, because project 2 doesn't run currently any builds and has the lowest build number from projects that doesn't run builds,
- We finish build 4,
- We choose build 5, because project 2 doesn't run currently any builds and has the lowest build number from projects that doesn't run builds,
- We choose build 6, because project 3 doesn't run currently any builds,
- We choose build 3, because project 1, 2 and 3 runs exactly one build now,
```

## Why was this MR needed?

Currently, we are scheduling builds using FIFO. This is catastrophic if there are projects that create a 100-300 jobs, this basically eats most of available shared runners.

## Performance

All this logic is implemented with the help of SQL queries, because this is the fastest way to process 1k-2k pending builds in queue.
It's not the fastest SQL query, because it sorts based on number of running_builds, and this forces to calculate a number of running builds for all dependent projects. However, since we have one/two shared runners that asks every few seconds for builds this should have minimal impact on DB performance.

```
 explain analyze SELECT "ci_builds".* FROM "ci_builds" JOIN (SELECT "ci_builds"."gl_project_id", count(case when status = 'running' AND runner_id = (SELECT "ci_runners"."id" FROM "ci_runners" WHERE "ci_runners"."is_shared" = 't') then 1 end) as running_builds FROM "ci_builds" INNER JOIN "projects" ON "projects"."id" = "ci_builds"."gl_project_id" AND "projects"."pending_delete" = 'f' WHERE "ci_builds"."type" IN ('Ci::Build') AND "ci_builds"."status" IN ('running', 'pending') AND "projects"."builds_enabled" = 't' AND "projects"."shared_runners_enabled" = 't' GROUP BY "ci_builds"."gl_project_id") AS projects ON ci_builds.gl_project_id=projects.gl_project_id WHERE "ci_builds"."type" IN ('Ci::Build') AND "ci_builds"."status" = 'pending' AND "ci_builds"."runner_id" IS NULL  ORDER BY projects.running_builds ASC, ci_builds.id ASC;
                                                                                  QUERY PLAN                                                                        
           
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------
 Sort  (cost=64777.28..64777.29 rows=1 width=1010) (actual time=301.794..302.535 rows=1537 loops=1)
   Sort Key: (count(CASE WHEN (((public.ci_builds.status)::text = 'running'::text) AND (public.ci_builds.runner_id = $0)) THEN 1 ELSE NULL::integer END)), public.ci
_builds.id
   Sort Method: quicksort  Memory: 1423kB
   ->  Nested Loop  (cost=63279.78..64777.27 rows=1 width=1010) (actual time=66.384..298.724 rows=1537 loops=1)
         ->  HashAggregate  (cost=63177.15..63177.30 rows=15 width=15) (actual time=65.641..65.851 rows=187 loops=1)
               InitPlan 1 (returns $0)
                 ->  Seq Scan on ci_runners  (cost=0.00..26963.66 rows=1 width=4) (actual time=1.145..34.381 rows=1 loops=1)
                       Filter: is_shared
                       Rows Removed by Filter: 6965
               ->  Nested Loop  (cost=0.00..36186.34 rows=2715 width=15) (actual time=0.065..29.717 rows=1710 loops=1)
                     ->  Index Scan using index_ci_builds_on_status on ci_builds  (cost=0.00..8913.95 rows=3577 width=15) (actual time=0.051..12.012 rows=2583 loops
=1)
                           Index Cond: ((status)::text = ANY ('{running,pending}'::text[]))
                           Filter: ((type)::text = 'Ci::Build'::text)
                           Rows Removed by Filter: 1219
                     ->  Index Scan using projects_pkey on projects  (cost=0.00..7.61 rows=1 width=4) (actual time=0.003..0.004 rows=1 loops=2583)
                           Index Cond: (id = public.ci_builds.gl_project_id)
                           Filter: ((NOT pending_delete) AND builds_enabled AND shared_runners_enabled)
                           Rows Removed by Filter: 0
         ->  Bitmap Heap Scan on ci_builds  (cost=102.63..106.64 rows=1 width=1002) (actual time=1.216..1.231 rows=8 loops=187)
               Recheck Cond: ((gl_project_id = public.ci_builds.gl_project_id) AND ((status)::text = 'pending'::text))
               Filter: ((runner_id IS NULL) AND ((type)::text = 'Ci::Build'::text))
               ->  BitmapAnd  (cost=102.63..102.63 rows=1 width=0) (actual time=1.201..1.201 rows=0 loops=187)
                     ->  Bitmap Index Scan on index_ci_builds_on_gl_project_id  (cost=0.00..10.52 rows=241 width=0) (actual time=0.406..0.406 rows=1944 loops=187)
                           Index Cond: (gl_project_id = public.ci_builds.gl_project_id)
                     ->  Bitmap Index Scan on index_ci_builds_on_status  (cost=0.00..91.78 rows=3089 width=0) (actual time=0.652..0.652 rows=3362 loops=187)
                           Index Cond: ((status)::text = 'pending'::text)
 Total runtime: 303.832 ms
```

## Specific runners

It doesn't affect the specific runners which still serve builds FIFO.

@stanhu @markpundsack @yorickpeterse What do you think?


See merge request !4634
2016-06-15 19:00:32 +00:00
Grzegorz Bizon d8670e114a Merge branch 'master' into fix/status-of-pipeline-without-builds
* master: (198 commits)
  Set inverse_of for Project/Services relation
  Fix admin hooks spec
  Prevent default disabled buttons and links.
  Add index on `requested_at` to the `members` table
  Rearrange order of tabs
  Fix admin active tab tests
  Show created_at in table column
  Nest li elements directly under ul
  Move builds tab to admin overview
  Add monitoring link with subtabs
  Add sub links to overview
  Add counter for abuse reports
  Remove admin layout-nav counters
  Move admin nav to horizontal layout nav
  Eager load project relations in IssueParser
  Use validate and required for environment and project
  Award Emoji can't be awarded on system notes backend
  Get rid of Gitlab::ShellEnv
  Update CHANGELOG.
  Fix project star tooltip on the fly.
  ...

Conflicts:
	app/services/ci/create_builds_service.rb
2016-06-15 20:14:25 +02:00
Grzegorz Bizon 2d495fce52 Remove reduntant method for building pipeline builds 2016-06-15 14:12:25 +02:00
Kamil Trzcinski 78d5828fb2 Fix typo 2016-06-15 13:06:01 +02:00
Lin Jen-Shin fd285f71d8 Merge branch 'master' into feature/runner-lock-on-project
* master: (147 commits)
  Update CHANGELOG
  Remove deprecated issues_tracker and issues_tracker_id from project
  Schema doesn’t reflect the changes of the last 3 migrations
  Revert CHANGELOG
  Also rename "find" in the specs
  Change to new Notes styleguide
  Add guide on changing a document's location
  Change logs.md location in README
  Move logs/logs.md to administration/logs.md
  Make "four phase test"
  Only show branches for revert / cherry-pick
  Instrument all Banzai::ReferenceParser classes
  Removed old comment from update_column_in_batches
  Update columns in batches until no rows are left
  Remove counters from Pipeline navigation
  Handle NULL migration errors in migration helpers
  Fix typo causing related branches to Error 500
  Improved SVG sanitizer specs to include smoke tests for clean.
  Refactored SVG sanitizer
  Added SVG sanitizer fix to the changelog
  ...
2016-06-14 23:05:26 +08:00
Grzegorz Bizon ab9a8643d8 Merge branch 'master' into fix/status-of-pipeline-without-builds
* master: (538 commits)
  Fix broken URI joining for `teamcity_url` with suffixes
  Factorize duplicated code into a method in BambooService and update specs
  Fix broken URI joining for `bamboo_url` with suffixes
  Honor credentials on calling Bamboo CI trigger
  Update CHANGELOG
  Use Issue.visible_to_user in Notes.search to avoid query duplication
  Project members with guest role can't access confidential issues
  Allow users to create confidential issues in private projects
  Update CHANGELOG
  Remove deprecated issues_tracker and issues_tracker_id from project
  Schema doesn’t reflect the changes of the last 3 migrations
  Apply reviewer notes: update CHANGELOG, adjust code formatting
  Move issue rendering tests into separate contexts
  Move change description to proper release and fix typo
  Add more information into RSS fead for issues
  Revert CHANGELOG
  Also rename "find" in the specs
  Change to new Notes styleguide
  Add guide on changing a document's location
  Change logs.md location in README
  ...

Conflicts:
	app/services/ci/create_builds_service.rb
	app/services/ci/create_pipeline_service.rb
	app/services/create_commit_builds_service.rb
	spec/models/ci/commit_spec.rb
	spec/services/ci/create_builds_service_spec.rb
	spec/services/create_commit_builds_service_spec.rb
2016-06-14 13:44:03 +02:00
Kamil Trzcinski 1685b9dc2e Optimise SQL query 2016-06-14 00:14:30 +02:00
Kamil Trzcinski ee2e583500 Fair usage of Shared Runners 2016-06-13 22:06:14 +02:00
Kamil Trzcinski 907c0e6796 Added initial version of deployments 2016-06-10 23:36:54 +02:00
Kamil Trzcinski 921c356b5e Rename commit to pipeline in TriggerRequest 2016-06-09 17:57:07 +02:00
Lin Jen-Shin 268f7713a9 Remove Build#can_be_served? and rename Runner#can_serve? to can_pick?
This also moves tests from build_spec.rb to runner_spec.rb
2016-06-09 16:00:24 +08:00
Kamil Trzcinski 9839bbae9c Merge branch 'rename-ci-commit-phase-2' into rename-ci-commit-phase-3 2016-06-07 10:27:27 +02:00
Kamil Trzcinski dbf235f514 Fix tests failures 2016-06-07 10:25:57 +02:00
Kamil Trzcinski 1927a2d30b Rename all ci_commit[s] in application code to pipeline[s] 2016-06-03 16:27:50 +02:00
Kamil Trzcinski 393ec8e74a Rename commit to pipeline in application code 2016-06-03 16:22:53 +02:00
Grzegorz Bizon d8c4556d3c Refactor code reponsible for creating builds
This removes duplications and extracts method that builds build-jobs
without persisting those objects, to a separate method.
2016-06-03 12:50:51 +02:00
Kamil TrzcinskiandGrzegorz Bizon 8e811f2c6c Update CreateCommitBuildsService to pass tests 2016-06-03 11:34:36 +02:00
Kamil TrzcinskiandGrzegorz Bizon c6bce7e63c Save Ci::Commit object to persist all created builds 2016-06-03 11:34:36 +02:00
Grzegorz Bizon 07af37a243 Do not create pipeline objects when no builds 2016-06-03 11:34:36 +02:00
Grzegorz Bizon 0d19abf450 Add minor improvements in create builds service 2016-06-03 11:34:36 +02:00
Grzegorz Bizon af2f56f8f7 Refactor ci commit pipeline to prevent implicit saves 2016-06-03 11:34:36 +02:00
Kamil Trzcinski 021d3810c3 Rename Ci::Commit to Ci::Pipeline and rename some of the ci_commit to pipeline 2016-06-02 16:59:04 +02:00
Kamil Trzcinski 4f1c636831 Create pipeline objects with parameters 2016-05-18 17:01:42 -05:00
Kamil Trzcinski ef60b8e168 Use pipelines.errors when communicating the error 2016-05-18 13:02:10 -05:00
Kamil Trzcinski 003526e2ee Add method new_pipeline 2016-05-14 19:47:16 -05:00
Kamil Trzcinski 0d43b92706 Fix CI tests 2016-05-12 13:08:18 -05:00
Kamil Trzcinski fe2137d871 Improve pipelines design 2016-05-10 02:26:13 +03:00
Kamil Trzcinski ac50f9dddf Fix rest of rspec and spinach tests 2016-04-12 10:23:31 +02:00
Kamil Trzcinski af7214d0f0 Fix specs 2016-04-11 23:32:55 +02:00
Kamil Trzcinski 5d69f5b46d Use Ci::Commit as Pipeline 2016-04-11 23:32:54 +02:00
Jason Roehm a8f1c5ed03 add 'triggers' keyword to gitlab-ci.yml 'only' and 'except' fields to allow control over whether triggers will cause jobs to run 2016-03-15 09:27:33 -04:00
Kamil Trzcinski 0672258915 Cleanup CiCommit and CiBuild
- Remove all view related methods from Ci::Build and CommitStatus
- Remove unused Ci::Commit and Ci::Build methods
- Use polymorphism to render different types of CommitStatus
2016-03-14 13:20:35 +01:00
Grzegorz Bizon 364072b7d0 Return a builds array in builds create service 2016-02-18 10:29:20 +01:00
Grzegorz Bizon 28c4c949a5 Improve CI status badge implementation 2016-02-11 10:29:14 +01:00
Kamil Trzcinski fc1e2f8986 Run builds from projects with enabled CI 2015-12-11 18:03:48 +01:00
Kamil Trzcinski 1e2a4895c8 Finishing touches 2015-12-11 18:02:09 +01:00
Kamil Trzcinski 64bfd9d71a Remove ci_ prefix from all ci related things 2015-12-11 18:02:09 +01:00
Kamil Trzcinski e80e3f5372 Migrate CI::Project to Project 2015-12-11 18:02:09 +01:00
Kamil Trzcinski 2988e1fbf5 Migrate CI::Services and CI::WebHooks to Services and WebHooks 2015-12-10 16:04:08 +01:00
Kamil Trzcinski 271ad4e354 Fix CI badge
The previous code relied on having on ref stored in commit, however the ref was moved to the build.
2015-10-26 12:23:40 +01:00
Kamil Trzcinski 0aa6061d6a Implement when syntax in .gitlab-ci.yml 2015-10-15 23:49:39 +02:00
Kamil Trzcinski 7af4f5215e Show warning if build doesn't have runners with specified tags or runners didn't connect recently
Slightly refactor runner status detection: moving it to Runner class

Signed-off-by: Kamil Trzcinski <ayufan@ayufan.eu>
2015-10-14 17:29:18 +02:00
Kamil Trzcinski 5cd504ed33 Rename builds_without_retry to latest_builds 2015-10-12 16:39:08 +02:00
Kamil Trzcinski 2e9c1608e5 Fix commit skipping 2015-10-12 16:35:58 +02:00
Kamil Trzcinski 914cfbd2f1 Implement Commit Status API 2015-10-12 11:53:49 +02:00
Kamil Trzcinski 97a11136d3 Fix create_trigger_request_service_spec 2015-10-05 17:06:31 +02:00
Kamil Trzcinski f42078f7c1 Fix rest of tests 2015-10-05 14:31:51 +02:00
Kamil Trzcinski 5064c9038c Fix next bunch of tests 2015-10-05 13:51:28 +02:00