diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-06 15:10:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-06 15:10:38 +0300 |
commit | 25db9c1230f7b54a7337b3d2dfe714478a7d54f0 (patch) | |
tree | b9b8d6494ad4098c52eb029ae6a47d795abf9f5b /lib/gitlab/highlight.rb | |
parent | c06178d51ad9b8d4ce665047873615facfc9c1c5 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/highlight.rb')
-rw-r--r-- | lib/gitlab/highlight.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index 06558e1a212..45f17d73f30 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -10,6 +10,10 @@ module Gitlab .highlight(blob_content, continue: false, plain: plain) end + def self.too_large?(size) + size.to_i > Gitlab.config.extra['maximum_text_highlight_size_kilobytes'] + end + attr_reader :blob_name def initialize(blob_name, blob_content, language: nil) @@ -22,7 +26,7 @@ module Gitlab def highlight(text, continue: false, plain: false, context: {}) @context = context - plain ||= text.length > maximum_text_highlight_size + plain ||= self.class.too_large?(text.length) highlighted_text = highlight_text(text, continue: continue, plain: plain) highlighted_text = link_dependencies(text, highlighted_text) if blob_name @@ -64,6 +68,8 @@ module Gitlab tokens = lexer.lex(text, continue: continue) Timeout.timeout(timeout_time) { @formatter.format(tokens, context.merge(tag: tag)).html_safe } rescue Timeout::Error => e + add_highlight_timeout_metric + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) highlight_plain(text) rescue StandardError @@ -78,8 +84,17 @@ module Gitlab Gitlab::DependencyLinker.link(blob_name, text, highlighted_text) end - def maximum_text_highlight_size - Gitlab.config.extra['maximum_text_highlight_size_kilobytes'] + def add_highlight_timeout_metric + return unless Feature.enabled?(:track_highlight_timeouts) + + highlight_timeout.increment(source: Gitlab::Runtime.sidekiq? ? "background" : "foreground") + end + + def highlight_timeout + @highlight_timeout ||= Gitlab::Metrics.counter( + :highlight_timeout, + 'Counts the times highlights have timed out' + ) end end end |