summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-09-07 11:15:27 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-11-02 18:11:44 +0100
commitf64085e6932ff128facdc361c340cb951214c1c6 (patch)
tree04e4572e2d77e2372ef73ffdfd257ff920ea083d /lib
parentaccc3a4517091f67ebaa61da2457e7165e7621d9 (diff)
downloadgitlab-ce-f64085e6932ff128facdc361c340cb951214c1c6.tar.gz
Move labels tests from Metrics rack spec to Transaction spec
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/rack_middleware.rb12
-rw-r--r--lib/gitlab/metrics/transaction.rb26
2 files changed, 19 insertions, 19 deletions
diff --git a/lib/gitlab/metrics/rack_middleware.rb b/lib/gitlab/metrics/rack_middleware.rb
index 11af1fb6322..a5aa0c49551 100644
--- a/lib/gitlab/metrics/rack_middleware.rb
+++ b/lib/gitlab/metrics/rack_middleware.rb
@@ -41,18 +41,6 @@ module Gitlab
def filtered_path(env)
ActionDispatch::Request.new(env).filtered_path.presence || env['REQUEST_URI']
end
-
- def endpoint_paths_cache
- @endpoint_paths_cache ||= Hash.new do |hash, http_method|
- hash[http_method] = Hash.new do |inner_hash, raw_path|
- inner_hash[raw_path] = endpoint_instrumentable_path(raw_path)
- end
- end
- end
-
- def endpoint_instrumentable_path(raw_path)
- raw_path.sub('(.:format)', '').sub('/:version', '')
- end
end
end
end
diff --git a/lib/gitlab/metrics/transaction.rb b/lib/gitlab/metrics/transaction.rb
index 91e9628606b..5bf8580d91f 100644
--- a/lib/gitlab/metrics/transaction.rb
+++ b/lib/gitlab/metrics/transaction.rb
@@ -55,7 +55,7 @@ module Gitlab
end
def action
- "#{labels[:controller]}##{labels[:action]}" if labels
+ "#{labels[:controller]}##{labels[:action]}" if labels && !labels.empty?
end
def labels
@@ -63,9 +63,9 @@ module Gitlab
# memoize transaction labels only source env variables were present
@labels = if @env[CONTROLLER_KEY]
- labels_from_controller(@env) || {}
+ labels_from_controller || {}
elsif @env[ENDPOINT_KEY]
- labels_from_endpoint(@env) || {}
+ labels_from_endpoint || {}
end
@labels || {}
@@ -199,8 +199,8 @@ module Gitlab
)
end
- def labels_from_controller(env)
- controller = env[CONTROLLER_KEY]
+ def labels_from_controller
+ controller = @env[CONTROLLER_KEY]
action = "#{controller.action_name}"
suffix = CONTENT_TYPES[controller.content_type]
@@ -212,8 +212,8 @@ module Gitlab
{ controller: controller.class.name, action: action }
end
- def labels_from_endpoint(env)
- endpoint = env[ENDPOINT_KEY]
+ def labels_from_endpoint
+ endpoint = @env[ENDPOINT_KEY]
begin
route = endpoint.route
@@ -228,6 +228,18 @@ module Gitlab
{ controller: 'Grape', action: "#{route.request_method} #{path}" }
end
end
+
+ def endpoint_paths_cache
+ @endpoint_paths_cache ||= Hash.new do |hash, http_method|
+ hash[http_method] = Hash.new do |inner_hash, raw_path|
+ inner_hash[raw_path] = endpoint_instrumentable_path(raw_path)
+ end
+ end
+ end
+
+ def endpoint_instrumentable_path(raw_path)
+ raw_path.sub('(.:format)', '').sub('/:version', '')
+ end
end
end
end