Commit 493869e5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add new prometheus counter for corrupted build logs

This commit adds a new metric we will increment once we detect a
corrupted build log. Corrupted build log is detected when checking CRC32
checksum yields an invalid result and the build size differs from the
size reported by a runner.
parent 5704c69e
......@@ -64,6 +64,12 @@ module Gitlab
end
end
def trace_size
trace_chunks.reduce(0) do |total, chunk|
total + chunk_size(chunk)
end
end
def chunks_count
trace_chunks.to_a.size
end
......
......@@ -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)
......
......@@ -113,6 +113,18 @@ RSpec.describe Gitlab::Ci::Trace::Checksum do
end
end
describe '#trace_size' do
before do
create_chunk(index: 0, data: 'a' * 128.kilobytes)
create_chunk(index: 1, data: 'b' * 128.kilobytes)
create_chunk(index: 2, data: 'abcdefg-ü')
end
it 'returns total trace size in bytes' do
expect(subject.trace_size).to eq 262154
end
end
def create_chunk(index:, data:)
create(:ci_build_trace_chunk, :persisted, build: build,
chunk_index: index,
......
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