Commit 2208f4fa authored by Andreas Brandl's avatar Andreas Brandl
Browse files

Add another counter to calculate method call ratio

We should see the ratio drop down when enabling the Feature.

Recommendation by @andrewn
parent b7d76186f413
...@@ -33,6 +33,8 @@ module Routable ...@@ -33,6 +33,8 @@ module Routable
# #
# Returns a single object, or nil. # Returns a single object, or nil.
def find_by_full_path(path, follow_redirects: false) def find_by_full_path(path, follow_redirects: false)
increment_counter(:routable_find_by_full_path, 'Number of calls to Routable.find_by_full_path')
if Feature.enabled?(:routable_two_step_lookup) if Feature.enabled?(:routable_two_step_lookup)
# Case sensitive match first (it's cheaper and the usual case) # Case sensitive match first (it's cheaper and the usual case)
# If we didn't have an exact match, we perform a case insensitive search # If we didn't have an exact match, we perform a case insensitive search
...@@ -59,7 +61,7 @@ def find_by_full_path(path, follow_redirects: false) ...@@ -59,7 +61,7 @@ def find_by_full_path(path, follow_redirects: false)
def where_full_path_in(paths) def where_full_path_in(paths)
return none if paths.empty? return none if paths.empty?
increment_full_path_in_counter increment_counter(:routable_where_full_path_in, 'Number of calls to Routable.where_full_path_in')
wheres = paths.map do |path| wheres = paths.map do |path|
"(LOWER(routes.path) = LOWER(#{connection.quote(path)}))" "(LOWER(routes.path) = LOWER(#{connection.quote(path)}))"
...@@ -68,11 +70,11 @@ def where_full_path_in(paths) ...@@ -68,11 +70,11 @@ def where_full_path_in(paths)
joins(:route).where(wheres.join(' OR ')) joins(:route).where(wheres.join(' OR '))
end end
# Temporary instrumentation of method calls for .where_full_path_in # Temporary instrumentation of method calls
def increment_full_path_in_counter def increment_counter(counter, description)
@counter ||= Gitlab::Metrics.counter(:routable_caseinsensitive_lookup_calls, 'Number of calls to Routable.where_full_path_in') @counters[counter] ||= Gitlab::Metrics.counter(counter, description)
@counter.increment @counters[counter].increment
rescue rescue
# ignore the error # ignore the error
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment