From 1f37aed1c917260eefda63a18d3a9af91c4a1abb Mon Sep 17 00:00:00 2001 From: charlieablett Date: Tue, 30 Apr 2019 20:30:15 +1200 Subject: New logfile for graphql queries Specify dedicated logfile and logger class for GraphQL queries. Move complexity analyzer to a dedicated class. --- spec/requests/api/graphql/gitlab_schema_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec/requests/api/graphql') diff --git a/spec/requests/api/graphql/gitlab_schema_spec.rb b/spec/requests/api/graphql/gitlab_schema_spec.rb index a724c5c3f1c..0eb026f1ed9 100644 --- a/spec/requests/api/graphql/gitlab_schema_spec.rb +++ b/spec/requests/api/graphql/gitlab_schema_spec.rb @@ -83,6 +83,16 @@ describe 'GitlabSchema configurations' do end end + context 'logging' do + it 'writes to the GraphQL log' do + expect(Gitlab::GraphqlLogger).to receive(:info).with(/Query Complexity/) + + query = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) + + post_graphql(query, current_user: nil) + end + end + context 'when IntrospectionQuery' do it 'is not too complex' do query = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) -- cgit v1.2.1 From 2a1006416748950805294793f1bc8d6fa7435eea Mon Sep 17 00:00:00 2001 From: charlieablett Date: Thu, 2 May 2019 19:09:10 +1200 Subject: Restructure complexity analyzer Remove instance variables for class re-use, test individual methods, use `monotonic_time` --- spec/requests/api/graphql/gitlab_schema_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/requests/api/graphql') diff --git a/spec/requests/api/graphql/gitlab_schema_spec.rb b/spec/requests/api/graphql/gitlab_schema_spec.rb index 0eb026f1ed9..dcce8c1dbad 100644 --- a/spec/requests/api/graphql/gitlab_schema_spec.rb +++ b/spec/requests/api/graphql/gitlab_schema_spec.rb @@ -85,7 +85,7 @@ describe 'GitlabSchema configurations' do context 'logging' do it 'writes to the GraphQL log' do - expect(Gitlab::GraphqlLogger).to receive(:info).with(/Query Complexity/) + expect(Gitlab::GraphqlLogger).to receive(:info) query = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) -- cgit v1.2.1 From 184a5120dc764d33cece108fbc85b0ec96f7c050 Mon Sep 17 00:00:00 2001 From: charlieablett Date: Wed, 22 May 2019 17:13:06 +1200 Subject: Call analyzers from LoggerAnalyzer - Add changelog file - Fix failing tests --- spec/requests/api/graphql/gitlab_schema_spec.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'spec/requests/api/graphql') diff --git a/spec/requests/api/graphql/gitlab_schema_spec.rb b/spec/requests/api/graphql/gitlab_schema_spec.rb index dcce8c1dbad..510dec5edb2 100644 --- a/spec/requests/api/graphql/gitlab_schema_spec.rb +++ b/spec/requests/api/graphql/gitlab_schema_spec.rb @@ -84,10 +84,18 @@ describe 'GitlabSchema configurations' do end context 'logging' do - it 'writes to the GraphQL log' do - expect(Gitlab::GraphqlLogger).to receive(:info) - - query = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) + let(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) } + + it 'logs the query complexity' do + analyzer_memo = { + query_string: query, + variables: {}, + complexity: 181, + depth: 0, + duration: "7ms" + } + expect_any_instance_of(Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer).to receive(:duration).and_return(7) + expect(Gitlab::GraphqlLogger).to receive(:info).with(analyzer_memo) post_graphql(query, current_user: nil) end -- cgit v1.2.1 From 699532232ca27e6079c553261e0ab1d17317472a Mon Sep 17 00:00:00 2001 From: charlie ablett Date: Thu, 23 May 2019 22:43:47 +0000 Subject: 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 --- spec/requests/api/graphql/gitlab_schema_spec.rb | 31 +++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'spec/requests/api/graphql') diff --git a/spec/requests/api/graphql/gitlab_schema_spec.rb b/spec/requests/api/graphql/gitlab_schema_spec.rb index 510dec5edb2..1017e409f6c 100644 --- a/spec/requests/api/graphql/gitlab_schema_spec.rb +++ b/spec/requests/api/graphql/gitlab_schema_spec.rb @@ -83,31 +83,38 @@ describe 'GitlabSchema configurations' do end end + context 'when IntrospectionQuery' do + it 'is not too complex' do + query = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) + + post_graphql(query, current_user: nil) + + expect(graphql_errors).to be_nil + end + end + context 'logging' do let(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) } - it 'logs the query complexity' do + it 'logs the query complexity and depth' do analyzer_memo = { - query_string: query, - variables: {}, - complexity: 181, - depth: 0, - duration: "7ms" + query_string: query, + variables: {}.to_s, + complexity: 181, + depth: 0, + duration: 7 } + expect_any_instance_of(Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer).to receive(:duration).and_return(7) expect(Gitlab::GraphqlLogger).to receive(:info).with(analyzer_memo) post_graphql(query, current_user: nil) end - end - context 'when IntrospectionQuery' do - it 'is not too complex' do - query = File.read(Rails.root.join('spec/fixtures/api/graphql/introspection.graphql')) + it 'logs using `format_message`' do + expect_any_instance_of(Gitlab::GraphqlLogger).to receive(:format_message) post_graphql(query, current_user: nil) - - expect(graphql_errors).to be_nil end end end -- cgit v1.2.1