diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /lib/gitlab/highlight.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'lib/gitlab/highlight.rb')
-rw-r--r-- | lib/gitlab/highlight.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index e4857280969..d05ced00a6b 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -11,9 +11,11 @@ module Gitlab end def self.too_large?(size) - return false unless size.to_i > Gitlab.config.extra['maximum_text_highlight_size_kilobytes'] + file_size_limit = 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) + return false unless size.to_i > file_size_limit + + over_highlight_size_limit.increment(source: "file size: #{file_size_limit}") if Feature.enabled?(:track_file_size_over_highlight_limit) true end @@ -68,6 +70,8 @@ module Gitlab end def highlight_rich(text, continue: true) + add_highlight_attempt_metric + tag = lexer.tag tokens = lexer.lex(text, continue: continue) Timeout.timeout(timeout_time) { @formatter.format(tokens, context.merge(tag: tag)).html_safe } @@ -88,12 +92,25 @@ module Gitlab Gitlab::DependencyLinker.link(blob_name, text, highlighted_text) 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 return unless Feature.enabled?(:track_highlight_timeouts) highlight_timeout.increment(source: Gitlab::Runtime.sidekiq? ? "background" : "foreground") end + def highlighting_attempt + @highlight_attempt ||= Gitlab::Metrics.counter( + :file_highlighting_attempt, + 'Counts the times highlighting has been attempted on a file' + ) + end + def highlight_timeout @highlight_timeout ||= Gitlab::Metrics.counter( :highlight_timeout, |