Commit 91b7a1e4 authored by Nick Thomas's avatar Nick Thomas

Merge branch '204891-enable-gathering-metrics-of-blob-truncation' into 'master'

Begin collecting blob truncation metrics

See merge request gitlab-org/gitlab!25464
parents 9dfd885b df0081ee
......@@ -124,11 +124,12 @@ module Gitlab
self.__send__("#{key}=", options[key.to_sym]) # rubocop:disable GitlabSecurity/PublicSend
end
record_metric_blob_size
# Retain the actual size before it is encoded
@loaded_size = @data.bytesize if @data
@loaded_all_data = @loaded_size == size
record_metric_blob_size
record_metric_truncated(truncated?)
end
def binary_in_repo?
......@@ -210,6 +211,14 @@ module Gitlab
self.class.gitlab_blob_size.observe({}, size)
end
def record_metric_truncated(bool)
if bool
self.class.gitlab_blob_truncated_true.increment
else
self.class.gitlab_blob_truncated_false.increment
end
end
def has_lfs_version_key?
!empty? && text_in_repo? && data.start_with?("version https://git-lfs.github.com/spec")
end
......
......@@ -22,7 +22,23 @@ describe Gitlab::Git::Blob, :seed_helper do
it 'records blob size' do
expect(described_class).to receive(:gitlab_blob_size).and_call_original
Gitlab::Git::Blob.new(name: 'test', size: 1234)
Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abcd')
end
context 'when untruncated' do
it 'attempts to record gitlab_blob_truncated_false' do
expect(described_class).to receive(:gitlab_blob_truncated_false).and_call_original
Gitlab::Git::Blob.new(name: 'test', size: 4, data: 'abcd')
end
end
context 'when truncated' do
it 'attempts to record gitlab_blob_truncated_true' do
expect(described_class).to receive(:gitlab_blob_truncated_true).and_call_original
Gitlab::Git::Blob.new(name: 'test', size: 40, data: 'abcd')
end
end
end
......
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