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
b5b9b321
Commit
b5b9b321
authored
Dec 19, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project_metrics
parent
3e40f2fc
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
60 additions
and
7 deletions
+60
-7
app/models/namespace.rb
app/models/namespace.rb
+2
-1
app/models/project.rb
app/models/project.rb
+8
-4
app/models/project_metrics.rb
app/models/project_metrics.rb
+5
-0
app/services/update_build_minutes_service.rb
app/services/update_build_minutes_service.rb
+3
-0
app/workers/clear_shared_runner_minutes_worker.rb
app/workers/clear_shared_runner_minutes_worker.rb
+7
-1
db/migrate/20161202152038_create_table_namespace_metrics.rb
db/migrate/20161202152038_create_table_namespace_metrics.rb
+2
-1
db/migrate/20161202152039_create_table_project_metrics.rb
db/migrate/20161202152039_create_table_project_metrics.rb
+15
-0
db/migrate/20161202152040_add_index_to_namespace_metrics.rb
db/migrate/20161202152040_add_index_to_namespace_metrics.rb
+0
-0
db/migrate/20161202152040_add_index_to_project_metrics.rb
db/migrate/20161202152040_add_index_to_project_metrics.rb
+11
-0
spec/factories/ci/namespace_metrics.rb
spec/factories/ci/namespace_metrics.rb
+7
-0
No files found.
app/models/namespace.rb
View file @
b5b9b321
...
...
@@ -42,7 +42,8 @@ class Namespace < ActiveRecord::Base
scope
:root
,
->
{
where
(
'type IS NULL'
)
}
delegate
:shared_runners_minutes
,
to: :namespace_metrics
,
allow_nil:
true
delegate
:shared_runners_minutes
,
:shared_runners_minutes_last_reset
,
to: :namespace_metrics
,
allow_nil:
true
class
<<
self
def
by_path
(
path
)
...
...
app/models/project.rb
View file @
b5b9b321
...
...
@@ -28,9 +28,11 @@ class Project < ActiveRecord::Base
:merge_requests_enabled?
,
:issues_enabled?
,
to: :project_feature
,
allow_nil:
true
delegate
:shared_runners_minutes
,
:shared_runners_minutes_limit
,
:shared_runners_minutes_used?
,
to: :namespace
,
allow_nil:
true
delegate
:shared_runners_minutes
,
:shared_runners_minutes_last_reset
,
to: :project_metrics
,
allow_nil:
true
delegate
:shared_runners_minutes_limit_enabled?
,
:shared_runners_minutes_limit
,
:shared_runners_minutes_used?
,
to: :namespace
default_value_for
:archived
,
false
default_value_for
:visibility_level
,
gitlab_config_features
.
visibility_level
...
...
@@ -74,6 +76,8 @@ class Project < ActiveRecord::Base
belongs_to
:namespace
belongs_to
:mirror_user
,
foreign_key:
'mirror_user_id'
,
class_name:
'User'
has_one
:project_metrics
,
dependent: :destroy
has_one
:push_rule
,
dependent: :destroy
has_one
:last_event
,
->
{
order
'events.created_at DESC'
},
class_name:
'Event'
has_many
:boards
,
dependent: :destroy
...
...
@@ -1237,7 +1241,7 @@ class Project < ActiveRecord::Base
end
shared_runners_enabled?
&&
!
shared_runners_minutes_used?
&&
!
namespace
.
shared_runners_minutes_used?
&&
Ci
::
Runner
.
shared
.
active
.
any?
(
&
block
)
end
...
...
app/models/project_metrics.rb
0 → 100644
View file @
b5b9b321
class
ProjectMetrics
<
ActiveRecord
::
Base
belongs_to
:project
validates
:project
,
presence:
true
end
app/services/update_build_minutes_service.rb
View file @
b5b9b321
...
...
@@ -6,6 +6,9 @@ class UpdateBuildMinutesService < BaseService
return
unless
build
.
project
return
unless
build
.
project
.
shared_runners_minutes_limit_enabled?
project
.
find_or_create_project_metrics
.
update_all
(
'shared_runners_minutes = shared_runners_minutes + ?'
,
build
.
duration
)
project
.
namespace
.
find_or_create_namespace_metrics
.
update_all
(
'shared_runners_minutes = shared_runners_minutes + ?'
,
build
.
duration
)
end
...
...
app/workers/clear_shared_runner_minutes_worker.rb
View file @
b5b9b321
...
...
@@ -3,6 +3,12 @@ class ClearSharedRunnerMinutesWorker
include
DedicatedSidekiqQueue
def
perform
NamespaceMetrics
.
update_all
(
shared_runners_minutes:
0
)
ProjectMetrics
.
update_all
(
shared_runners_minutes:
0
,
shared_runners_minutes_last_reset:
Time
.
now
)
NamespaceMetrics
.
update_all
(
shared_runners_minutes:
0
,
shared_runners_minutes_last_reset:
Time
.
now
)
end
end
db/migrate/20161202152038_create_table_namespace_metrics.rb
View file @
b5b9b321
...
...
@@ -5,8 +5,9 @@ class CreateTableNamespaceMetrics < ActiveRecord::Migration
def
change
create_table
:namespace_metrics
do
|
t
|
t
.
integer
:namespace_id
,
null:
false
t
.
integer
:namespace_id
,
null:
false
,
unique:
true
t
.
integer
:shared_runners_minutes
,
default:
0
,
null:
false
t
.
timestamp
:shared_runners_minutes_last_reset
end
add_foreign_key
:namespace_metrics
,
:namespaces
,
on_delete: :cascade
...
...
db/migrate/20161202152039_create_table_project_metrics.rb
0 → 100644
View file @
b5b9b321
class
CreateTableProjectMetrics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
create_table
:project_metrics
do
|
t
|
t
.
integer
:project_id
,
null:
false
,
unique:
true
t
.
integer
:shared_runners_minutes
,
default:
0
,
null:
false
t
.
timestamp
:shared_runners_minutes_last_reset
end
add_foreign_key
:project_metrics
,
:projects
,
on_delete: :cascade
end
end
db/migrate/201612021520
39
_add_index_to_namespace_metrics.rb
→
db/migrate/201612021520
40
_add_index_to_namespace_metrics.rb
View file @
b5b9b321
File moved
db/migrate/20161202152040_add_index_to_project_metrics.rb
0 → 100644
View file @
b5b9b321
class
AddIndexToNamespaceMetrics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
change
add_concurrent_index
:project_metrics
,
[
:project_id
],
{
unique:
true
}
end
end
spec/factories/ci/namespace_metrics.rb
0 → 100644
View file @
b5b9b321
FactoryGirl
.
define
do
factory
:namespace_metrics
do
trait
:with_used_limit
do
shared_runners_minutes
1000
end
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