diff options
author | Rémy Coutable <remy@rymai.me> | 2019-03-12 09:51:38 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2019-03-12 09:51:38 +0000 |
commit | 1c931c214e0fdcb53622dcb54fc12a307d1ed97d (patch) | |
tree | 992eee7e969a04dce7769c9338f280b35de282dd /scripts/insert-rspec-profiling-data | |
parent | 32056fc7b282d1fd14e62939e721c7935492ec8f (diff) | |
parent | f11030173b909c64aa23ce7482af8fcee8554be9 (diff) | |
download | gitlab-ce-1c931c214e0fdcb53622dcb54fc12a307d1ed97d.tar.gz |
Merge branch 'sh-store-rspec-profiling-csv' into 'master'
Batch insert CI profiling spec data
Closes gitlab-ee#10154
See merge request gitlab-org/gitlab-ce!25937
Diffstat (limited to 'scripts/insert-rspec-profiling-data')
-rwxr-xr-x | scripts/insert-rspec-profiling-data | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/insert-rspec-profiling-data b/scripts/insert-rspec-profiling-data new file mode 100755 index 00000000000..10e337b9972 --- /dev/null +++ b/scripts/insert-rspec-profiling-data @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +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. + Result.establish_connection(results_url) + end + + def prepared? + connection.data_source_exists?(table) + end + + def results_url + ENV['RSPEC_PROFILING_POSTGRES_URL'] + end + + class Result < ActiveRecord::Base + 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}..." + 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 + +insert_data('rspec_profiling') if ENV['RSPEC_PROFILING_POSTGRES_URL'].present? |