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
2fb3c041
Commit
2fb3c041
authored
Jun 09, 2021
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename shared runner builds table to running builds
parent
7204a481
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
45 deletions
+58
-45
app/models/ci/build.rb
app/models/ci/build.rb
+4
-4
app/models/ci/running_build.rb
app/models/ci/running_build.rb
+8
-3
app/services/ci/update_build_queue_service.rb
app/services/ci/update_build_queue_service.rb
+5
-4
db/migrate/20210601123341_add_running_builds_table.rb
db/migrate/20210601123341_add_running_builds_table.rb
+4
-3
db/structure.sql
db/structure.sql
+19
-18
spec/models/ci/running_build_spec.rb
spec/models/ci/running_build_spec.rb
+11
-8
spec/services/ci/retry_build_service_spec.rb
spec/services/ci/retry_build_service_spec.rb
+1
-1
spec/services/ci/update_build_queue_service_spec.rb
spec/services/ci/update_build_queue_service_spec.rb
+6
-4
No files found.
app/models/ci/build.rb
View file @
2fb3c041
...
...
@@ -39,7 +39,7 @@ module Ci
has_one
:deployment
,
as: :deployable
,
class_name:
'Deployment'
has_one
:pending_state
,
class_name:
'Ci::BuildPendingState'
,
inverse_of: :build
has_one
:queuing_entry
,
class_name:
'Ci::PendingBuild'
,
foreign_key: :build_id
has_one
:
shared_runner_metadata
,
class_name:
'Ci::SharedRunner
Build'
,
foreign_key: :build_id
has_one
:
runtime_metadata
,
class_name:
'Ci::Running
Build'
,
foreign_key: :build_id
has_many
:trace_sections
,
class_name:
'Ci::BuildTraceSection'
has_many
:trace_chunks
,
class_name:
'Ci::BuildTraceChunk'
,
foreign_key: :build_id
,
inverse_of: :build
has_many
:report_results
,
class_name:
'Ci::BuildReportResult'
,
inverse_of: :build
...
...
@@ -1074,7 +1074,7 @@ module Ci
end
##
# We can have only one queuing entry or
shared runner
build tracking entry,
# We can have only one queuing entry or
running
build tracking entry,
# because there is a unique index on `build_id` in each table, but we need
# a relation to remove these entries more efficiently in a single statement
# without actually loading data.
...
...
@@ -1083,8 +1083,8 @@ module Ci
::
Ci
::
PendingBuild
.
where
(
build_id:
self
.
id
)
end
def
all_
shared_runner
_metadata
::
Ci
::
SharedRunner
Build
.
where
(
build_id:
self
.
id
)
def
all_
runtime
_metadata
::
Ci
::
Running
Build
.
where
(
build_id:
self
.
id
)
end
protected
...
...
app/models/ci/
shared_runner
_build.rb
→
app/models/ci/
running
_build.rb
View file @
2fb3c041
# frozen_string_literal: true
module
Ci
class
SharedRunner
Build
<
ApplicationRecord
class
Running
Build
<
ApplicationRecord
extend
Gitlab
::
Ci
::
Model
belongs_to
:project
belongs_to
:build
,
class_name:
'Ci::Build'
belongs_to
:runner
,
class_name:
'Ci::Runner'
def
self
.
upsert_from_build!
(
build
)
enum
runner_type:
::
Ci
::
Runner
.
runner_types
def
self
.
upsert_shared_runner_build!
(
build
)
unless
build
.
runner
&&
build
.
runner
.
instance_type?
raise
ArgumentError
,
'build has not been picked by a shared runner'
end
entry
=
self
.
new
(
build:
build
,
project:
build
.
project
,
runner:
build
.
runner
)
entry
=
self
.
new
(
build:
build
,
project:
build
.
project
,
runner:
build
.
runner
,
runner_type:
build
.
runner
.
runner_type
)
entry
.
validate!
...
...
app/services/ci/update_build_queue_service.rb
View file @
2fb3c041
...
...
@@ -49,7 +49,8 @@ module Ci
end
##
# Add shared runner build tracking entry (used for queuing).
# Add shared runner build tracking entry (used for queuing). This will rase
# an exception if a build has not been picked by a shared runner.
#
def
track
(
build
,
transition
)
return
unless
Feature
.
enabled?
(
:ci_track_shared_runner_builds
,
build
.
project
,
default_enabled: :yaml
)
...
...
@@ -57,7 +58,7 @@ module Ci
raise
InvalidQueueTransition
unless
transition
.
to
==
'running'
transition
.
within_transaction
do
result
=
::
Ci
::
SharedRunnerBuild
.
upsert_from
_build!
(
build
)
result
=
::
Ci
::
RunningBuild
.
upsert_shared_runner
_build!
(
build
)
unless
result
.
empty?
metrics
.
increment_queue_operation
(
:shared_runner_build_new
)
...
...
@@ -68,7 +69,7 @@ module Ci
end
##
# Remove a
shared runner
build tracking entry (used for queuing).
# Remove a
runtime
build tracking entry (used for queuing).
#
def
untrack
(
build
,
transition
)
return
unless
Feature
.
enabled?
(
:ci_untrack_shared_runner_builds
,
build
.
project
,
default_enabled: :yaml
)
...
...
@@ -76,7 +77,7 @@ module Ci
raise
InvalidQueueTransition
unless
transition
.
from
==
'running'
transition
.
within_transaction
do
removed
=
build
.
all_
shared_runner
_metadata
.
delete_all
removed
=
build
.
all_
runtime
_metadata
.
delete_all
if
removed
>
0
metrics
.
increment_queue_operation
(
:shared_runner_build_done
)
...
...
db/migrate/20210601123341_add_
shared_runner
_builds_table.rb
→
db/migrate/20210601123341_add_
running
_builds_table.rb
View file @
2fb3c041
# frozen_string_literal: true
class
Add
SharedRunner
BuildsTable
<
ActiveRecord
::
Migration
[
6.0
]
class
Add
Running
BuildsTable
<
ActiveRecord
::
Migration
[
6.0
]
def
up
create_table
:ci_
shared_runner
_builds
do
|
t
|
create_table
:ci_
running
_builds
do
|
t
|
t
.
references
:build
,
index:
{
unique:
true
},
null:
false
,
foreign_key:
{
to_table: :ci_builds
,
on_delete: :cascade
}
t
.
references
:project
,
index:
true
,
null:
false
,
foreign_key:
{
on_delete: :cascade
}
t
.
references
:runner
,
index:
true
,
null:
false
,
foreign_key:
{
to_table: :ci_runners
,
on_delete: :cascade
}
t
.
integer
:runner_type
,
limit:
2
,
null:
false
t
.
datetime_with_timezone
:created_at
,
null:
false
,
default:
->
{
'NOW()'
}
end
end
def
down
drop_table
:ci_
shared_runner
_builds
drop_table
:ci_
running
_builds
end
end
db/structure.sql
View file @
2fb3c041
...
...
@@ -11151,22 +11151,23 @@ CREATE SEQUENCE ci_runners_id_seq
ALTER SEQUENCE ci_runners_id_seq OWNED BY ci_runners.id;
CREATE TABLE ci_
shared_runner
_builds (
CREATE TABLE ci_
running
_builds (
id bigint NOT NULL,
build_id bigint NOT NULL,
project_id bigint NOT NULL,
runner_id bigint NOT NULL,
runner_type smallint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
);
CREATE SEQUENCE ci_
shared_runner
_builds_id_seq
CREATE SEQUENCE ci_
running
_builds_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE ci_
shared_runner_builds_id_seq OWNED BY ci_shared_runner
_builds.id;
ALTER SEQUENCE ci_
running_builds_id_seq OWNED BY ci_running
_builds.id;
CREATE TABLE ci_sources_pipelines (
id integer NOT NULL,
...
...
@@ -19714,7 +19715,7 @@ ALTER TABLE ONLY ci_runner_projects ALTER COLUMN id SET DEFAULT nextval('ci_runn
ALTER TABLE ONLY ci_runners ALTER COLUMN id SET DEFAULT nextval('ci_runners_id_seq'::regclass);
ALTER TABLE ONLY ci_
shared_runner_builds ALTER COLUMN id SET DEFAULT nextval('ci_shared_runner
_builds_id_seq'::regclass);
ALTER TABLE ONLY ci_
running_builds ALTER COLUMN id SET DEFAULT nextval('ci_running
_builds_id_seq'::regclass);
ALTER TABLE ONLY ci_sources_pipelines ALTER COLUMN id SET DEFAULT nextval('ci_sources_pipelines_id_seq'::regclass);
...
...
@@ -20915,8 +20916,8 @@ ALTER TABLE ONLY ci_runner_projects
ALTER TABLE ONLY ci_runners
ADD CONSTRAINT ci_runners_pkey PRIMARY KEY (id);
ALTER TABLE ONLY ci_
shared_runner
_builds
ADD CONSTRAINT ci_
shared_runner
_builds_pkey PRIMARY KEY (id);
ALTER TABLE ONLY ci_
running
_builds
ADD CONSTRAINT ci_
running
_builds_pkey PRIMARY KEY (id);
ALTER TABLE ONLY ci_sources_pipelines
ADD CONSTRAINT ci_sources_pipelines_pkey PRIMARY KEY (id);
...
...
@@ -22904,11 +22905,11 @@ CREATE INDEX index_ci_runners_on_token ON ci_runners USING btree (token);
CREATE INDEX index_ci_runners_on_token_encrypted ON ci_runners USING btree (token_encrypted);
CREATE UNIQUE INDEX index_ci_
shared_runner_builds_on_build_id ON ci_shared_runner
_builds USING btree (build_id);
CREATE UNIQUE INDEX index_ci_
running_builds_on_build_id ON ci_running
_builds USING btree (build_id);
CREATE INDEX index_ci_
shared_runner_builds_on_project_id ON ci_shared_runner
_builds USING btree (project_id);
CREATE INDEX index_ci_
running_builds_on_project_id ON ci_running
_builds USING btree (project_id);
CREATE INDEX index_ci_
shared_runner_builds_on_runner_id ON ci_shared_runner
_builds USING btree (runner_id);
CREATE INDEX index_ci_
running_builds_on_runner_id ON ci_running
_builds USING btree (runner_id);
CREATE INDEX index_ci_sources_pipelines_on_pipeline_id ON ci_sources_pipelines USING btree (pipeline_id);
...
...
@@ -26422,9 +26423,6 @@ ALTER TABLE ONLY onboarding_progresses
ALTER TABLE ONLY protected_branch_unprotect_access_levels
ADD CONSTRAINT fk_rails_2d2aba21ef FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_shared_runner_builds
ADD CONSTRAINT fk_rails_2de6fdddcb FOREIGN KEY (runner_id) REFERENCES ci_runners(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_freeze_periods
ADD CONSTRAINT fk_rails_2e02bbd1a6 FOREIGN KEY (project_id) REFERENCES projects(id);
...
...
@@ -26725,6 +26723,9 @@ ALTER TABLE ONLY vulnerability_scanners
ALTER TABLE ONLY reviews
ADD CONSTRAINT fk_rails_5ca11d8c31 FOREIGN KEY (merge_request_id) REFERENCES merge_requests(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_running_builds
ADD CONSTRAINT fk_rails_5ca491d360 FOREIGN KEY (runner_id) REFERENCES ci_runners(id) ON DELETE CASCADE;
ALTER TABLE ONLY epic_issues
ADD CONSTRAINT fk_rails_5d942936b4 FOREIGN KEY (epic_id) REFERENCES epics(id) ON DELETE CASCADE;
...
...
@@ -26824,9 +26825,6 @@ ALTER TABLE ONLY plan_limits
ALTER TABLE ONLY operations_feature_flags_issues
ADD CONSTRAINT fk_rails_6a8856ca4f FOREIGN KEY (feature_flag_id) REFERENCES operations_feature_flags(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_shared_runner_builds
ADD CONSTRAINT fk_rails_6b0c3012c9 FOREIGN KEY (build_id) REFERENCES ci_builds(id) ON DELETE CASCADE;
ALTER TABLE ONLY prometheus_alerts
ADD CONSTRAINT fk_rails_6d9b283465 FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE CASCADE;
...
...
@@ -27022,9 +27020,6 @@ ALTER TABLE ONLY alert_management_alert_user_mentions
ALTER TABLE ONLY project_daily_statistics
ADD CONSTRAINT fk_rails_8e549b272d FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_shared_runner_builds
ADD CONSTRAINT fk_rails_8f43a1469c FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_pipelines_config
ADD CONSTRAINT fk_rails_906c9a2533 FOREIGN KEY (pipeline_id) REFERENCES ci_pipelines(id) ON DELETE CASCADE;
...
...
@@ -27436,6 +27431,9 @@ ALTER TABLE ONLY geo_hashed_storage_attachments_events
ALTER TABLE ONLY merge_request_reviewers
ADD CONSTRAINT fk_rails_d9fec24b9d FOREIGN KEY (merge_request_id) REFERENCES merge_requests(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_running_builds
ADD CONSTRAINT fk_rails_da45cfa165 FOREIGN KEY (build_id) REFERENCES ci_builds(id) ON DELETE CASCADE;
ALTER TABLE ONLY jira_imports
ADD CONSTRAINT fk_rails_da617096ce FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
...
...
@@ -27448,6 +27446,9 @@ ALTER TABLE ONLY issues_prometheus_alert_events
ALTER TABLE ONLY board_user_preferences
ADD CONSTRAINT fk_rails_dbebdaa8fe FOREIGN KEY (board_id) REFERENCES boards(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_running_builds
ADD CONSTRAINT fk_rails_dc1d0801e8 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY vulnerability_occurrence_pipelines
ADD CONSTRAINT fk_rails_dc3ae04693 FOREIGN KEY (occurrence_id) REFERENCES vulnerability_occurrences(id) ON DELETE CASCADE;
spec/models/ci/
shared_runner
_build_spec.rb
→
spec/models/ci/
running
_build_spec.rb
View file @
2fb3c041
...
...
@@ -2,30 +2,33 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
SharedRunner
Build
do
RSpec
.
describe
Ci
::
Running
Build
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:instance_type
)
}
let
(
:build
)
{
create
(
:ci_build
,
:running
,
runner:
runner
,
pipeline:
pipeline
)
}
describe
'.upsert_
from
_build!'
do
describe
'.upsert_
shared_runner
_build!'
do
context
'another pending entry does not exist'
do
it
'creates a new pending entry'
do
result
=
described_class
.
upsert_
from
_build!
(
build
)
result
=
described_class
.
upsert_
shared_runner
_build!
(
build
)
expect
(
result
.
rows
.
dig
(
0
,
0
)).
to
eq
build
.
id
expect
(
build
.
reload
.
shared_runner
_metadata
).
to
be_present
expect
(
build
.
reload
.
runtime
_metadata
).
to
be_present
end
end
context
'when another queuing entry exists for given build'
do
before
do
described_class
.
create!
(
build:
build
,
project:
project
,
runner:
runner
)
described_class
.
create!
(
build:
build
,
project:
project
,
runner:
runner
,
runner_type:
runner
.
runner_type
)
end
it
'returns a build id as a result'
do
result
=
described_class
.
upsert_
from
_build!
(
build
)
result
=
described_class
.
upsert_
shared_runner
_build!
(
build
)
expect
(
result
.
rows
.
dig
(
0
,
0
)).
to
eq
build
.
id
end
...
...
@@ -35,7 +38,7 @@ RSpec.describe Ci::SharedRunnerBuild do
let
(
:runner
)
{
create
(
:ci_runner
,
:project
)
}
it
'raises an error'
do
expect
{
described_class
.
upsert_
from
_build!
(
build
)
}
expect
{
described_class
.
upsert_
shared_runner
_build!
(
build
)
}
.
to
raise_error
(
ArgumentError
,
'build has not been picked by a shared runner'
)
end
end
...
...
@@ -44,7 +47,7 @@ RSpec.describe Ci::SharedRunnerBuild do
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
it
'raises an error'
do
expect
{
described_class
.
upsert_
from
_build!
(
build
)
}
expect
{
described_class
.
upsert_
shared_runner
_build!
(
build
)
}
.
to
raise_error
(
ArgumentError
,
'build has not been picked by a shared runner'
)
end
end
...
...
spec/services/ci/retry_build_service_spec.rb
View file @
2fb3c041
...
...
@@ -60,7 +60,7 @@ RSpec.describe Ci::RetryBuildService do
artifacts_file artifacts_metadata artifacts_size commands
resource resource_group_id processed security_scans author
pipeline_id report_results pending_state pages_deployments
queuing_entry
shared_runner
_metadata]
.
freeze
queuing_entry
runtime
_metadata]
.
freeze
shared_examples
'build duplication'
do
let_it_be
(
:another_pipeline
)
{
create
(
:ci_empty_pipeline
,
project:
project
)
}
...
...
spec/services/ci/update_build_queue_service_spec.rb
View file @
2fb3c041
...
...
@@ -146,8 +146,9 @@ RSpec.describe Ci::UpdateBuildQueueService do
context
'when duplicate entry exists'
do
before
do
::
Ci
::
SharedRunnerBuild
.
create!
(
build:
build
,
project:
project
,
runner:
runner
)
::
Ci
::
RunningBuild
.
create!
(
build:
build
,
project:
project
,
runner:
runner
,
runner_type:
runner
.
runner_type
)
end
it
'does nothing and returns build id'
do
...
...
@@ -168,8 +169,9 @@ RSpec.describe Ci::UpdateBuildQueueService do
context
'when shared runner build tracking entry exists'
do
before
do
Ci
::
SharedRunnerBuild
.
create!
(
build:
build
,
project:
project
,
runner:
runner
)
Ci
::
RunningBuild
.
create!
(
build:
build
,
project:
project
,
runner:
runner
,
runner_type:
runner
.
runner_type
)
end
it
'removes shared runner build'
do
...
...
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