Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bf5198ac
Commit
bf5198ac
authored
Dec 15, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not account public projects
parent
d2078be3
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
32 additions
and
36 deletions
+32
-36
app/services/ci/register_build_service.rb
app/services/ci/register_build_service.rb
+18
-14
app/services/update_build_minutes_service.rb
app/services/update_build_minutes_service.rb
+2
-4
app/views/projects/runners/_form.html.haml
app/views/projects/runners/_form.html.haml
+0
-7
db/migrate/20161202152036_add_shared_runners_minutes_to_application_settings.rb
...036_add_shared_runners_minutes_to_application_settings.rb
+0
-0
db/migrate/20161202152037_add_shared_runners_minutes_limit_to_namespace.rb
...02152037_add_shared_runners_minutes_limit_to_namespace.rb
+0
-0
db/migrate/20161202152038_create_table_namespace_metrics.rb
db/migrate/20161202152038_create_table_namespace_metrics.rb
+1
-1
db/migrate/20161202152039_add_index_to_namespace_metrics.rb
db/migrate/20161202152039_add_index_to_namespace_metrics.rb
+0
-0
db/migrate/20161214135824_add_limit_build_minutes_to_runners.rb
...rate/20161214135824_add_limit_build_minutes_to_runners.rb
+0
-9
db/schema.rb
db/schema.rb
+11
-1
No files found.
app/services/ci/register_build_service.rb
View file @
bf5198ac
...
...
@@ -9,11 +9,7 @@ module Ci
builds
=
if
current_runner
.
shared?
if
current_runner
.
limit_build_minutes?
builds_for_shared_runners_with_build_minutes_limit
else
builds_for_shared_runners
end
builds_for_shared_runner
else
builds_for_specific_runner
end
...
...
@@ -44,21 +40,29 @@ module Ci
joins
(
'LEFT JOIN project_features ON ci_builds.gl_project_id = project_features.project_id'
).
where
(
'project_features.builds_access_level IS NULL or project_features.builds_access_level > 0'
)
.
# select projects which have allowed number of shared runner minutes or are public
where
(
"projects.visibility_level_field=? OR (
#{
builds_check_limit
.
to_sql
}
)"
,
Gitlab
::
VisibilityLevel
.
PUBLIC
)
# Implement fair scheduling
# this returns builds that are ordered by number of running builds
# we prefer projects that don't use shared runners at all
joins
(
"LEFT JOIN (
#{
running_builds_for_shared_runners
.
to_sql
}
) AS project_builds ON ci_builds.gl_project_id=project_builds.gl_project_id"
).
order
(
'COALESCE(project_builds.running_builds, 0) ASC'
,
'ci_builds.id ASC'
)
end
def
builds_for_shared_runners_with_build_minutes_limit
builds_for_shared_runner
.
# select projects with allowed number of shared runner minutes
joins
(
'LEFT JOIN namespaces ON ci_builds.gl_project_id = namespaces.project_id'
).
joins
(
'LEFT JOIN namespace_metrics ON namespaces.id = namespace_metrics.namespace_id'
).
where
(
'COALESCE(namespaces.shared_runner_minutes_limit, ?, 0) > 0 AND '
\
'COALESCE(namespace_metrics.shared_runner_minutes, 0) < COALESCE(namespaces.shared_runner_minutes_limit, ?, 0)'
,
current_application_settings
.
shared_runners_minutes
,
current_application_settings
.
shared_runners_minutes
)
def
builds_check_limit
Namespace
.
where
(
"namespaces.project_id = ci_builds.gl_project_id"
).
includes
(
:namespace_metrics
).
where
(
'COALESCE(namespaces.shared_runner_minutes_limit, ?, 0) == 0 OR '
\
'COALESCE(namespace_metrics.shared_runner_minutes, 0) < COALESCE(namespaces.shared_runner_minutes_limit, ?, 0)'
,
application_shared_runners_minutes
,
application_shared_runners_minutes
).
select
(
'1'
)
end
def
application_shared_runners_minutes
current_application_settings
.
shared_runners_minutes
end
def
builds_for_specific_runner
...
...
app/services/update_build_minutes_service.rb
View file @
bf5198ac
...
...
@@ -2,11 +2,9 @@ class UpdateBuildMinutesService < BaseService
def
execute
(
build
)
return
unless
build
.
runner
return
unless
build
.
runner
.
shared?
return
unless
build
.
runner
.
limit_build_minutes?
return
unless
build
.
duration
project
=
build
.
project
return
unless
project
return
unless
build
.
project
return
if
build
.
project
.
public?
namespace
=
project
.
namespace
return
unless
namespace
...
...
app/views/projects/runners/_form.html.haml
View file @
bf5198ac
...
...
@@ -18,13 +18,6 @@
.checkbox
=
f
.
check_box
:locked
%span
.light
When a runner is locked, it cannot be assigned to other projects
-
if
runner
.
shared?
.form-group
=
label
:limit_build_minutes
,
'Limit build minutes'
,
class:
'control-label'
.col-sm-10
.checkbox
=
f
.
check_box
:limit_build_minutes
%span
.light
When limiting is enabled, only namespaces with build minutes allowance will be picked.
.form-group
=
label_tag
:token
,
class:
'control-label'
do
Token
...
...
db/migrate/20161
129161815
_add_shared_runners_minutes_to_application_settings.rb
→
db/migrate/20161
202152036
_add_shared_runners_minutes_to_application_settings.rb
View file @
bf5198ac
File moved
db/migrate/20161
129161913
_add_shared_runners_minutes_limit_to_namespace.rb
→
db/migrate/20161
202152037
_add_shared_runners_minutes_limit_to_namespace.rb
View file @
bf5198ac
File moved
db/migrate/20161
129161957
_create_table_namespace_metrics.rb
→
db/migrate/20161
202152038
_create_table_namespace_metrics.rb
View file @
bf5198ac
...
...
@@ -9,6 +9,6 @@ class CreateTableNamespaceMetrics < ActiveRecord::Migration
t
.
integer
:shared_runners_minutes
,
default:
0
,
null:
false
end
add_foreign_key
:namespace_metrics
,
:
projects
,
column: :namespace_id
,
on_delete: :cascade
add_foreign_key
:namespace_metrics
,
:
namespaces
,
on_delete: :cascade
end
end
db/migrate/20161
129162216
_add_index_to_namespace_metrics.rb
→
db/migrate/20161
202152039
_add_index_to_namespace_metrics.rb
View file @
bf5198ac
File moved
db/migrate/20161214135824_add_limit_build_minutes_to_runners.rb
deleted
100644 → 0
View file @
d2078be3
class
AddLimitBuildMinutesToRunners
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:ci_runners
,
:limit_build_minutes
,
:boolean
end
end
db/schema.rb
View file @
bf5198ac
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2016120215203
5
)
do
ActiveRecord
::
Schema
.
define
(
version:
2016120215203
9
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -116,6 +116,7 @@ ActiveRecord::Schema.define(version: 20161202152035) do
t
.
string
"sidekiq_throttling_queues"
t
.
decimal
"sidekiq_throttling_factor"
t
.
boolean
"html_emails_enabled"
,
default:
true
t
.
integer
"shared_runners_minutes"
,
default:
0
,
null:
false
end
create_table
"approvals"
,
force: :cascade
do
|
t
|
...
...
@@ -818,6 +819,13 @@ ActiveRecord::Schema.define(version: 20161202152035) do
add_index
"milestones"
,
[
"title"
],
name:
"index_milestones_on_title"
,
using: :btree
add_index
"milestones"
,
[
"title"
],
name:
"index_milestones_on_title_trigram"
,
using: :gin
,
opclasses:
{
"title"
=>
"gin_trgm_ops"
}
create_table
"namespace_metrics"
,
force: :cascade
do
|
t
|
t
.
integer
"namespace_id"
,
null:
false
t
.
integer
"shared_runners_minutes"
,
default:
0
,
null:
false
end
add_index
"namespace_metrics"
,
[
"namespace_id"
],
name:
"index_namespace_metrics_on_namespace_id"
,
unique:
true
,
using: :btree
create_table
"namespaces"
,
force: :cascade
do
|
t
|
t
.
string
"name"
,
null:
false
t
.
string
"path"
,
null:
false
...
...
@@ -841,6 +849,7 @@ ActiveRecord::Schema.define(version: 20161202152035) do
t
.
boolean
"lfs_enabled"
t
.
integer
"repository_size_limit"
t
.
integer
"parent_id"
t
.
integer
"shared_runners_minutes_limit"
end
add_index
"namespaces"
,
[
"created_at"
],
name:
"index_namespaces_on_created_at"
,
using: :btree
...
...
@@ -1478,6 +1487,7 @@ ActiveRecord::Schema.define(version: 20161202152035) do
add_foreign_key
"merge_request_metrics"
,
"merge_requests"
,
on_delete: :cascade
add_foreign_key
"merge_requests_closing_issues"
,
"issues"
,
on_delete: :cascade
add_foreign_key
"merge_requests_closing_issues"
,
"merge_requests"
,
on_delete: :cascade
add_foreign_key
"namespace_metrics"
,
"namespaces"
,
on_delete: :cascade
add_foreign_key
"path_locks"
,
"projects"
add_foreign_key
"path_locks"
,
"users"
add_foreign_key
"personal_access_tokens"
,
"users"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment