debian-mirror-gitlab/scripts/insert-rspec-profiling-data

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2019-07-07 11:18:12 +05:30
#!/usr/bin/env ruby
2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
require 'csv'
require 'rspec_profiling'
require 'postgres-copy'
module RspecProfiling
module Collectors
class PSQL
def establish_connection
# This disables the automatic creation of the database and
# table. In the future, we may want a way to specify the host of
# the database to connect so that we can call #install.
2022-03-02 08:16:31 +05:30
Result.establish_connection(results_url) # rubocop: disable Database/EstablishConnection
2019-07-07 11:18:12 +05:30
end
def results_url
ENV['RSPEC_PROFILING_POSTGRES_URL']
end
class Result < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
acts_as_copy_target
end
end
end
end
def insert_data(path)
puts "#{Time.now} Inserting CI stats..."
collector = RspecProfiling::Collectors::PSQL.new
collector.install
files = Dir[File.join(path, "*.csv")]
files.each do |filename|
puts "#{Time.now} Inserting #{filename}..."
2020-03-13 15:44:24 +05:30
# Strip file of NULL bytes to ensure data gets inserted
system("sed", "-i", "-e", "s/\\x00//g", filename)
2019-07-07 11:18:12 +05:30
result = RspecProfiling::Collectors::PSQL::Result.copy_from(filename)
puts "#{Time.now} Inserted #{result.cmd_tuples} lines in #{filename}, DB response: #{result.cmd_status}"
end
end
2022-04-04 11:22:00 +05:30
insert_data(ENV['RSPEC_PROFILING_FOLDER_PATH']) if ENV['RSPEC_PROFILING_POSTGRES_URL'].present?