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>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /lib/gitlab/middleware
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/gitlab/middleware')
-rw-r--r--lib/gitlab/middleware/rack_multipart_tempfile_factory.rb4
-rw-r--r--lib/gitlab/middleware/read_only/controller.rb2
-rw-r--r--lib/gitlab/middleware/speedscope.rb78
3 files changed, 80 insertions, 4 deletions
diff --git a/lib/gitlab/middleware/rack_multipart_tempfile_factory.rb b/lib/gitlab/middleware/rack_multipart_tempfile_factory.rb
index d16c068c3c0..1686c3324b4 100644
--- a/lib/gitlab/middleware/rack_multipart_tempfile_factory.rb
+++ b/lib/gitlab/middleware/rack_multipart_tempfile_factory.rb
@@ -14,9 +14,7 @@ module Gitlab
end
def call(env)
- if ENV['GITLAB_TEMPFILE_IMMEDIATE_UNLINK'] == '1'
- env[Rack::RACK_MULTIPART_TEMPFILE_FACTORY] = FACTORY
- end
+ env[Rack::RACK_MULTIPART_TEMPFILE_FACTORY] = FACTORY
@app.call(env)
end
diff --git a/lib/gitlab/middleware/read_only/controller.rb b/lib/gitlab/middleware/read_only/controller.rb
index 226ef2041b2..65c08664a2b 100644
--- a/lib/gitlab/middleware/read_only/controller.rb
+++ b/lib/gitlab/middleware/read_only/controller.rb
@@ -153,4 +153,4 @@ module Gitlab
end
end
-Gitlab::Middleware::ReadOnly::Controller.prepend_if_ee('EE::Gitlab::Middleware::ReadOnly::Controller')
+Gitlab::Middleware::ReadOnly::Controller.prepend_mod_with('Gitlab::Middleware::ReadOnly::Controller')
diff --git a/lib/gitlab/middleware/speedscope.rb b/lib/gitlab/middleware/speedscope.rb
new file mode 100644
index 00000000000..74f334d9ab3
--- /dev/null
+++ b/lib/gitlab/middleware/speedscope.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Middleware
+ class Speedscope
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ request = ActionDispatch::Request.new(env)
+
+ return @app.call(env) unless rendering_flamegraph?(request)
+
+ body = nil
+
+ ::Gitlab::SafeRequestStore[:capturing_flamegraph] = true
+
+ require 'stackprof'
+
+ begin
+ flamegraph = ::StackProf.run(
+ mode: :wall,
+ raw: true,
+ aggregate: false,
+ interval: ::Gitlab::StackProf::DEFAULT_INTERVAL_US
+ ) do
+ _, _, body = @app.call(env)
+ end
+ ensure
+ body.close if body.respond_to?(:close)
+ end
+
+ render_flamegraph(flamegraph, request)
+ end
+
+ private
+
+ def rendering_flamegraph?(request)
+ request.params['performance_bar'] == 'flamegraph' && ::Gitlab::PerformanceBar.allowed_for_user?(request.env['warden']&.user)
+ end
+
+ def render_flamegraph(graph, request)
+ headers = { 'Content-Type' => 'text/html' }
+ path = request.env['PATH_INFO'].sub('//', '/')
+
+ speedscope_path = ::Gitlab::Utils.append_path(::Gitlab.config.gitlab.relative_url_root, '/-/speedscope/index.html')
+
+ html = <<~HTML
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <style>
+ body { margin: 0; height: 100vh; }
+ #speedscope-iframe { width: 100%; height: 100%; border: none; }
+ </style>
+ </head>
+ <body>
+ <script type="text/javascript" nonce="#{request.content_security_policy_nonce}">
+ var graph = #{Gitlab::Json.generate(graph)};
+ var json = JSON.stringify(graph);
+ var blob = new Blob([json], { type: 'text/plain' });
+ var objUrl = encodeURIComponent(URL.createObjectURL(blob));
+ var iframe = document.createElement('IFRAME');
+ iframe.setAttribute('id', 'speedscope-iframe');
+ document.body.appendChild(iframe);
+ var iframeUrl = '#{speedscope_path}#profileURL=' + objUrl + '&title=' + 'Flamegraph for #{CGI.escape(path)}';
+ iframe.setAttribute('src', iframeUrl);
+ </script>
+ </body>
+ </html>
+ HTML
+
+ [200, headers, [html]]
+ end
+ end
+ end
+end