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-12-22 21:07:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-22 21:07:08 +0300
commitb486760a6332905cd2ac94b3fade5cbc6a55d21e (patch)
tree0f1206f20aa3f1d49ddfee1418538c1777ef0957 /lib/gitlab/memory
parentaaf158bcb57386a043d8cb7dc491a2f306a4ac13 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/memory')
-rw-r--r--lib/gitlab/memory/reporter.rb30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/gitlab/memory/reporter.rb b/lib/gitlab/memory/reporter.rb
index 710c89c6216..5effafc9f5b 100644
--- a/lib/gitlab/memory/reporter.rb
+++ b/lib/gitlab/memory/reporter.rb
@@ -3,6 +3,8 @@
module Gitlab
module Memory
class Reporter
+ COMPRESS_CMD = %w[gzip --fast].freeze
+
attr_reader :reports_path
def initialize(reports_path: nil, logger: Gitlab::AppLogger)
@@ -67,29 +69,39 @@ module Gitlab
report_file = file_name(report)
tmp_file_path = File.join(tmp_dir, report_file)
+ write_heap_dump_file(report, tmp_file_path)
+
+ File.join(@reports_path, report_file).tap do |report_file_path|
+ FileUtils.mv(tmp_file_path, report_file_path)
+ end
+ end
+
+ def write_heap_dump_file(report, path)
io_r, io_w = IO.pipe
+ err_r, err_w = IO.pipe
pid = nil
- File.open(tmp_file_path, 'wb') do |file|
+ status = nil
+ File.open(path, 'wb') do |file|
extras = {
in: io_r,
out: file,
- err: $stderr
+ err: err_w
}
- pid = Process.spawn('gzip', '--fast', **extras)
+ pid = Process.spawn(*COMPRESS_CMD, **extras)
io_r.close
+ err_w.close
report.run(io_w)
io_w.close
- Process.waitpid(pid)
+ _, status = Process.wait2(pid)
end
- File.join(@reports_path, report_file).tap do |report_file_path|
- FileUtils.mv(tmp_file_path, report_file_path)
- end
+ errors = err_r.read&.strip
+ err_r.close
+ raise StandardError, "exit #{status.exitstatus}: #{errors}" if !status&.success? && errors.present?
ensure
- [io_r, io_w].each(&:close)
-
+ [io_r, io_w, err_r, err_w].each(&:close)
# Make sure we don't leave any running processes behind.
Gitlab::ProcessManagement.signal(pid, :KILL) if pid
end