summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcharlieablett <cablett@gitlab.com>2019-06-28 13:24:47 +1200
committercharlieablett <cablett@gitlab.com>2019-07-03 22:53:13 +1200
commitcf1b0d10bcdde69f05695a2e9a0d380c6badb6d1 (patch)
tree9bcc0d99dc22a2f4fa2601f1b904c7a418766616 /lib
parenta11fe5de4408595cc8b2b091cbbb76e423c98f34 (diff)
downloadgitlab-ce-cf1b0d10bcdde69f05695a2e9a0d380c6badb6d1.tar.gz
Address reviewer comments
- Add 1 for all fields that call Gitaly (with resolvers or without) - Clarify comment regarding Gitaly call alert - Expose predicate `calls_gitaly?` instead of ivar
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/graphql/calls_gitaly/instrumentation.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/gitlab/graphql/calls_gitaly/instrumentation.rb b/lib/gitlab/graphql/calls_gitaly/instrumentation.rb
index 08e98028755..e2733a1416f 100644
--- a/lib/gitlab/graphql/calls_gitaly/instrumentation.rb
+++ b/lib/gitlab/graphql/calls_gitaly/instrumentation.rb
@@ -7,7 +7,7 @@ module Gitlab
# Check if any `calls_gitaly: true` declarations need to be added
def instrument(_type, field)
type_object = field.metadata[:type_class]
- return field unless type_object && type_object.respond_to?(:calls_gitaly_check)
+ return field unless type_object && type_object.respond_to?(:calls_gitaly?)
old_resolver_proc = field.resolve_proc
@@ -15,16 +15,24 @@ module Gitlab
previous_gitaly_call_count = Gitlab::GitalyClient.get_request_count
result = old_resolver_proc.call(typed_object, args, ctx)
current_gitaly_call_count = Gitlab::GitalyClient.get_request_count
- type_object.calls_gitaly_check(current_gitaly_call_count - previous_gitaly_call_count)
+ calls_gitaly_check(type_object, current_gitaly_call_count - previous_gitaly_call_count)
result
- rescue => e
- ap "#{e.message}"
end
field.redefine do
resolve(gitaly_wrapped_resolve)
end
end
+
+ def calls_gitaly_check(type_object, calls)
+ return if type_object.calls_gitaly?
+ return if calls < 1
+
+ # Will inform you if there needs to be `calls_gitaly: true` as a kwarg in the field declaration
+ # if there is at least 1 Gitaly call involved with the field resolution.
+ error = RuntimeError.new("Gitaly is called for field '#{type_object.name}' on #{type_object.owner.try(:name)} - please add `calls_gitaly: true` to the field declaration")
+ Gitlab::Sentry.track_exception(error)
+ end
end
end
end