Commit 19043952 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '296616-continue-trace-archive-if-not-complete' into 'master'

Retry CI trace archive if left in incomplete state

See merge request gitlab-org/gitlab!68906
parents 2cada262 bc509e2f
...@@ -191,11 +191,7 @@ module Gitlab ...@@ -191,11 +191,7 @@ module Gitlab
def unsafe_archive! def unsafe_archive!
raise ArchiveError, 'Job is not finished yet' unless job.complete? raise ArchiveError, 'Job is not finished yet' unless job.complete?
if trace_artifact unsafe_trace_conditionally_cleanup_before_retry!
unsafe_trace_cleanup!
raise AlreadyArchivedError, 'Could not archive again'
end
if job.trace_chunks.any? if job.trace_chunks.any?
Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream| Gitlab::Ci::Trace::ChunkedIO.new(job) do |stream|
...@@ -215,12 +211,19 @@ module Gitlab ...@@ -215,12 +211,19 @@ module Gitlab
end end
end end
def unsafe_trace_cleanup! def already_archived?
# TODO check checksum to ensure archive completed successfully
# See https://gitlab.com/gitlab-org/gitlab/-/issues/259619
trace_artifact.archived_trace_exists?
end
def unsafe_trace_conditionally_cleanup_before_retry!
return unless trace_artifact return unless trace_artifact
if trace_artifact.archived_trace_exists? if already_archived?
# An archive already exists, so make sure to remove the trace chunks # An archive already exists, so make sure to remove the trace chunks
erase_trace_chunks! erase_trace_chunks!
raise AlreadyArchivedError, 'Could not archive again'
else else
# An archive already exists, but its associated file does not, so remove it # An archive already exists, but its associated file does not, so remove it
trace_artifact.destroy! trace_artifact.destroy!
......
...@@ -28,7 +28,7 @@ RSpec.describe Ci::ArchiveTraceService, '#execute' do ...@@ -28,7 +28,7 @@ RSpec.describe Ci::ArchiveTraceService, '#execute' do
context 'when live trace chunks still exist' do context 'when live trace chunks still exist' do
before do before do
create(:ci_build_trace_chunk, build: job) create(:ci_build_trace_chunk, build: job, chunk_index: 0)
end end
it 'removes the trace chunks' do it 'removes the trace chunks' do
...@@ -40,8 +40,14 @@ RSpec.describe Ci::ArchiveTraceService, '#execute' do ...@@ -40,8 +40,14 @@ RSpec.describe Ci::ArchiveTraceService, '#execute' do
job.job_artifacts_trace.file.remove! job.job_artifacts_trace.file.remove!
end end
it 'removes the trace artifact' do it 'removes the trace artifact and builds a new one' do
expect { subject }.to change { job.reload.job_artifacts_trace }.to(nil) existing_trace = job.job_artifacts_trace
expect(existing_trace).to receive(:destroy!).and_call_original
subject
expect(job.reload.job_artifacts_trace).to be_present
expect(job.reload.job_artifacts_trace.file.file).to be_present
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment