diff --git a/Gemfile.lock b/Gemfile.lock index 21057c302..e72a25cae 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -242,7 +242,7 @@ GEM graphiql-rails (1.7.0) railties sprockets-rails - graphql (1.9.15) + graphql (1.9.16) graphql-batch (0.4.1) graphql (>= 1.3, < 2) promise.rb (~> 0.7.2) @@ -614,9 +614,9 @@ GEM rack (~> 2.0) rack-protection (= 2.0.5) tilt (~> 2.0) - skylight (3.1.2) - skylight-core (= 3.1.2) - skylight-core (3.1.2) + skylight (4.2.1) + skylight-core (= 4.2.1) + skylight-core (4.2.1) activesupport (>= 4.2.0) smart_listing (1.2.2) coffee-rails diff --git a/app/graphql/api/v2/schema.rb b/app/graphql/api/v2/schema.rb index 26089ef11..10b1bfa13 100644 --- a/app/graphql/api/v2/schema.rb +++ b/app/graphql/api/v2/schema.rb @@ -59,19 +59,29 @@ class Api::V2::Schema < GraphQL::Schema raise GraphQL::ExecutionError.new("An object of type #{error.type.graphql_name} was hidden due to permissions", extensions: { code: :unauthorized }) end - middleware(GraphQL::Schema::TimeoutMiddleware.new(max_seconds: 5) do |_, query| - Rails.logger.info("GraphQL Timeout: #{query.query_string}") - end) + use GraphQL::Execution::Interpreter + use GraphQL::Analysis::AST + use GraphQL::Schema::Timeout, max_seconds: 5 + use GraphQL::Batch + use GraphQL::Backtrace if Rails.env.development? - query_analyzer(GraphQL::Analysis::QueryComplexity.new do |_, complexity| - Rails.logger.info("[GraphQL Query Complexity] #{complexity}") - end) - query_analyzer(GraphQL::Analysis::QueryDepth.new do |_, depth| - Rails.logger.info("[GraphQL Query Depth] #{depth}") - end) - end + class LogQueryDepth < GraphQL::Analysis::AST::QueryDepth + def result + Rails.logger.info("[GraphQL Query Depth] #{super}") + end + end - use GraphQL::Batch - use GraphQL::Tracing::SkylightTracing + class LogQueryComplexity < GraphQL::Analysis::AST::QueryComplexity + def result + Rails.logger.info("[GraphQL Query Complexity] #{super}") + end + end + + query_analyzer(LogQueryComplexity) + query_analyzer(LogQueryDepth) + else + query_analyzer(GraphQL::Analysis::AST::MaxQueryComplexity) + query_analyzer(GraphQL::Analysis::AST::MaxQueryDepth) + end end diff --git a/config/application.rb b/config/application.rb index 65080acaf..be10d163e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -49,5 +49,7 @@ module TPS debounce_delay: 3000, status_visible_duration: 6000 } + + config.skylight.probes += [:graphql] end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index dffb9d849..990c55961 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -21,6 +21,7 @@ describe ApplicationController, type: :controller do let(:payload) { {} } before do + allow(@controller).to receive(:content_type).and_return('') allow(@controller).to receive(:current_user).and_return(current_user) expect(@controller).to receive(:current_instructeur).and_return(current_instructeur) expect(@controller).to receive(:current_administrateur).and_return(current_administrateur) @@ -42,6 +43,8 @@ describe ApplicationController, type: :controller do payload.delete(key) end expect(payload).to eq({ + sk_rendered_format: nil, + sk_variant: [], user_agent: 'Rails Testing', user_roles: 'Guest' }) @@ -61,6 +64,8 @@ describe ApplicationController, type: :controller do payload.delete(key) end expect(payload).to eq({ + sk_rendered_format: nil, + sk_variant: [], user_agent: 'Rails Testing', user_id: current_user.id, user_email: current_user.email, @@ -85,6 +90,8 @@ describe ApplicationController, type: :controller do payload.delete(key) end expect(payload).to eq({ + sk_rendered_format: nil, + sk_variant: [], user_agent: 'Rails Testing', user_id: current_user.id, user_email: current_user.email, diff --git a/spec/controllers/manager/application_controller_spec.rb b/spec/controllers/manager/application_controller_spec.rb index 3af6744c7..45d8d995f 100644 --- a/spec/controllers/manager/application_controller_spec.rb +++ b/spec/controllers/manager/application_controller_spec.rb @@ -4,6 +4,7 @@ describe Manager::ApplicationController, type: :controller do let(:payload) { {} } before do + allow(@controller).to receive(:content_type).and_return('') allow(@controller).to receive(:current_user).and_return(current_user) @controller.send(:append_info_to_payload, payload) end @@ -13,6 +14,8 @@ describe Manager::ApplicationController, type: :controller do payload.delete(key) end expect(payload).to eq({ + sk_rendered_format: nil, + sk_variant: [], user_agent: 'Rails Testing', user_id: current_user.id, user_email: current_user.email