blob: a19fe15dcb96855bebfb459a30f1f39af3e9c48c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'fog/google'
require_relative '../lib/gitlab/memory/reports_uploader'
require_relative '../lib/gitlab/memory/upload_and_cleanup_reports'
require_relative '../lib/gitlab/memory/diagnostic_reports_logger'
# Fail fast if the necessary ENV vars are not set.
reports_path = ENV["GITLAB_DIAGNOSTIC_REPORTS_PATH"].to_s
raise 'GITLAB_DIAGNOSTIC_REPORTS_PATH dir is missing' unless Dir.exist?(reports_path)
gcs_key = ENV["GITLAB_GCP_KEY_PATH"].to_s
raise "GCS keyfile not found: #{gcs_key}" unless File.exist?(gcs_key)
gcs_project = ENV["GITLAB_DIAGNOSTIC_REPORTS_PROJECT"].to_s
raise 'GITLAB_DIAGNOSTIC_REPORTS_PROJECT is missing' unless gcs_project && !gcs_project.empty?
gcs_bucket = ENV["GITLAB_DIAGNOSTIC_REPORTS_BUCKET"].to_s
raise 'GITLAB_DIAGNOSTIC_REPORTS_BUCKET is missing' unless gcs_bucket && !gcs_bucket.empty?
rails_root = File.expand_path("..", __dir__)
log_file = File.expand_path('log/diagnostic_reports_json.log', rails_root)
logger = Gitlab::Memory::DiagnosticReportsLogger.new(log_file)
uploader = Gitlab::Memory::ReportsUploader.new(gcs_key: gcs_key, gcs_project: gcs_project, gcs_bucket: gcs_bucket,
logger: logger)
Gitlab::Memory::UploadAndCleanupReports.new(uploader: uploader, reports_path: reports_path, logger: logger).call
|