Commit 19484c77 authored by Gary Holtz's avatar Gary Holtz

Adding a new metric for total highlighting attempts

parent 79d47ab2
...@@ -32,8 +32,12 @@ module Gitlab ...@@ -32,8 +32,12 @@ module Gitlab
def highlight(text, continue: false, plain: false, context: {}) def highlight(text, continue: false, plain: false, context: {})
@context = context @context = context
add_highlight_attempt_metric
plain ||= self.class.too_large?(text.length) plain ||= self.class.too_large?(text.length)
highlight_timeout.increment(source: Gitlab::Runtime.sidekiq? ? "background" : "foreground")
highlighted_text = highlight_text(text, continue: continue, plain: plain) highlighted_text = highlight_text(text, continue: continue, plain: plain)
highlighted_text = link_dependencies(text, highlighted_text) if blob_name highlighted_text = link_dependencies(text, highlighted_text) if blob_name
highlighted_text highlighted_text
...@@ -90,12 +94,25 @@ module Gitlab ...@@ -90,12 +94,25 @@ module Gitlab
Gitlab::DependencyLinker.link(blob_name, text, highlighted_text) Gitlab::DependencyLinker.link(blob_name, text, highlighted_text)
end end
def add_highlight_attempt_metric
return unless Feature.enabled?(:track_highlight_timeouts)
highlighting_attempt.increment(source: @language || "undefined")
end
def add_highlight_timeout_metric def add_highlight_timeout_metric
return unless Feature.enabled?(:track_highlight_timeouts) return unless Feature.enabled?(:track_highlight_timeouts)
highlight_timeout.increment(source: Gitlab::Runtime.sidekiq? ? "background" : "foreground") highlight_timeout.increment(source: Gitlab::Runtime.sidekiq? ? "background" : "foreground")
end end
def highlighting_attempt
@highlight_timeout ||= Gitlab::Metrics.counter(
:file_highlighting_attempt,
'Counts the times highlighting has been attempted on a file'
)
end
def highlight_timeout def highlight_timeout
@highlight_timeout ||= Gitlab::Metrics.counter( @highlight_timeout ||= Gitlab::Metrics.counter(
:highlight_timeout, :highlight_timeout,
......
...@@ -143,6 +143,14 @@ RSpec.describe Gitlab::Highlight do ...@@ -143,6 +143,14 @@ RSpec.describe Gitlab::Highlight do
end end
describe 'highlight timeouts' do describe 'highlight timeouts' do
context 'when there is an attempt' do
let(:result) { described_class.highlight(file_name, content) }
it "increments the foreground counter if it's in the foreground" do
expect { result }.to change { highlight_attempt_total("undefined") }
end
end
context 'when there is a timeout error while highlighting' do context 'when there is a timeout error while highlighting' do
let(:result) { described_class.highlight(file_name, content) } let(:result) { described_class.highlight(file_name, content) }
...@@ -177,6 +185,12 @@ RSpec.describe Gitlab::Highlight do ...@@ -177,6 +185,12 @@ RSpec.describe Gitlab::Highlight do
.get(source: source) .get(source: source)
end end
def highlight_attempt_total(source)
Gitlab::Metrics
.counter(:file_highlighting_attempt, 'Counts the times highlighting has been attempted on a file')
.get(source: source)
end
def over_highlight_size_limit(source) def over_highlight_size_limit(source)
Gitlab::Metrics Gitlab::Metrics
.counter(:over_highlight_size_limit, .counter(:over_highlight_size_limit,
......
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