Commit 61875426 authored by Gary Holtz's avatar Gary Holtz Committed by Mark Chao

Adding initial tracking for file size highlight limits

parent db8dc95f
---
name: track_file_size_over_highlight_limit
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61273
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/330374
milestone: '13.12'
type: development
group: group::code review
default_enabled: false
......@@ -11,7 +11,11 @@ module Gitlab
end
def self.too_large?(size)
size.to_i > Gitlab.config.extra['maximum_text_highlight_size_kilobytes']
return false unless size.to_i > Gitlab.config.extra['maximum_text_highlight_size_kilobytes']
over_highlight_size_limit.increment(source: "text highlighter") if Feature.enabled?(:track_file_size_over_highlight_limit)
true
end
attr_reader :blob_name
......@@ -96,5 +100,12 @@ module Gitlab
'Counts the times highlights have timed out'
)
end
def self.over_highlight_size_limit
@over_highlight_size_limit ||= Gitlab::Metrics.counter(
:over_highlight_size_limit,
'Count the times files have been over the highlight size limit'
)
end
end
end
......@@ -46,13 +46,21 @@ RSpec.describe Gitlab::Highlight do
expect(result).to eq(%[<span id="LC1" class="line" lang="plaintext">plain text contents</span>])
end
it 'returns plain version for long content' do
context 'when content is too long to be highlighted' do
let(:result) { described_class.highlight(file_name, content) } # content is 44 bytes
before do
stub_config(extra: { 'maximum_text_highlight_size_kilobytes' => 0.0001 } ) # 1.024 bytes
end
result = described_class.highlight(file_name, content) # content is 44 bytes
it 'increments the metric for oversized files' do
expect { result }.to change { over_highlight_size_limit('text highlighter') }.by(1)
end
it 'returns plain version for long content' do
expect(result).to eq(%[<span id="LC1" class="line" lang="">(make-pathname :defaults name</span>\n<span id="LC2" class="line" lang="">:type "assem")</span>])
end
end
it 'highlights multi-line comments' do
result = described_class.highlight(file_name, multiline_content)
......@@ -168,4 +176,11 @@ RSpec.describe Gitlab::Highlight do
.counter(:highlight_timeout, 'Counts the times highlights have timed out')
.get(source: source)
end
def over_highlight_size_limit(source)
Gitlab::Metrics
.counter(:over_highlight_size_limit,
'Count the times text has been over the highlight size limit')
.get(source: source)
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