diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 18:11:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 18:11:26 +0300 |
commit | 4e752429e6173020567f9509f1fa993cc82a258a (patch) | |
tree | 49648f91db0d7849065d2d8897757f7de815c773 /lib/gitlab/memory | |
parent | 255831389a5080bb61242b3b50426918c4e1a5aa (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/memory')
-rw-r--r-- | lib/gitlab/memory/jemalloc.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/memory/reports/jemalloc_stats.rb | 12 | ||||
-rw-r--r-- | lib/gitlab/memory/reports_daemon.rb | 19 |
3 files changed, 24 insertions, 11 deletions
diff --git a/lib/gitlab/memory/jemalloc.rb b/lib/gitlab/memory/jemalloc.rb index e20e186cab9..81c4be0f7fc 100644 --- a/lib/gitlab/memory/jemalloc.rb +++ b/lib/gitlab/memory/jemalloc.rb @@ -97,7 +97,9 @@ module Gitlab end def file_name(extension, filename_label) - [FILENAME_PREFIX, $$, filename_label, Time.current.to_i, extension].reject(&:blank?).join('.') + timestamp = Time.current.strftime('%Y-%m-%d.%H:%M:%S:%L') + + [FILENAME_PREFIX, timestamp, filename_label, extension].reject(&:blank?).join('.') end end end diff --git a/lib/gitlab/memory/reports/jemalloc_stats.rb b/lib/gitlab/memory/reports/jemalloc_stats.rb index 05f0717d7c3..720f22ddbe4 100644 --- a/lib/gitlab/memory/reports/jemalloc_stats.rb +++ b/lib/gitlab/memory/reports/jemalloc_stats.rb @@ -16,8 +16,9 @@ module Gitlab # The cleanup logic will be redundant after we'll implement the uploads, which would perform the cleanup. DEFAULT_MAX_REPORTS_STORED = 250 - def initialize(reports_path:) + def initialize(reports_path:, filename_label:) @reports_path = reports_path + @filename_label = filename_label # Store report in tmp subdir while it is still streaming. # This will clearly separate finished reports from the files we are still writing to. @@ -28,7 +29,8 @@ module Gitlab def run return unless active? - Gitlab::Memory::Jemalloc.dump_stats(path: reports_path, tmp_dir: @tmp_dir, filename_label: worker_id).tap do + Gitlab::Memory::Jemalloc.dump_stats(path: reports_path, tmp_dir: @tmp_dir, + filename_label: filename_label).tap do cleanup end end @@ -39,7 +41,7 @@ module Gitlab private - attr_reader :reports_path + attr_reader :reports_path, :filename_label def cleanup reports_files_modified_order[0...-max_reports_stored].each do |f| @@ -61,10 +63,6 @@ module Gitlab end end - def worker_id - ::Prometheus::PidProvider.worker_id - end - def max_reports_stored ENV["GITLAB_DIAGNOSTIC_REPORTS_JEMALLOC_MAX_REPORTS_STORED"] || DEFAULT_MAX_REPORTS_STORED end diff --git a/lib/gitlab/memory/reports_daemon.rb b/lib/gitlab/memory/reports_daemon.rb index 0dfc31235e7..7070c65c705 100644 --- a/lib/gitlab/memory/reports_daemon.rb +++ b/lib/gitlab/memory/reports_daemon.rb @@ -24,7 +24,15 @@ module Gitlab @reports_path = ENV["GITLAB_DIAGNOSTIC_REPORTS_PATH"] || DEFAULT_REPORTS_PATH - @reports = [Gitlab::Memory::Reports::JemallocStats.new(reports_path: reports_path)] + # Set unique uuid for every ReportsDaemon instance. + # Because we spawn a single instance of it per process, it will also uniquely identify the worker. + # Unlike `::Prometheus::PidProvider.worker_id`, this uuid will remain unique across all Puma clusters. + # This way, we can identify reports that were produced from the same worker process during its lifetime. + @worker_uuid = SecureRandom.uuid + + @reports = [ + Gitlab::Memory::Reports::JemallocStats.new(reports_path: reports_path, filename_label: filename_label) + ] init_prometheus_metrics end @@ -54,7 +62,11 @@ module Gitlab private - attr_reader :alive, :reports + attr_reader :alive, :reports, :worker_uuid + + def filename_label + [worker_id, worker_uuid].join(".") + end # Returns the sleep interval with a random adjustment. # The random adjustment is put in place to ensure continued availability. @@ -70,7 +82,8 @@ module Gitlab perf_report: label, duration_s: duration_s.round(2), cpu_s: cpu_s.round(2), - perf_report_size_bytes: size + perf_report_size_bytes: size, + perf_report_worker_uuid: worker_uuid ) end |