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
d887ba7a
Commit
d887ba7a
authored
Jan 18, 2022
by
Furkan Ayhan
Committed by
Kamil Trzciński
Jan 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve cross-db queries for Runner scopes
The changes are behind the FF ci_find_runners_by_ci_mirrors
parent
f1083234
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
5 deletions
+51
-5
app/models/ci/runner.rb
app/models/ci/runner.rb
+7
-0
ee/lib/analytics/devops_adoption/snapshot_calculator.rb
ee/lib/analytics/devops_adoption/snapshot_calculator.rb
+6
-2
ee/spec/lib/analytics/devops_adoption/snapshot_calculator_spec.rb
...lib/analytics/devops_adoption/snapshot_calculator_spec.rb
+11
-1
lib/api/ci/runners.rb
lib/api/ci/runners.rb
+6
-1
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+10
-0
spec/requests/api/ci/runners_spec.rb
spec/requests/api/ci/runners_spec.rb
+11
-1
No files found.
app/models/ci/runner.rb
View file @
d887ba7a
...
...
@@ -112,6 +112,13 @@ module Ci
from
(
"(
#{
union_sql
}
)
#{
table_name
}
"
)
}
scope
:belonging_to_group_and_ancestors
,
->
(
group_id
)
{
group_self_and_ancestors_ids
=
::
Group
.
find_by
(
id:
group_id
)
&
.
self_and_ancestor_ids
joins
(
:runner_namespaces
)
.
where
(
ci_runner_namespaces:
{
namespace_id:
group_self_and_ancestors_ids
})
}
# deprecated
# split this into: belonging_to_group & belonging_to_group_and_ancestors
scope
:legacy_belonging_to_group
,
->
(
group_id
,
include_ancestors:
false
)
{
...
...
ee/lib/analytics/devops_adoption/snapshot_calculator.rb
View file @
d887ba7a
...
...
@@ -61,8 +61,12 @@ module Analytics
# rubocop: enable CodeReuse/ActiveRecord
def
runner_configured
::
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/337541'
)
do
Ci
::
Runner
.
active
.
legacy_belonging_to_group_or_project
(
snapshot_groups
,
snapshot_project_ids
).
exists?
if
::
Feature
.
enabled?
(
:ci_find_runners_by_ci_mirrors
,
enabled_namespace
.
namespace
,
default_enabled: :yaml
)
Ci
::
Runner
.
active
.
belonging_to_group_or_project_descendants
(
enabled_namespace
.
namespace
.
id
).
exists?
else
::
Gitlab
::
Database
.
allow_cross_joins_across_databases
(
url:
'https://gitlab.com/gitlab-org/gitlab/-/issues/337541'
)
do
Ci
::
Runner
.
active
.
legacy_belonging_to_group_or_project
(
snapshot_groups
,
snapshot_project_ids
).
exists?
end
end
end
...
...
ee/spec/lib/analytics/devops_adoption/snapshot_calculator_spec.rb
View file @
d887ba7a
...
...
@@ -61,7 +61,7 @@ RSpec.describe Analytics::DevopsAdoption::SnapshotCalculator do
it
{
is_expected
.
to
eq
false
}
end
describe
'runner_configured'
do
shared_examples
'runner_configured'
do
subject
{
data
[
:runner_configured
]
}
let!
(
:inactive_runner
)
{
create
(
:ci_runner
,
:project
,
active:
false
)
}
...
...
@@ -77,6 +77,16 @@ RSpec.describe Analytics::DevopsAdoption::SnapshotCalculator do
it
{
is_expected
.
to
eq
false
}
end
it_behaves_like
'runner_configured'
context
'when the FF ci_find_runners_by_ci_mirrors is disabled'
do
before
do
stub_feature_flags
(
ci_find_runners_by_ci_mirrors:
false
)
end
it_behaves_like
'runner_configured'
end
describe
'pipeline_succeeded'
do
subject
{
data
[
:pipeline_succeeded
]
}
...
...
lib/api/ci/runners.rb
View file @
d887ba7a
...
...
@@ -229,7 +229,12 @@ module API
use
:pagination
end
get
':id/runners'
do
runners
=
::
Ci
::
Runner
.
legacy_belonging_to_group
(
user_group
.
id
,
include_ancestors:
true
)
runners
=
if
::
Feature
.
enabled?
(
:ci_find_runners_by_ci_mirrors
,
user_group
,
default_enabled: :yaml
)
::
Ci
::
Runner
.
belonging_to_group_and_ancestors
(
user_group
.
id
)
else
::
Ci
::
Runner
.
legacy_belonging_to_group
(
user_group
.
id
,
include_ancestors:
true
)
end
runners
=
apply_filter
(
runners
,
params
)
present
paginate
(
runners
),
with:
Entities
::
Ci
::
Runner
...
...
spec/models/ci/runner_spec.rb
View file @
d887ba7a
...
...
@@ -1438,6 +1438,16 @@ RSpec.describe Ci::Runner do
end
end
describe
'.belonging_to_group_and_ancestors'
do
let_it_be
(
:parent_group
)
{
create
(
:group
)
}
let_it_be
(
:parent_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
parent_group
])
}
let_it_be
(
:group
)
{
create
(
:group
,
parent:
parent_group
)
}
it
'returns the group runner from the parent group'
do
expect
(
described_class
.
belonging_to_group_and_ancestors
(
group
.
id
)).
to
contain_exactly
(
parent_runner
)
end
end
describe
'.belonging_to_group_or_project_descendants'
do
it
'returns the specific group runners'
do
group1
=
create
(
:group
)
...
...
spec/requests/api/ci/runners_spec.rb
View file @
d887ba7a
...
...
@@ -980,7 +980,7 @@ RSpec.describe API::Ci::Runners do
end
end
describe
'GET /groups/:id/runners'
do
shared_context
'GET /groups/:id/runners'
do
context
'authorized user with maintainer privileges'
do
it
'returns all runners'
do
get
api
(
"/groups/
#{
group
.
id
}
/runners"
,
user
)
...
...
@@ -1048,6 +1048,16 @@ RSpec.describe API::Ci::Runners do
end
end
it_behaves_like
'GET /groups/:id/runners'
context
'when the FF ci_find_runners_by_ci_mirrors is disabled'
do
before
do
stub_feature_flags
(
ci_find_runners_by_ci_mirrors:
false
)
end
it_behaves_like
'GET /groups/:id/runners'
end
describe
'POST /projects/:id/runners'
do
context
'authorized user'
do
let_it_be
(
:project_runner2
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project2
])
}
...
...
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