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
08dc2c7c
Commit
08dc2c7c
authored
Jan 19, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename shared_runners_minutes to be shared_runners_seconds when calculating data
parent
71165067
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
68 additions
and
53 deletions
+68
-53
app/helpers/ee/groups_helper.rb
app/helpers/ee/groups_helper.rb
+2
-2
app/models/ee/namespace.rb
app/models/ee/namespace.rb
+1
-1
app/models/ee/project.rb
app/models/ee/project.rb
+1
-1
app/models/namespace_statistics.rb
app/models/namespace_statistics.rb
+4
-0
app/models/project_statistics.rb
app/models/project_statistics.rb
+4
-0
app/services/ee/ci/register_build_service.rb
app/services/ee/ci/register_build_service.rb
+1
-1
app/services/update_build_minutes_service.rb
app/services/update_build_minutes_service.rb
+3
-3
app/views/groups/pipeline_quota/index.html.haml
app/views/groups/pipeline_quota/index.html.haml
+1
-1
app/workers/clear_shared_runners_minutes_worker.rb
app/workers/clear_shared_runners_minutes_worker.rb
+4
-4
db/migrate/20170106172236_create_table_namespace_statistics.rb
...grate/20170106172236_create_table_namespace_statistics.rb
+2
-2
db/migrate/20170106172237_add_shared_runners_seconds_to_project_statistics.rb
...72237_add_shared_runners_seconds_to_project_statistics.rb
+3
-3
db/schema.rb
db/schema.rb
+4
-4
spec/factories/namespaces.rb
spec/factories/namespaces.rb
+3
-3
spec/lib/prependable_spec.rb
spec/lib/prependable_spec.rb
+1
-1
spec/models/ee/namespace_spec.rb
spec/models/ee/namespace_spec.rb
+2
-1
spec/models/ee/project_spec.rb
spec/models/ee/project_spec.rb
+2
-1
spec/models/namespace_statistics_spec.rb
spec/models/namespace_statistics_spec.rb
+6
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+3
-3
spec/services/ee/ci/register_build_service_spec.rb
spec/services/ee/ci/register_build_service_spec.rb
+3
-3
spec/services/update_build_minutes_service_spec.rb
spec/services/update_build_minutes_service_spec.rb
+12
-13
spec/workers/clear_shared_runners_minutes_worker_spec.rb
spec/workers/clear_shared_runners_minutes_worker_spec.rb
+6
-6
No files found.
app/helpers/ee/groups_helper.rb
View file @
08dc2c7c
module
EE
module
GroupsHelper
def
group_shared_runner_limits_quota
(
group
)
used
=
group
.
shared_runners_minutes
used
=
group
.
shared_runners_minutes
.
to_i
if
group
.
shared_runners_minutes_limit_enabled?
limit
=
group
.
actual_shared_runners_minutes_limit
...
...
@@ -19,7 +19,7 @@ module EE
def
group_shared_runner_limits_percent_used
(
group
)
return
0
unless
group
.
shared_runners_minutes_limit_enabled?
100
*
group
.
shared_runners_minutes
/
group
.
actual_shared_runners_minutes_limit
100
*
group
.
shared_runners_minutes
.
to_i
/
group
.
actual_shared_runners_minutes_limit
end
def
group_shared_runner_limits_progress_bar
(
group
)
...
...
app/models/ee/namespace.rb
View file @
08dc2c7c
...
...
@@ -9,7 +9,7 @@ module EE
prepended
do
has_one
:namespace_statistics
,
dependent: :destroy
delegate
:shared_runners_minutes
,
:shared_runners_
minute
s_last_reset
,
delegate
:shared_runners_minutes
,
:shared_runners_
seconds
,
:shared_runners_second
s_last_reset
,
to: :namespace_statistics
,
allow_nil:
true
end
...
...
app/models/ee/project.rb
View file @
08dc2c7c
...
...
@@ -9,7 +9,7 @@ module EE
prepended
do
scope
:with_shared_runners_limit_enabled
,
->
{
with_shared_runners
.
non_public_only
}
delegate
:shared_runners_minutes
,
:shared_runners_
minute
s_last_reset
,
delegate
:shared_runners_minutes
,
:shared_runners_
seconds
,
:shared_runners_second
s_last_reset
,
to: :statistics
,
allow_nil:
true
delegate
:actual_shared_runners_minutes_limit
,
...
...
app/models/namespace_statistics.rb
View file @
08dc2c7c
...
...
@@ -2,4 +2,8 @@ class NamespaceStatistics < ActiveRecord::Base
belongs_to
:namespace
validates
:namespace
,
presence:
true
def
shared_runners_minutes
shared_runners_seconds
.
to_i
/
60.0
end
end
app/models/project_statistics.rb
View file @
08dc2c7c
...
...
@@ -7,6 +7,10 @@ class ProjectStatistics < ActiveRecord::Base
STORAGE_COLUMNS
=
[
:repository_size
,
:lfs_objects_size
,
:build_artifacts_size
]
STATISTICS_COLUMNS
=
[
:commit_count
]
+
STORAGE_COLUMNS
def
shared_runners_minutes
shared_runners_seconds
.
to_i
/
60.0
end
def
total_repository_size
repository_size
+
lfs_objects_size
end
...
...
app/services/ee/ci/register_build_service.rb
View file @
08dc2c7c
...
...
@@ -21,7 +21,7 @@ module EE
where
(
'namespaces.id = projects.namespace_id'
).
joins
(
'LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id'
).
where
(
'COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR '
\
'COALESCE(namespace_statistics.shared_runners_
minutes, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0)
'
,
'COALESCE(namespace_statistics.shared_runners_
seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) * 60
'
,
application_shared_runners_minutes
,
application_shared_runners_minutes
).
select
(
'1'
)
end
...
...
app/services/update_build_minutes_service.rb
View file @
08dc2c7c
...
...
@@ -4,11 +4,11 @@ class UpdateBuildMinutesService < BaseService
return
unless
build
.
complete?
return
unless
build
.
duration
ProjectStatistics
.
update_counters
(
project
.
statistics
,
shared_runners_
minute
s:
build
.
duration
)
ProjectStatistics
.
update_counters
(
project
_
statistics
,
shared_runners_
second
s:
build
.
duration
)
NamespaceStatistics
.
update_counters
(
namespace_statistics
,
shared_runners_
minute
s:
build
.
duration
)
shared_runners_
second
s:
build
.
duration
)
end
private
...
...
app/views/groups/pipeline_quota/index.html.haml
View file @
08dc2c7c
...
...
@@ -6,7 +6,7 @@
.row
.col-sm-6
%strong
-
last_reset
=
@group
.
shared_runners_
minute
s_last_reset
-
last_reset
=
@group
.
shared_runners_
second
s_last_reset
-
if
last_reset
Usage since
=
last_reset
.
strftime
(
'%b %d, %Y'
)
...
...
app/workers/clear_shared_runners_minutes_worker.rb
View file @
08dc2c7c
...
...
@@ -8,12 +8,12 @@ class ClearSharedRunnersMinutesWorker
return
unless
try_obtain_lease
ProjectStatistics
.
update_all
(
shared_runners_
minute
s:
0
,
shared_runners_
minute
s_last_reset:
Time
.
now
)
shared_runners_
second
s:
0
,
shared_runners_
second
s_last_reset:
Time
.
now
)
NamespaceStatistics
.
update_all
(
shared_runners_
minute
s:
0
,
shared_runners_
minute
s_last_reset:
Time
.
now
)
shared_runners_
second
s:
0
,
shared_runners_
second
s_last_reset:
Time
.
now
)
end
private
...
...
db/migrate/20170106172236_create_table_namespace_statistics.rb
View file @
08dc2c7c
...
...
@@ -6,8 +6,8 @@ class CreateTableNamespaceStatistics < ActiveRecord::Migration
def
change
create_table
:namespace_statistics
do
|
t
|
t
.
references
:namespace
,
null:
false
,
index:
{
unique:
true
},
foreign_key:
{
on_delete: :cascade
}
t
.
integer
:shared_runners_
minute
s
,
default:
0
,
null:
false
t
.
timestamp
:shared_runners_
minute
s_last_reset
t
.
integer
:shared_runners_
second
s
,
default:
0
,
null:
false
t
.
timestamp
:shared_runners_
second
s_last_reset
end
end
end
db/migrate/20170106172237_add_shared_runners_
minute
s_to_project_statistics.rb
→
db/migrate/20170106172237_add_shared_runners_
second
s_to_project_statistics.rb
View file @
08dc2c7c
class
AddSharedRunners
Minute
sToProjectStatistics
<
ActiveRecord
::
Migration
class
AddSharedRunners
Second
sToProjectStatistics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
counter_column
=
{
limit:
8
,
null:
false
,
default:
0
}
add_column
:project_statistics
,
:shared_runners_
minute
s
,
:integer
,
counter_column
add_column
:project_statistics
,
:shared_runners_
minute
s_last_reset
,
:timestamp
add_column
:project_statistics
,
:shared_runners_
second
s
,
:integer
,
counter_column
add_column
:project_statistics
,
:shared_runners_
second
s_last_reset
,
:timestamp
end
end
db/schema.rb
View file @
08dc2c7c
...
...
@@ -827,8 +827,8 @@ ActiveRecord::Schema.define(version: 20170106172237) do
create_table
"namespace_statistics"
,
force: :cascade
do
|
t
|
t
.
integer
"namespace_id"
,
null:
false
t
.
integer
"shared_runners_
minute
s"
,
default:
0
,
null:
false
t
.
datetime
"shared_runners_
minute
s_last_reset"
t
.
integer
"shared_runners_
second
s"
,
default:
0
,
null:
false
t
.
datetime
"shared_runners_
second
s_last_reset"
end
add_index
"namespace_statistics"
,
[
"namespace_id"
],
name:
"index_namespace_statistics_on_namespace_id"
,
unique:
true
,
using: :btree
...
...
@@ -1050,8 +1050,8 @@ ActiveRecord::Schema.define(version: 20170106172237) do
t
.
integer
"repository_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"lfs_objects_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"build_artifacts_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"shared_runners_
minute
s"
,
limit:
8
,
default:
0
,
null:
false
t
.
datetime
"shared_runners_
minute
s_last_reset"
t
.
integer
"shared_runners_
second
s"
,
limit:
8
,
default:
0
,
null:
false
t
.
datetime
"shared_runners_
second
s_last_reset"
end
add_index
"project_statistics"
,
[
"namespace_id"
],
name:
"index_project_statistics_on_namespace_id"
,
using: :btree
...
...
spec/factories/namespaces.rb
View file @
08dc2c7c
...
...
@@ -5,7 +5,7 @@ FactoryGirl.define do
owner
trait
:with_build_minutes
do
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
minutes:
400
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
seconds:
400
.
minutes
.
to_i
end
trait
:with_build_minutes_limit
do
...
...
@@ -13,12 +13,12 @@ FactoryGirl.define do
end
trait
:with_not_used_build_minutes_limit
do
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
minutes:
300
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
seconds:
300
.
minutes
.
to_i
shared_runners_minutes_limit
500
end
trait
:with_used_build_minutes_limit
do
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
minutes:
1000
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
seconds:
1000
.
minutes
.
to_i
shared_runners_minutes_limit
500
end
end
...
...
spec/lib/prependable_spec.rb
View file @
08dc2c7c
...
...
@@ -9,7 +9,7 @@ describe Prependable do
end
it
'can execute a method'
do
expect
(
subject
.
class_value
).
to
eq
(
20
0
)
expect
(
subject
.
class_value
).
to
eq
(
20
)
end
end
...
...
spec/models/ee/namespace_spec.rb
View file @
08dc2c7c
...
...
@@ -6,7 +6,8 @@ describe Namespace, models: true do
it
{
is_expected
.
to
have_one
(
:namespace_statistics
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:namespace_statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_last_reset
).
to
(
:namespace_statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds
).
to
(
:namespace_statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds_last_reset
).
to
(
:namespace_statistics
)
}
describe
'#shared_runners_enabled?'
do
subject
{
namespace
.
shared_runners_enabled?
}
...
...
spec/models/ee/project_spec.rb
View file @
08dc2c7c
...
...
@@ -3,7 +3,8 @@ require 'spec_helper'
describe
Project
,
models:
true
do
describe
'associations'
do
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_last_reset
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds_last_reset
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:actual_shared_runners_minutes_limit
).
to
(
:namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_limit_enabled?
).
to
(
:namespace
)
}
...
...
spec/models/namespace_statistics_spec.rb
View file @
08dc2c7c
...
...
@@ -4,4 +4,10 @@ describe NamespaceStatistics, models: true do
it
{
is_expected
.
to
belong_to
(
:namespace
)
}
it
{
is_expected
.
to
validate_presence_of
(
:namespace
)
}
describe
'#shared_runners_minutes'
do
let
(
:namespace_statistics
)
{
build
(
:namespace_statistics
,
shared_runners_seconds:
120
)
}
it
{
expect
(
namespace_statistics
.
shared_runners_minutes
).
to
eq
(
2
)
}
end
end
spec/models/project_spec.rb
View file @
08dc2c7c
...
...
@@ -990,8 +990,8 @@ describe Project, models: true do
context
'when shared runners are disabled for project'
do
let!
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
false
)
}
it
"returns a
project
"
do
is_expected
.
to
eq
([
project
])
it
"returns a
n empty array
"
do
is_expected
.
to
be_empty
end
end
end
...
...
@@ -1155,7 +1155,7 @@ describe Project, models: true do
let!
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
false
)
}
it
"returns a empty list"
do
is_expected
.
to
be_
nil
is_expected
.
to
be_
empty
end
end
end
...
...
spec/services/ee/ci/register_build_service_spec.rb
View file @
08dc2c7c
...
...
@@ -11,7 +11,7 @@ module Ci
context
'for project with shared runners when global minutes limit is set'
do
before
do
project
.
update
(
shared_runners_enabled:
true
)
stub_application_setting
(
shared_runners_minutes:
5
00
)
stub_application_setting
(
shared_runners_minutes:
1
00
)
end
context
'allow to pick builds'
do
...
...
@@ -23,7 +23,7 @@ module Ci
context
'when over the global quota'
do
before
do
project
.
namespace
.
create_namespace_statistics
(
shared_runners_
minutes:
600
)
shared_runners_
seconds:
6001
)
end
let
(
:build
)
{
execute
(
shared_runner
)
}
...
...
@@ -54,7 +54,7 @@ module Ci
context
'when namespace quota is bigger than a global one'
do
before
do
project
.
namespace
.
update
(
shared_runners_minutes_limit:
10
00
)
project
.
namespace
.
update
(
shared_runners_minutes_limit:
10
1
)
end
it
"does return the build"
do
...
...
spec/services/update_build_minutes_service_spec.rb
View file @
08dc2c7c
...
...
@@ -2,9 +2,9 @@ require 'spec_helper'
describe
UpdateBuildMinutesService
,
services:
true
do
context
'#perform'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:namespace
)
{
create
(
:namespace
,
shared_runners_minutes_limit:
100
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:build
)
do
create
(
:ci_build
,
:success
,
runner:
runner
,
pipeline:
pipeline
,
...
...
@@ -16,29 +16,29 @@ describe UpdateBuildMinutesService, services: true do
context
'with shared runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:shared
)
}
it
"creates a
metr
ics and sets duration"
do
it
"creates a
statist
ics and sets duration"
do
subject
expect
(
project
.
statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
project
.
statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
build
.
duration
.
to_i
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
build
.
duration
.
to_i
)
end
context
'when
metr
ics are created'
do
context
'when
statist
ics are created'
do
before
do
project
.
create_statistics
(
shared_runners_minute
s:
100
)
namespace
.
create_namespace_statistics
(
shared_runners_
minute
s:
100
)
project
.
statistics
.
update
(
shared_runners_second
s:
100
)
namespace
.
create_namespace_statistics
(
shared_runners_
second
s:
100
)
end
it
"updates
metr
ics and adds duration"
do
it
"updates
statist
ics and adds duration"
do
subject
expect
(
project
.
statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
project
.
statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
100
+
build
.
duration
.
to_i
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
100
+
build
.
duration
.
to_i
)
end
end
...
...
@@ -47,10 +47,9 @@ describe UpdateBuildMinutesService, services: true do
context
'for specific runner'
do
let
(
:runner
)
{
create
(
:ci_runner
)
}
it
"does not create
metr
ics"
do
it
"does not create
statist
ics"
do
subject
expect
(
project
.
statistics
).
to
be_nil
expect
(
namespace
.
namespace_statistics
).
to
be_nil
end
end
...
...
spec/workers/clear_shared_runners_minutes_worker_spec.rb
View file @
08dc2c7c
...
...
@@ -16,35 +16,35 @@ describe ClearSharedRunnersMinutesWorker do
let
(
:statistics
)
{
project
.
statistics
}
before
do
statistics
.
update
(
shared_runners_
minute
s:
100
)
statistics
.
update
(
shared_runners_
second
s:
100
)
end
it
'clears counters'
do
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s
).
to
be_zero
expect
(
statistics
.
reload
.
shared_runners_
second
s
).
to
be_zero
end
it
'resets timer'
do
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s_last_reset
).
to
be_like_time
(
Time
.
now
)
expect
(
statistics
.
reload
.
shared_runners_
second
s_last_reset
).
to
be_like_time
(
Time
.
now
)
end
end
context
'when namespace statistics are defined'
do
let!
(
:statistics
)
{
create
(
:namespace_statistics
,
shared_runners_
minute
s:
100
)
}
let!
(
:statistics
)
{
create
(
:namespace_statistics
,
shared_runners_
second
s:
100
)
}
it
'clears counters'
do
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s
).
to
be_zero
expect
(
statistics
.
reload
.
shared_runners_
second
s
).
to
be_zero
end
it
'resets timer'
do
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s_last_reset
).
to
be_like_time
(
Time
.
now
)
expect
(
statistics
.
reload
.
shared_runners_
second
s_last_reset
).
to
be_like_time
(
Time
.
now
)
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