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
08ec6881
Commit
08ec6881
authored
Sep 21, 2021
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide decomposed query behind a feature flag
https://gitlab.com/gitlab-org/gitlab/-/issues/341341
parent
4e95bcd8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
146 additions
and
90 deletions
+146
-90
app/finders/ci/pipelines_for_merge_request_finder.rb
app/finders/ci/pipelines_for_merge_request_finder.rb
+40
-4
config/feature_flags/development/decomposed_ci_query_in_pipelines_for_merge_request_finder.yml
...mposed_ci_query_in_pipelines_for_merge_request_finder.yml
+8
-0
spec/finders/ci/pipelines_for_merge_request_finder_spec.rb
spec/finders/ci/pipelines_for_merge_request_finder_spec.rb
+98
-86
No files found.
app/finders/ci/pipelines_for_merge_request_finder.rb
View file @
08ec6881
...
...
@@ -47,12 +47,48 @@ module Ci
private
# rubocop: disable CodeReuse/ActiveRecord
def
pipelines_using_cte
sha_relation
=
merge_request
.
all_commits
.
select
(
:sha
).
distinct
cte
=
Gitlab
::
SQL
::
CTE
.
new
(
:shas
,
sha_relation
)
pipelines_for_merge_requests
=
triggered_by_merge_request
pipelines_for_branch
=
filter_by_sha
(
triggered_for_branch
,
cte
)
Ci
::
Pipeline
.
with
(
cte
.
to_arel
)
# rubocop: disable CodeReuse/ActiveRecord
.
from_union
([
pipelines_for_merge_requests
,
pipelines_for_branch
])
end
# rubocop: enable CodeReuse/ActiveRecord
def
filter_by_sha
(
pipelines
,
cte
)
hex
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
"'hex'"
)
string_sha
=
Arel
::
Nodes
::
NamedFunction
.
new
(
'encode'
,
[
cte
.
table
[
:sha
],
hex
])
join_condition
=
string_sha
.
eq
(
Ci
::
Pipeline
.
arel_table
[
:sha
])
filter_by
(
pipelines
,
cte
,
join_condition
)
end
def
filter_by
(
pipelines
,
cte
,
join_condition
)
shas_table
=
Ci
::
Pipeline
.
arel_table
.
join
(
cte
.
table
,
Arel
::
Nodes
::
InnerJoin
)
.
on
(
join_condition
)
.
join_sources
pipelines
.
joins
(
shas_table
)
# rubocop: disable CodeReuse/ActiveRecord
end
def
all_pipelines_for_merge_request
shas
=
merge_request
.
all_commit_shas
pipelines_for_merge_request
=
triggered_by_merge_request
pipelines_for_branch
=
triggered_for_branch
.
for_sha
(
shas
)
if
Feature
.
enabled?
(
:decomposed_ci_query_in_pipelines_for_merge_request_finder
,
source_project
,
default_enabled: :yaml
)
pipelines_using_cte
else
shas
=
merge_request
.
all_commit_shas
pipelines_for_merge_request
=
triggered_by_merge_request
pipelines_for_branch
=
triggered_for_branch
.
for_sha
(
shas
)
Ci
::
Pipeline
.
from_union
([
pipelines_for_merge_request
,
pipelines_for_branch
])
Ci
::
Pipeline
.
from_union
([
pipelines_for_merge_request
,
pipelines_for_branch
])
end
end
# NOTE: this method returns only parent merge request pipelines.
...
...
config/feature_flags/development/decomposed_ci_query_in_pipelines_for_merge_request_finder.yml
0 → 100644
View file @
08ec6881
---
name
:
decomposed_ci_query_in_pipelines_for_merge_request_finder
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68549
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/341341
milestone
:
'
14.4'
type
:
development
group
:
group::pipeline execution
default_enabled
:
false
spec/finders/ci/pipelines_for_merge_request_finder_spec.rb
View file @
08ec6881
...
...
@@ -134,117 +134,129 @@ RSpec.describe Ci::PipelinesForMergeRequestFinder do
end
end
context
'when pipelines exist for the branch and merge request'
do
let
(
:source_ref
)
{
'feature'
}
let
(
:target_ref
)
{
'master'
}
shared_examples
'returns all pipelines for merge request'
do
context
'when pipelines exist for the branch and merge request'
do
let
(
:source_ref
)
{
'feature'
}
let
(
:target_ref
)
{
'master'
}
let!
(
:branch_pipeline
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
second
)
end
let!
(
:tag_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
source_ref
,
tag:
true
)
end
let!
(
:detached_merge_request_pipeline
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
second
,
merge_request:
merge_request
)
end
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project
,
source_branch:
source_ref
,
target_project:
project
,
target_branch:
target_ref
)
end
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:shas
)
{
project
.
repository
.
commits
(
source_ref
,
limit:
2
).
map
(
&
:id
)
}
before
do
create
(
:merge_request_diff_commit
,
merge_request_diff:
merge_request
.
merge_request_diff
,
sha:
shas
.
second
,
relative_order:
1
)
end
it
'returns merge request pipeline first'
do
expect
(
subject
.
all
).
to
eq
([
detached_merge_request_pipeline
,
branch_pipeline
])
end
context
'when there are a branch pipeline and a merge request pipeline'
do
let!
(
:branch_pipeline_2
)
do
let!
(
:branch_pipeline
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
)
ref:
source_ref
,
sha:
shas
.
second
)
end
let!
(
:detached_merge_request_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
,
merge_request:
merge_request
)
let!
(
:tag_pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
ref:
source_ref
,
tag:
true
)
end
it
'returns merge request pipelines first'
do
expect
(
subject
.
all
)
.
to
eq
([
detached_merge_request_pipeline_2
,
detached_merge_request_pipeline
,
branch_pipeline_2
,
branch_pipeline
])
let!
(
:detached_merge_request_pipeline
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
second
,
merge_request:
merge_request
)
end
end
context
'when there are multiple merge request pipelines from the same branch'
do
let!
(
:branch_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
)
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
project
,
source_branch:
source_ref
,
target_project:
project
,
target_branch:
target_ref
)
end
let!
(
:branch_pipeline_with_sha_not_belonging_to_merge_request
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
)
end
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:shas
)
{
project
.
repository
.
commits
(
source_ref
,
limit:
2
).
map
(
&
:id
)
}
let!
(
:detached_merge_request_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
,
merge_request:
merge_request_2
)
before
do
create
(
:merge_request_diff_commit
,
merge_request_diff:
merge_request
.
merge_request_diff
,
sha:
shas
.
second
,
relative_order:
1
)
end
let
(
:merge_request_2
)
do
create
(
:merge_request
,
source_project:
project
,
source_branch:
source_ref
,
target_project:
project
,
target_branch:
'stable'
)
it
'returns merge request pipeline first'
do
expect
(
subject
.
all
).
to
eq
([
detached_merge_request_pipeline
,
branch_pipeline
])
end
before
do
shas
.
each
.
with_index
do
|
sha
,
index
|
create
(
:merge_request_diff_commit
,
merge_request_diff:
merge_request_2
.
merge_request_diff
,
sha:
sha
,
relative_order:
index
)
context
'when there are a branch pipeline and a merge request pipeline'
do
let!
(
:branch_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
)
end
end
it
'returns only related merge request pipelines'
do
expect
(
subject
.
all
)
.
to
eq
([
detached_merge_request_pipeline
,
branch_pipeline_2
,
branch_pipeline
])
let!
(
:detached_merge_request_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
,
merge_request:
merge_request
)
end
expect
(
described_class
.
new
(
merge_request_2
,
nil
).
all
)
.
to
eq
([
detached_merge_request_pipeline_2
,
branch_pipeline_2
,
branch_pipeline
])
it
'returns merge request pipelines first'
do
expect
(
subject
.
all
)
.
to
eq
([
detached_merge_request_pipeline_2
,
detached_merge_request_pipeline
,
branch_pipeline_2
,
branch_pipeline
])
end
end
end
context
'when detached merge request pipeline is run on head ref of the merge request'
do
let!
(
:detached_merge_request_pipeline
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
merge_request
.
ref_path
,
sha:
shas
.
second
,
merge_request:
merge_request
)
end
context
'when there are multiple merge request pipelines from the same branch'
do
let!
(
:branch_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
)
end
let!
(
:branch_pipeline_with_sha_not_belonging_to_merge_request
)
do
create
(
:ci_pipeline
,
source: :push
,
project:
project
,
ref:
source_ref
)
end
let!
(
:detached_merge_request_pipeline_2
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
source_ref
,
sha:
shas
.
first
,
merge_request:
merge_request_2
)
end
let
(
:merge_request_2
)
do
create
(
:merge_request
,
source_project:
project
,
source_branch:
source_ref
,
target_project:
project
,
target_branch:
'stable'
)
end
before
do
shas
.
each
.
with_index
do
|
sha
,
index
|
create
(
:merge_request_diff_commit
,
merge_request_diff:
merge_request_2
.
merge_request_diff
,
sha:
sha
,
relative_order:
index
)
end
end
it
'sets the head ref of the merge request to the pipeline ref'
do
expect
(
detached_merge_request_pipeline
.
ref
).
to
match
(
%r{refs/merge-requests/
\d
+/head}
)
it
'returns only related merge request pipelines'
do
expect
(
subject
.
all
)
.
to
eq
([
detached_merge_request_pipeline
,
branch_pipeline_2
,
branch_pipeline
])
expect
(
described_class
.
new
(
merge_request_2
,
nil
).
all
)
.
to
eq
([
detached_merge_request_pipeline_2
,
branch_pipeline_2
,
branch_pipeline
])
end
end
it
'includes the detached merge request pipeline even though the ref is custom path'
do
expect
(
merge_request
.
all_pipelines
).
to
include
(
detached_merge_request_pipeline
)
context
'when detached merge request pipeline is run on head ref of the merge request'
do
let!
(
:detached_merge_request_pipeline
)
do
create
(
:ci_pipeline
,
source: :merge_request_event
,
project:
project
,
ref:
merge_request
.
ref_path
,
sha:
shas
.
second
,
merge_request:
merge_request
)
end
it
'sets the head ref of the merge request to the pipeline ref'
do
expect
(
detached_merge_request_pipeline
.
ref
).
to
match
(
%r{refs/merge-requests/
\d
+/head}
)
end
it
'includes the detached merge request pipeline even though the ref is custom path'
do
expect
(
merge_request
.
all_pipelines
).
to
include
(
detached_merge_request_pipeline
)
end
end
end
end
it_behaves_like
'returns all pipelines for merge request'
context
'when `decomposed_ci_query_in_pipelines_for_merge_request_finder` feature flag disabled'
do
before
do
stub_feature_flags
(
decomposed_ci_query_in_pipelines_for_merge_request_finder:
false
)
end
it_behaves_like
'returns all pipelines for merge request'
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