Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcharlie ablett <cablett@gitlab.com>2019-05-24 01:43:47 +0300
committercharlieablett <cablett@gitlab.com>2019-05-31 10:57:02 +0300
commit699532232ca27e6079c553261e0ab1d17317472a (patch)
tree47c7e56de28ba1857add8ea13627de07936e117e /lib/gitlab/graphql
parent5f0c230a18b677bd4ec6a4a54085775b0c69a498 (diff)
Apply reviewer feedback
- Comply doc with guidelines - Improve tests for readability and completeness - Separate out phases visually with newlines - Add `format_message` test - test readability - code and test structure/styling - static query analyzers - call `as_json` on `provided_variables` - add exception handling
Diffstat (limited to 'lib/gitlab/graphql')
-rw-r--r--lib/gitlab/graphql/query_analyzers/logger_analyzer.rb48
1 files changed, 27 insertions, 21 deletions
diff --git a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
index 8119d232124..01b55a1667f 100644
--- a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
+++ b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb
@@ -4,18 +4,22 @@ module Gitlab
module Graphql
module QueryAnalyzers
class LoggerAnalyzer
+ COMPLEXITY_ANALYZER = GraphQL::Analysis::QueryComplexity.new { |query, complexity_value| complexity_value }
+ DEPTH_ANALYZER = GraphQL::Analysis::QueryDepth.new { |query, depth_value| depth_value }
+
def analyze?(query)
Feature.enabled?(:graphql_logging, default_enabled: true)
end
def initial_value(query)
- {
- time_started: Gitlab::Metrics::System.monotonic_time,
+ variables = process_variables(query.provided_variables)
+ default_initial_values(query).merge({
query_string: query.query_string,
- query: query,
- variables: process_variables(query.provided_variables),
- duration: nil
- }
+ variables: variables
+ })
+ rescue => e
+ Gitlab::Sentry.track_exception(e)
+ default_initial_values(query)
end
def call(memo, visit_type, irep_node)
@@ -23,7 +27,9 @@ module Gitlab
end
def final_value(memo)
- analyzers = [complexity_analyzer, depth_analyzer]
+ return if memo.nil?
+
+ analyzers = [COMPLEXITY_ANALYZER, DEPTH_ANALYZER]
complexity, depth = GraphQL::Analysis.analyze_query(memo[:query], analyzers)
memo[:depth] = depth
@@ -31,34 +37,34 @@ module Gitlab
memo[:duration] = duration(memo[:time_started]).round(1)
GraphqlLogger.info(memo.except!(:time_started, :query))
+ rescue => e
+ Gitlab::Sentry.track_exception(e)
end
private
def process_variables(variables)
- if variables.respond_to?(:to_json)
- variables.to_json
+ if variables.respond_to?(:to_s)
+ variables.to_s
else
variables
end
end
- def complexity_analyzer
- GraphQL::Analysis::QueryComplexity.new do |query, complexity_value|
- complexity_value
- end
- end
-
- def depth_analyzer
- GraphQL::Analysis::QueryDepth.new do |query, depth_value|
- depth_value
- end
- end
-
def duration(time_started)
nanoseconds = Gitlab::Metrics::System.monotonic_time - time_started
nanoseconds * 1000000
end
+
+ def default_initial_values(query)
+ {
+ time_started: Gitlab::Metrics::System.monotonic_time,
+ query_string: nil,
+ query: query,
+ variables: nil,
+ duration: nil
+ }
+ end
end
end
end