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
8fac0f36
Commit
8fac0f36
authored
Sep 30, 2021
by
Fabio Pitino
Committed by
Jan Provaznik
Sep 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor project shared_runners_seconds to use new tracking
parent
958b6550
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
88 additions
and
16 deletions
+88
-16
app/models/project_statistics.rb
app/models/project_statistics.rb
+0
-1
ee/app/models/ee/namespace.rb
ee/app/models/ee/namespace.rb
+6
-0
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+15
-1
ee/app/models/ee/project_statistics.rb
ee/app/models/ee/project_statistics.rb
+0
-9
ee/app/models/namespace_statistics.rb
ee/app/models/namespace_statistics.rb
+0
-1
ee/app/services/ci/minutes/batch_reset_service.rb
ee/app/services/ci/minutes/batch_reset_service.rb
+4
-2
ee/app/views/namespaces/pipelines_quota/_list.haml
ee/app/views/namespaces/pipelines_quota/_list.haml
+1
-1
ee/config/feature_flags/development/ci_use_new_monthly_minutes.yml
.../feature_flags/development/ci_use_new_monthly_minutes.yml
+8
-0
ee/spec/models/ee/namespace_spec.rb
ee/spec/models/ee/namespace_spec.rb
+16
-0
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+38
-1
No files found.
app/models/project_statistics.rb
View file @
8fac0f36
...
@@ -31,7 +31,6 @@ class ProjectStatistics < ApplicationRecord
...
@@ -31,7 +31,6 @@ class ProjectStatistics < ApplicationRecord
scope
:for_project_ids
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
)
}
scope
:for_project_ids
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
)
}
scope
:for_namespaces
,
->
(
namespaces
)
{
where
(
namespace:
namespaces
)
}
scope
:for_namespaces
,
->
(
namespaces
)
{
where
(
namespace:
namespaces
)
}
scope
:with_any_ci_minutes_used
,
->
{
where
.
not
(
shared_runners_seconds:
0
)
}
def
total_repository_size
def
total_repository_size
repository_size
+
lfs_objects_size
repository_size
+
lfs_objects_size
...
...
ee/app/models/ee/namespace.rb
View file @
8fac0f36
...
@@ -252,6 +252,12 @@ module EE
...
@@ -252,6 +252,12 @@ module EE
@ci_minutes_quota
||=
::
Ci
::
Minutes
::
Quota
.
new
(
self
)
@ci_minutes_quota
||=
::
Ci
::
Minutes
::
Quota
.
new
(
self
)
end
end
def
new_monthly_ci_minutes_enabled?
strong_memoize
(
:new_monthly_ci_minutes_enabled
)
do
::
Feature
.
enabled?
(
:ci_use_new_monthly_minutes
,
self
,
default_enabled: :yaml
)
end
end
# The same method name is used also at project level
# The same method name is used also at project level
def
shared_runners_minutes_limit_enabled?
def
shared_runners_minutes_limit_enabled?
any_project_with_shared_runners_enabled?
&&
ci_minutes_quota
.
enabled?
any_project_with_shared_runners_enabled?
&&
ci_minutes_quota
.
enabled?
...
...
ee/app/models/ee/project.rb
View file @
8fac0f36
...
@@ -190,7 +190,7 @@ module EE
...
@@ -190,7 +190,7 @@ module EE
.
order
(
excess_arel
.
desc
)
.
order
(
excess_arel
.
desc
)
end
end
delegate
:shared_runners_
minutes
,
:shared_runners_
seconds
,
:shared_runners_seconds_last_reset
,
delegate
:shared_runners_seconds
,
:shared_runners_seconds_last_reset
,
to: :statistics
,
allow_nil:
true
to: :statistics
,
allow_nil:
true
delegate
:ci_minutes_quota
,
to: :shared_runners_limit_namespace
delegate
:ci_minutes_quota
,
to: :shared_runners_limit_namespace
...
@@ -363,6 +363,14 @@ module EE
...
@@ -363,6 +363,14 @@ module EE
!
disable_overriding_approvers_per_merge_request
!
disable_overriding_approvers_per_merge_request
end
end
def
ci_minutes_used
(
namespace_actor
)
if
namespace_actor
.
new_monthly_ci_minutes_enabled?
ci_minutes_usage
.
amount_used
.
to_i
else
shared_runners_seconds
.
to_i
/
60
end
end
def
shared_runners_available?
def
shared_runners_available?
super
&&
!
ci_minutes_quota
.
minutes_used_up?
super
&&
!
ci_minutes_quota
.
minutes_used_up?
end
end
...
@@ -831,6 +839,12 @@ module EE
...
@@ -831,6 +839,12 @@ module EE
private
private
def
ci_minutes_usage
strong_memoize
(
:ci_minutes_usage
)
do
::
Ci
::
Minutes
::
ProjectMonthlyUsage
.
find_or_create_current
(
project_id:
id
)
end
end
def
github_integration_enabled?
def
github_integration_enabled?
feature_available?
(
:github_project_service_integration
)
feature_available?
(
:github_project_service_integration
)
end
end
...
...
ee/app/models/ee/project_statistics.rb
deleted
100644 → 0
View file @
958b6550
# frozen_string_literal: true
module
EE
module
ProjectStatistics
def
shared_runners_minutes
shared_runners_seconds
.
to_i
/
60
end
end
end
ee/app/models/namespace_statistics.rb
View file @
8fac0f36
...
@@ -8,7 +8,6 @@ class NamespaceStatistics < ApplicationRecord
...
@@ -8,7 +8,6 @@ class NamespaceStatistics < ApplicationRecord
validates
:namespace
,
presence:
true
validates
:namespace
,
presence:
true
scope
:for_namespaces
,
->
(
namespaces
)
{
where
(
namespace:
namespaces
)
}
scope
:for_namespaces
,
->
(
namespaces
)
{
where
(
namespace:
namespaces
)
}
scope
:with_any_ci_minutes_used
,
->
{
where
.
not
(
shared_runners_seconds:
0
)
}
before_save
:update_storage_size
before_save
:update_storage_size
after_save
:update_root_storage_statistics
,
if: :saved_change_to_storage_size?
after_save
:update_root_storage_statistics
,
if: :saved_change_to_storage_size?
...
...
ee/app/services/ci/minutes/batch_reset_service.rb
View file @
8fac0f36
...
@@ -98,17 +98,19 @@ module Ci
...
@@ -98,17 +98,19 @@ module Ci
Arel
::
Nodes
::
NamedFunction
.
new
(
name
,
attrs
)
Arel
::
Nodes
::
NamedFunction
.
new
(
name
,
attrs
)
end
end
# rubocop: disable CodeReuse/ActiveRecord
def
reset_shared_runners_seconds!
(
namespaces
)
def
reset_shared_runners_seconds!
(
namespaces
)
NamespaceStatistics
NamespaceStatistics
.
for_namespaces
(
namespaces
)
.
for_namespaces
(
namespaces
)
.
w
ith_any_ci_minutes_used
.
w
here
.
not
(
shared_runners_seconds:
0
)
.
update_all
(
shared_runners_seconds:
0
,
shared_runners_seconds_last_reset:
Time
.
current
)
.
update_all
(
shared_runners_seconds:
0
,
shared_runners_seconds_last_reset:
Time
.
current
)
::
ProjectStatistics
::
ProjectStatistics
.
for_namespaces
(
namespaces
)
.
for_namespaces
(
namespaces
)
.
w
ith_any_ci_minutes_used
.
w
here
.
not
(
shared_runners_seconds:
0
)
.
update_all
(
shared_runners_seconds:
0
,
shared_runners_seconds_last_reset:
Time
.
current
)
.
update_all
(
shared_runners_seconds:
0
,
shared_runners_seconds_last_reset:
Time
.
current
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
def
reset_ci_minutes_notifications!
(
namespaces
)
def
reset_ci_minutes_notifications!
(
namespaces
)
namespaces
.
without_last_ci_minutes_notification
.
update_all
(
namespaces
.
without_last_ci_minutes_notification
.
update_all
(
...
...
ee/app/views/namespaces/pipelines_quota/_list.haml
View file @
8fac0f36
...
@@ -65,7 +65,7 @@
...
@@ -65,7 +65,7 @@
=
project_icon
(
project
,
alt:
''
,
class:
'avatar project-avatar s20'
)
=
project_icon
(
project
,
alt:
''
,
class:
'avatar project-avatar s20'
)
%strong
=
link_to
project
.
full_name
,
project
%strong
=
link_to
project
.
full_name
,
project
%td
%td
=
project
.
shared_runners_minutes
=
project
.
ci_minutes_used
(
namespace
)
-
if
projects
.
blank?
-
if
projects
.
blank?
%tr
%tr
%td
{
colspan:
2
}
%td
{
colspan:
2
}
...
...
ee/config/feature_flags/development/ci_use_new_monthly_minutes.yml
0 → 100644
View file @
8fac0f36
---
name
:
ci_use_new_monthly_minutes
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71180
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/341730
milestone
:
'
14.4'
type
:
development
group
:
group::pipeline execution
default_enabled
:
false
ee/spec/models/ee/namespace_spec.rb
View file @
8fac0f36
...
@@ -667,6 +667,22 @@ RSpec.describe Namespace do
...
@@ -667,6 +667,22 @@ RSpec.describe Namespace do
end
end
end
end
describe
'#new_monthly_ci_minutes_enabled?'
do
subject
{
namespace
.
new_monthly_ci_minutes_enabled?
}
context
'when feature flag ci_use_new_monthly_minutes is enabled'
do
it
{
is_expected
.
to
be_truthy
}
end
context
'when feature flag ci_use_new_monthly_minutes is disabled'
do
before
do
stub_feature_flags
(
ci_use_new_monthly_minutes:
false
)
end
it
{
is_expected
.
to
be_falsy
}
end
end
describe
'#shared_runners_minutes_limit_enabled?'
do
describe
'#shared_runners_minutes_limit_enabled?'
do
subject
{
namespace
.
shared_runners_minutes_limit_enabled?
}
subject
{
namespace
.
shared_runners_minutes_limit_enabled?
}
...
...
ee/spec/models/project_spec.rb
View file @
8fac0f36
...
@@ -10,7 +10,6 @@ RSpec.describe Project do
...
@@ -10,7 +10,6 @@ RSpec.describe Project do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
describe
'associations'
do
describe
'associations'
do
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds
).
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
(
:shared_runners_seconds_last_reset
).
to
(
:statistics
)
}
...
@@ -1191,6 +1190,44 @@ RSpec.describe Project do
...
@@ -1191,6 +1190,44 @@ RSpec.describe Project do
end
end
end
end
describe
'#ci_minutes_used'
do
subject
{
project
.
ci_minutes_used
(
project
.
namespace
)
}
context
'when CI minutes have not been used'
do
it
{
is_expected
.
to
be_zero
}
context
'when ci_use_new_monthly_minutes feature flag is disabled'
do
before
do
stub_feature_flags
(
ci_use_new_monthly_minutes:
false
)
end
it
{
is_expected
.
to
be_zero
}
end
end
context
'when CI minutes have been used'
do
let
(
:minutes_used
)
{
70.3
}
# this difference in minutes is purely to test that the value
# comes from the expected table
let
(
:legacy_minutes_used
)
{
60.3
}
before
do
create
(
:project_statistics
,
project:
project
,
shared_runners_seconds:
legacy_minutes_used
.
minutes
)
create
(
:ci_project_monthly_usage
,
project:
project
,
amount_used:
minutes_used
)
end
it
{
is_expected
.
to
eq
(
70
)
}
context
'when ci_use_new_monthly_minutes feature flag is disabled'
do
before
do
stub_feature_flags
(
ci_use_new_monthly_minutes:
false
)
end
it
{
is_expected
.
to
eq
(
60
)
}
end
end
end
describe
'#root_namespace'
do
describe
'#root_namespace'
do
let
(
:project
)
{
build
(
:project
,
namespace:
parent
)
}
let
(
:project
)
{
build
(
:project
,
namespace:
parent
)
}
...
...
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