Commit ebef26de authored by Thong Kuah's avatar Thong Kuah

Merge branch 'bw-graphql-timeout-plugin' into 'master'

GraphQL: Migrate from the TimeoutMiddleware to the Timeout plugin

See merge request gitlab-org/gitlab!26822
parents 2a303ef3 39f7cf75
...@@ -16,6 +16,7 @@ class GitlabSchema < GraphQL::Schema ...@@ -16,6 +16,7 @@ class GitlabSchema < GraphQL::Schema
use Gitlab::Graphql::CallsGitaly use Gitlab::Graphql::CallsGitaly
use Gitlab::Graphql::Connections use Gitlab::Graphql::Connections
use Gitlab::Graphql::GenericTracing use Gitlab::Graphql::GenericTracing
use Gitlab::Graphql::Timeout, max_seconds: Gitlab.config.gitlab.graphql_timeout
query_analyzer Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer.new query_analyzer Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer.new
query_analyzer Gitlab::Graphql::QueryAnalyzers::RecursionAnalyzer.new query_analyzer Gitlab::Graphql::QueryAnalyzers::RecursionAnalyzer.new
......
...@@ -5,7 +5,3 @@ GraphQL::Field.accepts_definitions(authorize: GraphQL::Define.assign_metadata_ke ...@@ -5,7 +5,3 @@ GraphQL::Field.accepts_definitions(authorize: GraphQL::Define.assign_metadata_ke
GraphQL::Schema::Object.accepts_definition(:authorize) GraphQL::Schema::Object.accepts_definition(:authorize)
GraphQL::Schema::Field.accepts_definition(:authorize) GraphQL::Schema::Field.accepts_definition(:authorize)
GitlabSchema.middleware << GraphQL::Schema::TimeoutMiddleware.new(max_seconds: Gitlab.config.gitlab.graphql_timeout) do |timeout_error, query|
Gitlab::GraphqlLogger.error(message: timeout_error.to_s, query: query.query_string, query_variables: query.provided_variables)
end
# frozen_string_literal: true
module Gitlab
module Graphql
class Timeout < GraphQL::Schema::Timeout
def handle_timeout(error, query)
Gitlab::GraphqlLogger.error(message: error.message, query: query.query_string, query_variables: query.provided_variables)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Graphql::Timeout do
it 'inherits from ' do
expect(described_class.superclass).to eq GraphQL::Schema::Timeout
end
it 'sends the error to our GraphQL logger' do
parent_type = double(graphql_name: 'parent_type')
field = double(graphql_name: 'field')
query = double(query_string: 'query_string', provided_variables: 'provided_variables')
error = GraphQL::Schema::Timeout::TimeoutError.new(parent_type, field)
expect(Gitlab::GraphqlLogger)
.to receive(:error)
.with(message: 'Timeout on parent_type.field', query: 'query_string', query_variables: 'provided_variables')
timeout = described_class.new(max_seconds: 30)
timeout.handle_timeout(error, query)
end
end
...@@ -11,11 +11,11 @@ describe 'GitlabSchema configurations' do ...@@ -11,11 +11,11 @@ describe 'GitlabSchema configurations' do
describe 'timeouts' do describe 'timeouts' do
context 'when timeout is reached' do context 'when timeout is reached' do
it 'shows an error' do it 'shows an error' do
Timecop.scale(50000000) do # ludicrously large number because the timeout has to happen before the query even begins allow_any_instance_of(Gitlab::Graphql::Timeout).to receive(:max_seconds).and_return(0)
subject
expect_graphql_errors_to_include /Timeout/ subject
end
expect_graphql_errors_to_include /Timeout/
end end
end end
end end
...@@ -140,7 +140,7 @@ describe 'GitlabSchema configurations' do ...@@ -140,7 +140,7 @@ describe 'GitlabSchema configurations' do
end end
it_behaves_like 'imposing query limits' do it_behaves_like 'imposing query limits' do
it "fails all queries when only one of the queries is too complex" do it 'fails all queries when only one of the queries is too complex' do
# The `project` query above has a complexity of 5 # The `project` query above has a complexity of 5
allow(GitlabSchema).to receive(:max_query_complexity).and_return 4 allow(GitlabSchema).to receive(:max_query_complexity).and_return 4
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment