Commit 6bc3aace authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'sh-force-encode-ci-trace-chunks' into 'master'

Add more logging to track encoding errors appending CI traces

See merge request gitlab-org/gitlab!63920
parents 89ab38fb 6f240a53
......@@ -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