diff options
author | charlieablett <cablett@gitlab.com> | 2019-05-22 08:13:06 +0300 |
---|---|---|
committer | charlieablett <cablett@gitlab.com> | 2019-05-30 09:27:28 +0300 |
commit | 184a5120dc764d33cece108fbc85b0ec96f7c050 (patch) | |
tree | bdf00d369d555a629d7f83d26fe8d0c719de449d /lib/gitlab/graphql | |
parent | b94a17e00efc89187aefd24d388e36584cd11784 (diff) |
Call analyzers from LoggerAnalyzer
- Add changelog file
- Fix failing tests
Diffstat (limited to 'lib/gitlab/graphql')
-rw-r--r-- | lib/gitlab/graphql/query_analyzers/logger_analyzer.rb | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb index e229e66849b..1e49c894ecb 100644 --- a/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb +++ b/lib/gitlab/graphql/query_analyzers/logger_analyzer.rb @@ -4,35 +4,27 @@ module Gitlab module Graphql module QueryAnalyzers class LoggerAnalyzer - # Called before initializing the analyzer. - # Returns true to run this analyzer, or false to skip it. def analyze?(query) Feature.enabled?(:graphql_logging, default_enabled: true) end - # Called before the visit. - # Returns the initial value for `memo` def initial_value(query) + analyzers = [complexity_analyzer, depth_analyzer] + complexity, depth = GraphQL::Analysis.analyze_query(query, analyzers) { time_started: Gitlab::Metrics::System.monotonic_time, query_string: query.query_string, variables: process_variables(query.provided_variables), - complexity: nil, - depth: nil, + complexity: complexity, + depth: depth, duration: nil } end - # This is like the `reduce` callback. - # The return value is passed to the next call as `memo` def call(memo, visit_type, irep_node) - memo = set_complexity(memo) - set_depth(memo) + memo end - # Called when we're done the whole visit. - # The return value may be a GraphQL::AnalysisError (or an array of them). - # Or, you can use this hook to write to a log, etc def final_value(memo) memo[:duration] = "#{duration(memo[:time_started]).round(1)}ms" GraphqlLogger.info(memo.except!(:time_started)) @@ -49,18 +41,16 @@ module Gitlab end end - def set_complexity(memo) + def complexity_analyzer GraphQL::Analysis::QueryComplexity.new do |query, complexity_value| - memo[:complexity] = complexity_value + complexity_value end - memo end - def set_depth(memo) + def depth_analyzer GraphQL::Analysis::QueryDepth.new do |query, depth_value| - memo[:depth] = depth_value + depth_value end - memo end def duration(time_started) |