Class: Gitlab::Memory::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/memory/reporter.rb

Constant Summary collapse

COMPRESS_CMD =
%w[gzip --fast].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reports_path: nil, logger: Gitlab::AppLogger) ⇒ Reporter

Returns a new instance of Reporter.



10
11
12
13
14
15
16
17
18
# File 'lib/gitlab/memory/reporter.rb', line 10

def initialize(reports_path: nil, logger: Gitlab::AppLogger)
  @reports_path = reports_path || ENV["GITLAB_DIAGNOSTIC_REPORTS_PATH"] || Dir.mktmpdir
  @logger = logger

  @worker_id = ::Prometheus::PidProvider.worker_id
  @worker_uuid = SecureRandom.uuid

  init_prometheus_metrics
end

Instance Attribute Details

#reports_pathObject (readonly)

Returns the value of attribute reports_path.



8
9
10
# File 'lib/gitlab/memory/reporter.rb', line 8

def reports_path
  @reports_path
end

Instance Method Details

#run_report(report) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/gitlab/memory/reporter.rb', line 20

def run_report(report)
  return false unless report.active?

  @logger.info(
    log_labels(
      message: 'started',
      perf_report: report.name
    ))

  start_monotonic_time = Gitlab::Metrics::System.monotonic_time
  start_thread_cpu_time = Gitlab::Metrics::System.thread_cpu_time

  report_file = store_report(report)

  cpu_s = Gitlab::Metrics::System.thread_cpu_duration(start_thread_cpu_time)
  duration_s = Gitlab::Metrics::System.monotonic_time - start_monotonic_time

  @logger.info(
    log_labels(
      message: 'finished',
      perf_report: report.name,
      cpu_s: cpu_s.round(2),
      duration_s: duration_s.round(2),
      perf_report_file: report_file,
      perf_report_size_bytes: file_size(report_file)
    ))

  @report_duration_counter.increment({ report: report.name }, duration_s)

  true
rescue StandardError => e
  @logger.error(
    log_labels(
      message: 'failed',
      perf_report: report.name,
      error: e.inspect
    ))

  false
end