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
bbf08ffe
Commit
bbf08ffe
authored
Sep 27, 2021
by
Marius Bobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store MD5 checksum for archived traces
Store MD5 checksum for archived traces
parent
fe07d8c4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
32 deletions
+81
-32
app/models/ci/build_trace_metadata.rb
app/models/ci/build_trace_metadata.rb
+4
-2
app/services/ci/archive_build_trace_service.rb
app/services/ci/archive_build_trace_service.rb
+49
-0
lib/gitlab/ci/trace.rb
lib/gitlab/ci/trace.rb
+1
-29
spec/models/ci/build_trace_metadata_spec.rb
spec/models/ci/build_trace_metadata_spec.rb
+3
-1
spec/services/ci/archive_build_trace_service_spec.rb
spec/services/ci/archive_build_trace_service_spec.rb
+24
-0
No files found.
app/models/ci/build_trace_metadata.rb
View file @
bbf08ffe
...
...
@@ -37,8 +37,10 @@ module Ci
increment!
(
:archival_attempts
,
touch: :last_archival_attempt_at
)
end
def
track_archival!
(
trace_artifact_id
)
update!
(
trace_artifact_id:
trace_artifact_id
,
archived_at:
Time
.
current
)
def
track_archival!
(
trace_artifact_id
,
checksum
)
update!
(
trace_artifact_id:
trace_artifact_id
,
checksum:
checksum
,
archived_at:
Time
.
current
)
end
def
archival_attempts_message
...
...
app/services/ci/archive_build_trace_service.rb
0 → 100644
View file @
bbf08ffe
# frozen_string_literal: true
module
Ci
class
ArchiveBuildTraceService
include
::
Gitlab
::
Utils
::
StrongMemoize
include
Checksummable
attr_reader
:job
,
:trace_metadata
def
initialize
(
job
,
trace_metadata
)
@job
=
job
@trace_metadata
=
trace_metadata
end
def
execute!
(
stream
)
clone_file!
(
stream
,
JobArtifactUploader
.
workhorse_upload_path
)
do
|
clone_path
|
md5_checksum
=
self
.
class
.
md5_hexdigest
(
clone_path
)
trace_artifact
=
create_build_trace!
(
job
,
clone_path
)
trace_metadata
.
track_archival!
(
trace_artifact
.
id
,
md5_checksum
)
end
end
private
def
clone_file!
(
src_stream
,
temp_dir
)
FileUtils
.
mkdir_p
(
temp_dir
)
Dir
.
mktmpdir
(
"tmp-trace-
#{
job
.
id
}
"
,
temp_dir
)
do
|
dir_path
|
temp_path
=
File
.
join
(
dir_path
,
"job.log"
)
FileUtils
.
touch
(
temp_path
)
size
=
IO
.
copy_stream
(
src_stream
,
temp_path
)
raise
::
Gitlab
::
Ci
::
Trace
::
ArchiveError
,
'Failed to copy stream'
unless
size
==
src_stream
.
size
yield
(
temp_path
)
end
end
def
create_build_trace!
(
job
,
path
)
File
.
open
(
path
)
do
|
stream
|
# TODO: Set `file_format: :raw` after we've cleaned up legacy traces migration
# https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20307
job
.
create_job_artifacts_trace!
(
project:
job
.
project
,
file_type: :trace
,
file:
stream
,
file_sha256:
self
.
class
.
sha256_hexdigest
(
path
))
end
end
end
end
lib/gitlab/ci/trace.rb
View file @
bbf08ffe
...
...
@@ -236,35 +236,7 @@ module Gitlab
end
def
archive_stream!
(
stream
)
clone_file!
(
stream
,
JobArtifactUploader
.
workhorse_upload_path
)
do
|
clone_path
|
create_build_trace!
(
job
,
clone_path
)
end
end
def
clone_file!
(
src_stream
,
temp_dir
)
FileUtils
.
mkdir_p
(
temp_dir
)
Dir
.
mktmpdir
(
"tmp-trace-
#{
job
.
id
}
"
,
temp_dir
)
do
|
dir_path
|
temp_path
=
File
.
join
(
dir_path
,
"job.log"
)
FileUtils
.
touch
(
temp_path
)
size
=
IO
.
copy_stream
(
src_stream
,
temp_path
)
raise
ArchiveError
,
'Failed to copy stream'
unless
size
==
src_stream
.
size
yield
(
temp_path
)
end
end
def
create_build_trace!
(
job
,
path
)
File
.
open
(
path
)
do
|
stream
|
# TODO: Set `file_format: :raw` after we've cleaned up legacy traces migration
# https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/20307
trace_artifact
=
job
.
create_job_artifacts_trace!
(
project:
job
.
project
,
file_type: :trace
,
file:
stream
,
file_sha256:
self
.
class
.
sha256_hexdigest
(
path
))
trace_metadata
.
track_archival!
(
trace_artifact
.
id
)
end
::
Ci
::
ArchiveBuildTraceService
.
new
(
job
,
trace_metadata
).
execute!
(
stream
)
end
def
trace_metadata
...
...
spec/models/ci/build_trace_metadata_spec.rb
View file @
bbf08ffe
...
...
@@ -88,14 +88,16 @@ RSpec.describe Ci::BuildTraceMetadata do
describe
'#track_archival!'
do
let
(
:trace_artifact
)
{
create
(
:ci_job_artifact
)
}
let
(
:metadata
)
{
create
(
:ci_build_trace_metadata
)
}
let
(
:checksum
)
{
SecureRandom
.
hex
}
it
'stores the artifact id and timestamp'
do
expect
(
metadata
.
trace_artifact_id
).
to
be_nil
metadata
.
track_archival!
(
trace_artifact
.
id
)
metadata
.
track_archival!
(
trace_artifact
.
id
,
checksum
)
metadata
.
reload
expect
(
metadata
.
trace_artifact_id
).
to
eq
(
trace_artifact
.
id
)
expect
(
metadata
.
checksum
).
to
eq
(
checksum
)
expect
(
metadata
.
archived_at
).
to
be_like_time
(
Time
.
current
)
end
end
...
...
spec/services/ci/archive_build_trace_service_spec.rb
0 → 100644
View file @
bbf08ffe
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Ci
::
ArchiveBuildTraceService
do
let_it_be
(
:job
)
{
create
(
:ci_build
,
:success
,
:trace_live
)
}
let_it_be
(
:trace_metadata
)
{
create
(
:ci_build_trace_metadata
,
build:
job
)
}
let_it_be
(
:src_checksum
)
do
job
.
trace
.
read
{
|
stream
|
Digest
::
MD5
.
hexdigest
(
stream
.
raw
)
}
end
describe
'#execute'
do
subject
{
described_class
.
new
(
job
,
trace_metadata
)
}
it
'computes and assigns checksum'
do
Gitlab
::
Ci
::
Trace
::
ChunkedIO
.
new
(
job
)
do
|
stream
|
expect
{
subject
.
execute!
(
stream
)
}.
to
change
{
Ci
::
JobArtifact
.
count
}.
by
(
1
)
end
expect
(
trace_metadata
.
checksum
).
to
eq
(
src_checksum
)
expect
(
trace_metadata
.
trace_artifact
).
to
eq
(
job
.
job_artifacts_trace
)
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