Commit 6f240a53 authored by Stan Hu's avatar Stan Hu

Add more logging to track encoding errors appending CI traces

We are seeing a recent increase in `Encoding::CompatibilityError`
errors. This commit adds more logging to understand the root cause.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/333424

Changelog: other
parent 39f94c3d
......@@ -33,6 +33,20 @@ module Ci
set_data(model, new_data)
new_data.bytesize
rescue Encoding::CompatibilityError => e
Gitlab::ErrorTracking.track_and_raise_exception(
e,
build_id: model.build_id,
chunk_index: model.chunk_index,
chunk_start_offset: model.start_offset,
chunk_end_offset: model.end_offset,
chunk_size: model.size,
chunk_data_store: model.data_store,
offset: offset,
old_data_encoding: truncated_data.encoding.to_s,
new_data: new_data,
new_data_size: new_data.bytesize,
new_data_encoding: new_data.encoding.to_s)
end
def size(model)
......
......@@ -102,6 +102,23 @@ RSpec.describe Ci::BuildTraceChunks::Fog do
end
end
describe '#append_data' do
let(:model) { create(:ci_build_trace_chunk, :fog_with_data, initial_data: (+'😺').force_encoding('ASCII-8BIT')) }
let(:data) { data_store.data(model) }
it 'appends ASCII data' do
data_store.append_data(model, 'hello world', 4)
expect(data.encoding).to eq(Encoding.find('ASCII-8BIT'))
expect(data.force_encoding('UTF-8')).to eq('😺hello world')
end
it 'throws an exception when appending UTF-8 data' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_exception).and_call_original
expect { data_store.append_data(model, 'Résumé', 4) }.to raise_exception(Encoding::CompatibilityError)
end
end
describe '#delete_data' do
subject { data_store.delete_data(model) }
......
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