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
4f2e7ab3
Commit
4f2e7ab3
authored
Aug 20, 2021
by
Marius Bobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix namespace checks for live quota consumption
Changelog: fixed EE: true
parent
457ef961
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
160 additions
and
87 deletions
+160
-87
app/models/namespace.rb
app/models/namespace.rb
+0
-5
ee/app/services/ci/minutes/track_live_consumption_service.rb
ee/app/services/ci/minutes/track_live_consumption_service.rb
+0
-2
ee/lib/gitlab/ci/minutes/cost_factor.rb
ee/lib/gitlab/ci/minutes/cost_factor.rb
+1
-0
ee/spec/lib/ee/gitlab/ci/matching/runner_matcher_spec.rb
ee/spec/lib/ee/gitlab/ci/matching/runner_matcher_spec.rb
+1
-1
ee/spec/lib/gitlab/ci/minutes/build_consumption_spec.rb
ee/spec/lib/gitlab/ci/minutes/build_consumption_spec.rb
+1
-0
ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb
ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb
+122
-69
ee/spec/models/ci/build_spec.rb
ee/spec/models/ci/build_spec.rb
+4
-0
ee/spec/models/ee/ci/runner_spec.rb
ee/spec/models/ee/ci/runner_spec.rb
+26
-6
ee/spec/services/ci/minutes/track_live_consumption_service_spec.rb
...ervices/ci/minutes/track_live_consumption_service_spec.rb
+3
-2
ee/spec/services/ci/pipeline_creation/drop_not_runnable_builds_service_spec.rb
...ipeline_creation/drop_not_runnable_builds_service_spec.rb
+2
-2
No files found.
app/models/namespace.rb
View file @
4f2e7ab3
...
...
@@ -274,11 +274,6 @@ class Namespace < ApplicationRecord
projects
.
with_shared_runners
.
any?
end
# Internal Gitlab owned namespaces only (example: gitlab-org)
def
unlimited_minutes?
shared_runners_minutes_limit
==
0
end
def
user_ids_for_project_authorizations
[
owner_id
]
end
...
...
ee/app/services/ci/minutes/track_live_consumption_service.rb
View file @
4f2e7ab3
...
...
@@ -77,8 +77,6 @@ module Ci
ServiceResponse
.
error
(
message:
'Feature not enabled'
)
elsif
!
build
.
running?
ServiceResponse
.
error
(
message:
'Build is not running'
)
elsif
root_namespace
.
unlimited_minutes?
ServiceResponse
.
error
(
message:
'Namespace has unlimited minutes'
)
elsif
!
build
.
cost_factor_enabled?
ServiceResponse
.
error
(
message:
'Cost factor not enabled for build'
)
else
...
...
ee/lib/gitlab/ci/minutes/cost_factor.rb
View file @
4f2e7ab3
...
...
@@ -22,6 +22,7 @@ module Gitlab
def
for_project
(
project
)
return
0.0
unless
@runner_matcher
.
instance_type?
return
0.0
unless
project
.
ci_minutes_quota
.
enabled?
cost_factor
=
for_visibility
(
project
.
visibility_level
)
...
...
ee/spec/lib/ee/gitlab/ci/matching/runner_matcher_spec.rb
View file @
4f2e7ab3
...
...
@@ -65,7 +65,7 @@ RSpec.describe Gitlab::Ci::Matching::RunnerMatcher do
before
do
allow
(
project
)
.
to
receive
(
:ci_minutes_quota
)
.
and_return
(
double
(
minutes_used_up?:
quota_minutes_used_up
))
.
and_return
(
double
(
minutes_used_up?:
quota_minutes_used_up
,
enabled?:
true
))
end
it
{
is_expected
.
to
eq
(
result
)
}
...
...
ee/spec/lib/gitlab/ci/minutes/build_consumption_spec.rb
View file @
4f2e7ab3
...
...
@@ -33,6 +33,7 @@ RSpec.describe Gitlab::Ci::Minutes::BuildConsumption do
project
.
update!
(
visibility_level:
visibility_level
)
allow
(
build
).
to
receive
(
:duration
).
and_return
(
duration
)
allow
(
::
Gitlab
::
CurrentSettings
).
to
receive
(
:shared_runners_minutes
)
{
400
}
end
it
'returns the expected consumption'
do
...
...
ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb
View file @
4f2e7ab3
This diff is collapsed.
Click to expand it.
ee/spec/models/ci/build_spec.rb
View file @
4f2e7ab3
...
...
@@ -51,6 +51,10 @@ RSpec.describe Ci::Build do
describe
'#cost_factor_enabled?'
do
subject
{
job
.
cost_factor_enabled?
}
before
do
allow
(
::
Gitlab
::
CurrentSettings
).
to
receive
(
:shared_runners_minutes
)
{
400
}
end
context
'for shared runner'
do
before
do
job
.
runner
=
create
(
:ci_runner
,
:instance
)
...
...
ee/spec/models/ee/ci/runner_spec.rb
View file @
4f2e7ab3
...
...
@@ -3,6 +3,12 @@
require
'spec_helper'
RSpec
.
describe
EE
::
Ci
::
Runner
do
let
(
:shared_runners_minutes
)
{
400
}
before
do
allow
(
::
Gitlab
::
CurrentSettings
).
to
receive
(
:shared_runners_minutes
)
{
shared_runners_minutes
}
end
describe
'#cost_factor_for_project'
do
subject
{
runner
.
cost_factor_for_project
(
project
)
}
...
...
@@ -42,6 +48,12 @@ RSpec.describe EE::Ci::Runner do
let
(
:project
)
{
create
(
:project
,
visibility_level:
::
Gitlab
::
VisibilityLevel
::
PRIVATE
)
}
it
{
is_expected
.
to
eq
(
1.1
)
}
context
'with unlimited minutes'
do
let
(
:shared_runners_minutes
)
{
400
}
it
{
is_expected
.
to
eq
(
1.1
)
}
end
end
context
'with public visibility level'
do
...
...
@@ -85,18 +97,26 @@ RSpec.describe EE::Ci::Runner do
end
describe
'#cost_factor_enabled?'
do
let_it_be
(
:project
)
do
let_it_be
_with_reload
(
:project
)
do
namespace
=
create
(
:group
,
created_at:
Date
.
new
(
2021
,
7
,
16
))
create
(
:project
,
namespace:
namespace
)
end
context
'when the project has any cost factor'
do
it
'returns true'
do
runner
=
create
(
:ci_runner
,
:instance
,
private_projects_minutes_cost_factor:
1
,
public_projects_minutes_cost_factor:
0
)
let
(
:runner
)
do
create
(
:ci_runner
,
:instance
,
private_projects_minutes_cost_factor:
1
,
public_projects_minutes_cost_factor:
0
)
end
subject
{
runner
.
cost_factor_enabled?
(
project
)
}
it
{
is_expected
.
to
be_truthy
}
context
'with unlimited minutes'
do
let
(
:shared_runners_minutes
)
{
0
}
expect
(
runner
.
cost_factor_enabled?
(
project
)).
to
be_truthy
it
{
is_expected
.
to
be_falsy
}
end
end
...
...
ee/spec/services/ci/minutes/track_live_consumption_service_spec.rb
View file @
4f2e7ab3
...
...
@@ -82,10 +82,11 @@ RSpec.describe Ci::Minutes::TrackLiveConsumptionService do
context
'when namespace has unlimited minutes'
do
before
do
namespace
.
update!
(
shared_runners_minutes_limit:
0
)
quota
=
double
(
'quota'
,
enabled?:
false
)
allow
(
project
).
to
receive
(
:ci_minutes_quota
).
and_return
(
quota
)
end
it_behaves_like
'returns early'
,
'
Namespace has unlimited minutes
'
it_behaves_like
'returns early'
,
'
Cost factor not enabled for build
'
end
context
'when build has not been tracked recently'
do
...
...
ee/spec/services/ci/pipeline_creation/drop_not_runnable_builds_service_spec.rb
View file @
4f2e7ab3
...
...
@@ -40,7 +40,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
shared_examples
'limit exceeded'
do
before
do
allow
(
pipeline
.
project
).
to
receive
(
:ci_minutes_quota
)
.
and_return
(
double
(
'quota'
,
minutes_used_up?:
true
))
.
and_return
(
double
(
'quota'
,
minutes_used_up?:
true
,
enabled?:
true
))
end
it
'drops the job with ci_quota_exceeded reason'
do
...
...
@@ -96,7 +96,7 @@ RSpec.describe Ci::PipelineCreation::DropNotRunnableBuildsService do
context
'when the CI quota is exceeded'
do
before
do
allow
(
pipeline
.
project
).
to
receive
(
:ci_minutes_quota
)
.
and_return
(
double
(
'quota'
,
minutes_used_up?:
true
))
.
and_return
(
double
(
'quota'
,
minutes_used_up?:
true
,
enabled?:
true
))
end
it_behaves_like
'jobs allowed to run'
...
...
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