summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2019-04-04 13:50:31 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2019-04-04 13:50:31 +0000
commit54de12b6959b7b07a870466b1cb24806adc00fa3 (patch)
treee831b2d81109f2b6ead9509f1ef5c97174e653b7 /lib
parent815901e322b60d28983f52a7ce5e98555285bef8 (diff)
parent435d98c9cee0d32305a6fd20995f41849749e8eb (diff)
downloadgitlab-ce-54de12b6959b7b07a870466b1cb24806adc00fa3.tar.gz
Merge branch 'jprovazn-graphql-prometheus' into 'master'
Monitor GraphQL with Prometheus (try 2) See merge request gitlab-org/gitlab-ce!26917
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/graphql/tracing.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/tracing.rb b/lib/gitlab/graphql/tracing.rb
new file mode 100644
index 00000000000..6b505e4262b
--- /dev/null
+++ b/lib/gitlab/graphql/tracing.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Graphql
+ class Tracing < GraphQL::Tracing::PlatformTracing
+ self.platform_keys = {
+ 'lex' => 'graphql.lex',
+ 'parse' => 'graphql.parse',
+ 'validate' => 'graphql.validate',
+ 'analyze_query' => 'graphql.analyze',
+ 'analyze_multiplex' => 'graphql.analyze',
+ 'execute_multiplex' => 'graphql.execute',
+ 'execute_query' => 'graphql.execute',
+ 'execute_query_lazy' => 'graphql.execute',
+ 'execute_field' => 'graphql.execute',
+ 'execute_field_lazy' => 'graphql.execute'
+ }
+
+ def platform_field_key(type, field)
+ "#{type.name}.#{field.name}"
+ end
+
+ def platform_trace(platform_key, key, data, &block)
+ start = Gitlab::Metrics::System.monotonic_time
+
+ yield
+ ensure
+ duration = Gitlab::Metrics::System.monotonic_time - start
+
+ graphql_duration_seconds.observe({ platform_key: platform_key, key: key }, duration)
+ end
+
+ private
+
+ def graphql_duration_seconds
+ @graphql_duration_seconds ||= Gitlab::Metrics.histogram(
+ :graphql_duration_seconds,
+ 'GraphQL execution time'
+ )
+ end
+ end
+ end
+end