Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-14 18:08:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-14 18:08:59 +0300
commit9b762f50fee09b50b97b5ab208a9a62522447c8c (patch)
tree4dbd16c66f6aeacc1b88c1e3350df09ce4f91183 /lib/gitlab/diff
parent9769ccf613ec45634ee32efaf1c39763a759a917 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r--lib/gitlab/diff/rendered/notebook/diff_file.rb42
1 files changed, 35 insertions, 7 deletions
diff --git a/lib/gitlab/diff/rendered/notebook/diff_file.rb b/lib/gitlab/diff/rendered/notebook/diff_file.rb
index fb70f80c21b..cf97569ca31 100644
--- a/lib/gitlab/diff/rendered/notebook/diff_file.rb
+++ b/lib/gitlab/diff/rendered/notebook/diff_file.rb
@@ -6,6 +6,14 @@ module Gitlab
include Gitlab::Utils::StrongMemoize
class DiffFile < Gitlab::Diff::File
+ RENDERED_TIMEOUT_BACKGROUND = 10.seconds
+ RENDERED_TIMEOUT_FOREGROUND = 1.5.seconds
+ BACKGROUND_EXECUTION = 'background'
+ FOREGROUND_EXECUTION = 'foreground'
+ LOG_IPYNBDIFF_GENERATED = 'IPYNB_DIFF_GENERATED'
+ LOG_IPYNBDIFF_TIMEOUT = 'IPYNB_DIFF_TIMEOUT'
+ LOG_IPYNBDIFF_INVALID = 'IPYNB_DIFF_INVALID'
+
attr_reader :source_diff
delegate :repository, :diff_refs, :fallback_diff_refs, :unfolded, :unique_identifier,
@@ -52,14 +60,17 @@ module Gitlab
def notebook_diff
strong_memoize(:notebook_diff) do
- Gitlab::AppLogger.info({ message: 'IPYNB_DIFF_GENERATED' })
-
- IpynbDiff.diff(source_diff.old_blob&.data, source_diff.new_blob&.data,
- raise_if_invalid_nb: true,
- diffy_opts: { include_diff_info: true })
+ Timeout.timeout(timeout_time) do
+ IpynbDiff.diff(source_diff.old_blob&.data, source_diff.new_blob&.data,
+ raise_if_invalid_nb: true, diffy_opts: { include_diff_info: true })&.tap do
+ log_event(LOG_IPYNBDIFF_GENERATED)
+ end
+ end
+ rescue Timeout::Error => e
+ rendered_timeout.increment(source: Gitlab::Runtime.sidekiq? ? BACKGROUND_EXECUTION : FOREGROUND_EXECUTION)
+ log_event(LOG_IPYNBDIFF_TIMEOUT, e)
rescue IpynbDiff::InvalidNotebookError, IpynbDiff::InvalidTokenError => e
- Gitlab::ErrorTracking.log_exception(e)
- nil
+ log_event(LOG_IPYNBDIFF_INVALID, e)
end
end
@@ -116,6 +127,23 @@ module Gitlab
[removals, additions]
end
+
+ def rendered_timeout
+ @rendered_timeout ||= Gitlab::Metrics.counter(
+ :ipynb_semantic_diff_timeouts_total,
+ 'Counts the times notebook diff rendering timed out'
+ )
+ end
+
+ def timeout_time
+ Gitlab::Runtime.sidekiq? ? RENDERED_TIMEOUT_BACKGROUND : RENDERED_TIMEOUT_FOREGROUND
+ end
+
+ def log_event(message, error = nil)
+ Gitlab::AppLogger.info({ message: message })
+ Gitlab::ErrorTracking.track_exception(error) if error
+ nil
+ end
end
end
end