diff options
Diffstat (limited to 'lib/gitlab/ci/trace')
-rw-r--r-- | lib/gitlab/ci/trace/checksum.rb | 23 | ||||
-rw-r--r-- | lib/gitlab/ci/trace/metrics.rb | 3 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/gitlab/ci/trace/checksum.rb b/lib/gitlab/ci/trace/checksum.rb index 62532ef1cd2..7cdb6a6c03c 100644 --- a/lib/gitlab/ci/trace/checksum.rb +++ b/lib/gitlab/ci/trace/checksum.rb @@ -64,10 +64,33 @@ module Gitlab end end + def state_bytesize + strong_memoize(:state_bytesize) do + build.pending_state&.trace_bytesize + end + end + + def trace_size + strong_memoize(:trace_size) do + trace_chunks.sum { |chunk| chunk_size(chunk) } + end + end + + def corrupted? + return false unless has_bytesize? + return false if valid? + + state_bytesize.to_i != trace_size.to_i + end + def chunks_count trace_chunks.to_a.size end + def has_bytesize? + state_bytesize.present? + end + private def chunk_size(chunk) diff --git a/lib/gitlab/ci/trace/metrics.rb b/lib/gitlab/ci/trace/metrics.rb index 097436d84ea..ce9efbda7ea 100644 --- a/lib/gitlab/ci/trace/metrics.rb +++ b/lib/gitlab/ci/trace/metrics.rb @@ -18,7 +18,8 @@ module Gitlab :conflict, # runner has sent unrecognized build state details :locked, # build trace has been locked by a different mechanism :stalled, # failed to migrate chunk due to a worker duplication - :invalid # malformed build trace has been detected using CRC32 + :invalid, # invalid build trace has been detected using CRC32 + :corrupted # malformed trace found after comparing CRC32 and size ].freeze def increment_trace_operation(operation: :unknown) |