summaryrefslogtreecommitdiff
path: root/scripts/insert-rspec-profiling-data
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-07 17:19:56 -0800
committerStan Hu <stanhu@gmail.com>2019-03-09 07:12:35 -0800
commitedc0ed44a95a52b3b2d3e28cf572a4a6a9680ddc (patch)
treede21879f8a6e600b77d198f05d0c1f659334a238 /scripts/insert-rspec-profiling-data
parent5566809c977ad6d61b6f16aad6135e6980e26b1f (diff)
downloadgitlab-ce-sh-rspec-profile-batch-testing.tar.gz
Batch insert CI rspec_profiling datash-rspec-profile-batch-testing
Instead of inserting a row after each example to an external database, we save the CI profiling reports into the `rspec_profiling` directory and insert the data in one batch in the update-tests-metadata CI stage. This should make each spec run faster and also reduce the number of PostgreSQL connections needed by concurrent CI builds. Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/10154
Diffstat (limited to 'scripts/insert-rspec-profiling-data')
-rwxr-xr-xscripts/insert-rspec-profiling-data50
1 files changed, 50 insertions, 0 deletions
diff --git a/scripts/insert-rspec-profiling-data b/scripts/insert-rspec-profiling-data
new file mode 100755
index 00000000000..e1fb042d098
--- /dev/null
+++ b/scripts/insert-rspec-profiling-data
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+
+require 'csv'
+require 'rspec_profiling'
+
+module RspecProfiling
+ module Collectors
+ class PSQL
+ def establish_connection
+ Result.establish_connection(results_url)
+ end
+
+ def prepared?
+ connection.data_source_exists?(table)
+ end
+
+ def results_url
+ ENV['RSPEC_PROFILING_POSTGRES_URL']
+ 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")]
+
+ puts "#{Time.now} Detected #{files.count} files in rspec_profiling"
+
+ files.each do |filename|
+ csv_data = CSV.open(filename, headers: :first_row)
+ count = 0
+
+ puts "#{Time.now}: Inserting #{filename}..."
+
+ csv_data.each do |entry|
+ entry = entry.to_h.each_value { |x| x&.strip! }
+ collector.insert(entry)
+ count += 1
+ end
+
+ puts "#{Time.now}: Done inserting #{count} lines in #{filename}"
+ end
+end
+
+insert_data('rspec_profiling') if ENV['RSPEC_PROFILING_POSTGRES_URL'].present?