diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-02 09:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-02 09:08:59 +0300 |
commit | 5ab92edc77d032261ce105e3fa13355b92f8ed32 (patch) | |
tree | d2628c82859c7c8810481ec54c7d564f2e080b78 /lib/gitlab/other_markup.rb | |
parent | 0409a31740fa29fa1131c0496da16677cb3debe4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/other_markup.rb')
-rw-r--r-- | lib/gitlab/other_markup.rb | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/gitlab/other_markup.rb b/lib/gitlab/other_markup.rb index 0dd6b8a809c..2fb83e5d9eb 100644 --- a/lib/gitlab/other_markup.rb +++ b/lib/gitlab/other_markup.rb @@ -3,18 +3,39 @@ module Gitlab # Parser/renderer for markups without other special support code. module OtherMarkup + RENDER_TIMEOUT = 10.seconds + # Public: Converts the provided markup into HTML. # # input - the source text in a markup format # def self.render(file_name, input, context) - html = GitHub::Markup.render(file_name, input) - .force_encoding(input.encoding) + html = render_markup(file_name, input, context).force_encoding(input.encoding) + context[:pipeline] ||= :markup html = Banzai.render(html, context) - html.html_safe end + + def self.render_markup(file_name, input, context) + if Feature.enabled?(:markup_rendering_timeout, context[:project]) + Gitlab::RenderTimeout.timeout(foreground: RENDER_TIMEOUT) { GitHub::Markup.render(file_name, input) } + else + GitHub::Markup.render(file_name, input) + end + + rescue Timeout::Error => e + class_name = name.demodulize + timeout_counter.increment(source: class_name) + Gitlab::ErrorTracking.track_exception(e, project_id: context[:project]&.id, class_name: class_name, + file_name: file_name) + + ActionController::Base.helpers.simple_format(input) + end + + def self.timeout_counter + Gitlab::Metrics.counter(:banzai_filter_timeouts_total, 'Count of the Banzai filters that time out') + end end end |