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
ad394fc6
Commit
ad394fc6
authored
Dec 14, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add namespace_metrics and count number of build minutes on namespace basis
parent
7b9dc100
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
98 additions
and
51 deletions
+98
-51
Gemfile.lock
Gemfile.lock
+1
-1
app/models/namespace.rb
app/models/namespace.rb
+21
-0
app/models/namespace_metrics.rb
app/models/namespace_metrics.rb
+5
-0
app/models/project.rb
app/models/project.rb
+3
-16
app/models/project_metrics.rb
app/models/project_metrics.rb
+0
-5
app/services/ci/register_build_service.rb
app/services/ci/register_build_service.rb
+16
-7
app/services/update_build_minutes_service.rb
app/services/update_build_minutes_service.rb
+8
-1
app/views/projects/runners/_form.html.haml
app/views/projects/runners/_form.html.haml
+7
-0
app/workers/clear_shared_runner_minutes_worker.rb
app/workers/clear_shared_runner_minutes_worker.rb
+1
-1
db/migrate/20161129161913_add_shared_runners_minutes_limit_to_projects.rb
...129161913_add_shared_runners_minutes_limit_to_projects.rb
+2
-2
db/migrate/20161129161957_create_table_namespace_metrics.rb
db/migrate/20161129161957_create_table_namespace_metrics.rb
+14
-0
db/migrate/20161129161957_create_table_project_metrics.rb
db/migrate/20161129161957_create_table_project_metrics.rb
+0
-18
db/migrate/20161129162216_add_index_to_namespace_metrics.rb
db/migrate/20161129162216_add_index_to_namespace_metrics.rb
+11
-0
db/migrate/20161214135824_add_limit_build_minutes_to_runners.rb
...rate/20161214135824_add_limit_build_minutes_to_runners.rb
+9
-0
No files found.
Gemfile.lock
View file @
ad394fc6
...
...
@@ -872,8 +872,8 @@ DEPENDENCIES
gollum-rugged_adapter (~> 0.4.2)
gon (~> 6.1.0)
grape (~> 0.15.0)
gssapi
grape-entity (~> 0.6.0)
gssapi
haml_lint (~> 0.18.2)
hamlit (~> 2.6.1)
health_check (~> 2.2.0)
...
...
app/models/namespace.rb
View file @
ad394fc6
...
...
@@ -4,11 +4,14 @@ class Namespace < ActiveRecord::Base
include
CacheMarkdownField
include
Sortable
include
Gitlab
::
ShellAdapter
include
Gitlab
::
CurrentSettings
include
Routable
cache_markdown_field
:description
,
pipeline: :description
has_many
:projects
,
dependent: :destroy
has_one
:namespace_metrics
,
dependent: :destroy
belongs_to
:owner
,
class_name:
"User"
belongs_to
:parent
,
class_name:
"Namespace"
...
...
@@ -39,6 +42,8 @@ class Namespace < ActiveRecord::Base
scope
:root
,
->
{
where
(
'type IS NULL'
)
}
delegate
:shared_runners_minutes
,
to: :namespace_metrics
,
allow_nil:
true
class
<<
self
def
by_path
(
path
)
find_by
(
'lower(path) = :value'
,
value:
path
.
downcase
)
...
...
@@ -203,7 +208,23 @@ class Namespace < ActiveRecord::Base
find_each
(
&
:refresh_members_authorized_projects
)
end
<<<<<<<
HEAD
def
full_path_changed?
path_changed?
||
parent_id_changed?
=======
def
shared_runners_minutes_limit
read_attribute
(
:shared_runners_minutes_limit
)
||
current_application_settings
.
shared_runners_minutes
end
def
shared_runners_minutes_limit_enabled?
shared_runners_minutes_limit
.
nonzero?
end
def
shared_runners_minutes_used?
shared_runners_enabled?
&&
shared_runners_minutes_limit_enabled?
&&
shared_runners_minutes
.
to_i
<
shared_runners_minutes_limit
>>>>>>>
Add
namespace_metrics
and
count
number
of
build
minutes
on
namespace
basis
end
end
app/models/namespace_metrics.rb
0 → 100644
View file @
ad394fc6
class
NamespaceMetrics
<
ActiveRecord
::
Base
belongs_to
:namespace
validates
:namespace
,
presence:
true
end
app/models/project.rb
View file @
ad394fc6
...
...
@@ -28,7 +28,9 @@ class Project < ActiveRecord::Base
:merge_requests_enabled?
,
:issues_enabled?
,
to: :project_feature
,
allow_nil:
true
delegate
:shared_runners_minutes
,
to: :project_metrics
,
allow_nil:
true
delegate
:shared_runners_minutes
,
:shared_runners_minutes_limit
,
:shared_runners_minutes_used?
,
:shared_runners_minutes_limit_enabled?
,
to: :namespace
,
allow_nil:
true
default_value_for
:archived
,
false
default_value_for
:visibility_level
,
gitlab_config_features
.
visibility_level
...
...
@@ -152,7 +154,6 @@ class Project < ActiveRecord::Base
has_one
:import_data
,
dependent: :destroy
,
class_name:
"ProjectImportData"
has_one
:project_feature
,
dependent: :destroy
has_one
:project_metrics
,
dependent: :destroy
has_many
:commit_statuses
,
dependent: :destroy
,
foreign_key: :gl_project_id
has_many
:pipelines
,
dependent: :destroy
,
class_name:
'Ci::Pipeline'
,
foreign_key: :gl_project_id
...
...
@@ -1546,20 +1547,6 @@ class Project < ActiveRecord::Base
end
end
def
shared_runners_minutes_limit
read_attribute
(
:shared_runners_minutes_limit
)
||
current_application_settings
.
shared_runners_minutes
end
def
shared_runners_minutes_limit_enabled?
shared_runners_minutes_limit
.
nonzero?
end
def
shared_runners_minutes_used?
shared_runners_enabled?
&&
shared_runners_minutes_limit_enabled?
&&
shared_runners_minutes
.
to_i
<
shared_runners_minutes_limit
end
private
# Check if a reference is being done cross-project
...
...
app/models/project_metrics.rb
deleted
100644 → 0
View file @
7b9dc100
class
ProjectMetrics
<
ActiveRecord
::
Base
belongs_to
:project
validates
:project
,
presence:
true
end
app/services/ci/register_build_service.rb
View file @
ad394fc6
...
...
@@ -9,7 +9,11 @@ module Ci
builds
=
if
current_runner
.
shared?
builds_for_shared_runner_with_build_minutes
if
current_runner
.
limit_build_minutes?
builds_for_shared_runners_with_build_minutes_limit
else
builds_for_shared_runners
end
else
builds_for_specific_runner
end
...
...
@@ -40,18 +44,23 @@ 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 with allowed number of shared runner minutes
joins
(
'LEFT JOIN project_metrics ON ci_builds.gl_project_id = project_metrics.project_id'
).
where
(
'COALESCE(projects.shared_runner_minutes_limit, ?, 0) > 0 AND '
\
'COALESCE(project_metrics.shared_runner_minutes, 0) < COALESCE(projects.shared_runner_minutes_limit, ?, 0)'
,
current_application_settings
.
shared_runners_minutes
)
# 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
)
end
def
builds_for_specific_runner
new_builds
.
where
(
project:
current_runner
.
projects
.
with_builds_enabled
).
order
(
'created_at ASC'
)
end
...
...
app/services/update_build_minutes_service.rb
View file @
ad394fc6
...
...
@@ -2,9 +2,16 @@ 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
.
find_or_create_project_metrics
.
project
=
build
.
project
return
unless
project
namespace
=
project
.
namespace
return
unless
namespace
namespace
.
find_or_create_project_metrics
.
update_all
(
'shared_runners_minutes = shared_runners_minutes + ?'
,
build
.
duration
)
end
end
app/views/projects/runners/_form.html.haml
View file @
ad394fc6
...
...
@@ -18,6 +18,13 @@
.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
...
...
app/workers/clear_shared_runner_minutes_worker.rb
View file @
ad394fc6
...
...
@@ -3,6 +3,6 @@ class ClearSharedRunnerMinutesWorker
include
DedicatedSidekiqQueue
def
perform
Project
Metrics
.
update_all
(
shared_runner_minutes:
0
)
Namespace
Metrics
.
update_all
(
shared_runner_minutes:
0
)
end
end
db/migrate/20161129161913_add_shared_runners_minutes_limit_to_projects.rb
View file @
ad394fc6
class
AddSharedRunnersMinutesLimitTo
Projects
<
ActiveRecord
::
Migration
class
AddSharedRunnersMinutesLimitTo
Namespace
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:
project
s
,
:shared_runners_minutes_limit
,
:integer
add_column
:
namespace
s
,
:shared_runners_minutes_limit
,
:integer
end
end
db/migrate/20161129161957_create_table_namespace_metrics.rb
0 → 100644
View file @
ad394fc6
class
CreateTableNamespaceMetrics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
create_table
:namespace_metrics
do
|
t
|
t
.
integer
:namespace_id
,
null:
false
t
.
integer
:shared_runners_minutes
,
default:
0
,
null:
false
end
add_foreign_key
:namespace_metrics
,
:projects
,
column: :namespace_id
,
on_delete: :cascade
end
end
db/migrate/20161129161957_create_table_project_metrics.rb
deleted
100644 → 0
View file @
7b9dc100
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
CreateTableProjectMetrics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
def
change
create_table
:project_metrics
do
|
t
|
t
.
integer
:project_id
,
null:
false
t
.
integer
:shared_runners_minutes
,
default:
0
,
null:
false
end
add_foreign_key
:project_metrics
,
:projects
,
column: :project_id
,
on_delete: :cascade
end
end
db/migrate/20161129162216_add_index_to_
project
_metrics.rb
→
db/migrate/20161129162216_add_index_to_
namespace
_metrics.rb
View file @
ad394fc6
class
AddIndexTo
Project
Metrics
<
ActiveRecord
::
Migration
class
AddIndexTo
Namespace
Metrics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
...
...
@@ -6,6 +6,6 @@ class AddIndexToProjectMetrics < ActiveRecord::Migration
disable_ddl_transaction!
def
change
add_concurrent_index
:
project_metrics
,
[
:project
_id
],
{
unique:
true
}
add_concurrent_index
:
namespace_metrics
,
[
:namespace
_id
],
{
unique:
true
}
end
end
db/migrate/20161214135824_add_limit_build_minutes_to_runners.rb
0 → 100644
View file @
ad394fc6
class
AddLimitBuildMinutesToRunners
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:runners
,
:limit_build_minutes
,
:boolean
end
end
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