diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/lib/gitlab/graphql/tracers/logger_tracer_spec.rb | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/lib/gitlab/graphql/tracers/logger_tracer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/graphql/tracers/logger_tracer_spec.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/lib/gitlab/graphql/tracers/logger_tracer_spec.rb b/spec/lib/gitlab/graphql/tracers/logger_tracer_spec.rb new file mode 100644 index 00000000000..d83ac4dabc5 --- /dev/null +++ b/spec/lib/gitlab/graphql/tracers/logger_tracer_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true +require "fast_spec_helper" +require "support/graphql/fake_query_type" + +RSpec.describe Gitlab::Graphql::Tracers::LoggerTracer do + let(:dummy_schema) do + Class.new(GraphQL::Schema) do + # LoggerTracer depends on TimerTracer + use Gitlab::Graphql::Tracers::LoggerTracer + use Gitlab::Graphql::Tracers::TimerTracer + + query_analyzer Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer.new + + query Graphql::FakeQueryType + end + end + + around do |example| + Gitlab::ApplicationContext.with_context(caller_id: 'caller_a', feature_category: 'feature_a') do + example.run + end + end + + it "logs every query", :aggregate_failures do + variables = { name: "Ada Lovelace" } + query_string = 'query fooOperation($name: String) { helloWorld(message: $name) }' + + # Build an actual query so we don't have to hardocde the "fingerprint" calculations + query = GraphQL::Query.new(dummy_schema, query_string, variables: variables) + + expect(::Gitlab::GraphqlLogger).to receive(:info).with({ + "correlation_id" => anything, + "meta.caller_id" => "caller_a", + "meta.feature_category" => "feature_a", + "query_analysis.duration_s" => kind_of(Numeric), + "query_analysis.complexity" => 1, + "query_analysis.depth" => 1, + "query_analysis.used_deprecated_fields" => [], + "query_analysis.used_fields" => ["FakeQuery.helloWorld"], + duration_s: be > 0, + is_mutation: false, + operation_fingerprint: query.operation_fingerprint, + operation_name: 'fooOperation', + query_fingerprint: query.fingerprint, + query_string: query_string, + trace_type: "execute_query", + variables: variables.to_s + }) + + dummy_schema.execute(query_string, variables: variables) + end +end |