diff options
author | charlieablett <cablett@gitlab.com> | 2019-06-21 16:20:00 +0200 |
---|---|---|
committer | charlieablett <cablett@gitlab.com> | 2019-07-03 22:53:13 +1200 |
commit | f4890d90782ad42a802b89c2a17c83bf9fb9d123 (patch) | |
tree | 233421eff8ec110cc16b1dcb9b50bedccb044e76 /lib/gitlab/graphql/calls_gitaly | |
parent | c99c30fdd6f3adf4fb29aad4b10e265be69d2d67 (diff) | |
download | gitlab-ce-f4890d90782ad42a802b89c2a17c83bf9fb9d123.tar.gz |
Alert if `calls_gitaly` declaration missing
- Move `calls_gitaly_check` to public
- Add instrumentation for flagging missing CallsGitaly declarations
- Wrap resolver proc in before-and-after Gitaly counts to get the net
Gitaly call count for the resolver.
Diffstat (limited to 'lib/gitlab/graphql/calls_gitaly')
-rw-r--r-- | lib/gitlab/graphql/calls_gitaly/instrumentation.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/calls_gitaly/instrumentation.rb b/lib/gitlab/graphql/calls_gitaly/instrumentation.rb new file mode 100644 index 00000000000..ca54e12c049 --- /dev/null +++ b/lib/gitlab/graphql/calls_gitaly/instrumentation.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Gitlab + module Graphql + module CallsGitaly + class Instrumentation + # 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) + + old_resolver_proc = field.resolve_proc + wrapped_proc = gitaly_wrapped_resolve(old_resolver_proc, type_object) + field.redefine { resolve(wrapped_proc) } + end + + def gitaly_wrapped_resolve(old_resolver_proc, type_object) + proc do |parent_typed_object, args, ctx| + previous_gitaly_call_count = Gitlab::GitalyClient.get_request_count + + old_resolver_proc.call(parent_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) + end + end + end + end + end +end |