Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKamil TrzciƄski <ayufan@ayufan.eu>2019-07-23 12:30:00 +0300
committerGrzegorz Bizon <grzegorz@gitlab.com>2019-07-23 12:30:00 +0300
commit3a4cb6d6759abbfd16e048413e8545d1d94e7d9e (patch)
treed6631643d70462ee38936708107bbedefbb5f45f /lib
parent5e102f17f0ef16d0fd1eff98b9229fea2bc1fec9 (diff)
Bring backward compatibility for request profiles
It seems that we missed the backward compatibility support for profiles in the existing folder. This commit also fixes some specs to be idempotent and work in a temporary directory which not always seems to be the case. This commit also brings the profile_spec.rb which seems to be missing.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/request_profiler.rb15
-rw-r--r--lib/gitlab/request_profiler/profile.rb29
2 files changed, 24 insertions, 20 deletions
diff --git a/lib/gitlab/request_profiler.rb b/lib/gitlab/request_profiler.rb
index 64593153686..033e451dbee 100644
--- a/lib/gitlab/request_profiler.rb
+++ b/lib/gitlab/request_profiler.rb
@@ -6,6 +6,21 @@ module Gitlab
module RequestProfiler
PROFILES_DIR = "#{Gitlab.config.shared.path}/tmp/requests_profiles".freeze
+ def all
+ Dir["#{PROFILES_DIR}/*.{html,txt}"].map do |path|
+ Profile.new(File.basename(path))
+ end.select(&:valid?)
+ end
+ module_function :all
+
+ def find(name)
+ file_path = File.join(PROFILES_DIR, name)
+ return unless File.exist?(file_path)
+
+ Profile.new(name)
+ end
+ module_function :find
+
def profile_token
Rails.cache.fetch('profile-token') do
Devise.friendly_token
diff --git a/lib/gitlab/request_profiler/profile.rb b/lib/gitlab/request_profiler/profile.rb
index 74f2ec1d083..76c675658b1 100644
--- a/lib/gitlab/request_profiler/profile.rb
+++ b/lib/gitlab/request_profiler/profile.rb
@@ -7,19 +7,6 @@ module Gitlab
alias_method :to_param, :name
- def self.all
- Dir["#{PROFILES_DIR}/*.{html,txt}"].map do |path|
- new(File.basename(path))
- end
- end
-
- def self.find(name)
- file_path = File.join(PROFILES_DIR, name)
- return unless File.exist?(file_path)
-
- new(name)
- end
-
def initialize(name)
@name = name
@file_path = File.join(PROFILES_DIR, name)
@@ -27,8 +14,8 @@ module Gitlab
set_attributes
end
- def content
- File.read("#{PROFILES_DIR}/#{name}")
+ def valid?
+ @request_path.present?
end
def content_type
@@ -43,11 +30,13 @@ module Gitlab
private
def set_attributes
- _, path, timestamp, profile_mode, type = name.split(/(.*)_(\d+)_(.*)\.(html|txt)$/)
- @request_path = path.tr('|', '/')
- @time = Time.at(timestamp.to_i).utc
- @profile_mode = profile_mode
- @type = type
+ matches = name.match(/^(?<path>.*)_(?<timestamp>\d+)(_(?<profile_mode>\w+))?\.(?<type>html|txt)$/)
+ return unless matches
+
+ @request_path = matches[:path].tr('|', '/')
+ @time = Time.at(matches[:timestamp].to_i).utc
+ @profile_mode = matches[:profile_mode] || 'unknown'
+ @type = matches[:type]
end
end
end