Commit 2c10a884 authored by Mehmet Emin INAC's avatar Mehmet Emin INAC Committed by Igor Drozdov

Merge graphql logs with application(controller) logs

parent 53488ad0
...@@ -113,6 +113,12 @@ class GraphqlController < ApplicationController ...@@ -113,6 +113,12 @@ class GraphqlController < ApplicationController
# Merging to :metadata will ensure these are logged as top level keys # Merging to :metadata will ensure these are logged as top level keys
payload[:metadata] ||= {} payload[:metadata] ||= {}
payload[:metadata].merge!(graphql: { operation_name: params[:operationName] }) payload[:metadata].merge!(graphql: logs)
end
def logs
RequestStore.store[:graphql_logs].to_h
.except(:duration_s, :query_string)
.merge(operation_name: params[:operationName])
end end
end end
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
end end
def call(memo, visit_type, irep_node) def call(memo, visit_type, irep_node)
memo RequestStore.store[:graphql_logs] = memo
end end
def final_value(memo) def final_value(memo)
...@@ -35,6 +35,8 @@ module Gitlab ...@@ -35,6 +35,8 @@ module Gitlab
memo[:depth] = depth memo[:depth] = depth
memo[:complexity] = complexity memo[:complexity] = complexity
# This duration is not the execution time of the
# query but the execution time of the analyzer.
memo[:duration_s] = duration(memo[:time_started]).round(1) memo[:duration_s] = duration(memo[:time_started]).round(1)
memo[:used_fields] = field_usages.first memo[:used_fields] = field_usages.first
memo[:used_deprecated_fields] = field_usages.second memo[:used_deprecated_fields] = field_usages.second
......
...@@ -150,9 +150,11 @@ RSpec.describe GraphqlController do ...@@ -150,9 +150,11 @@ RSpec.describe GraphqlController do
describe '#append_info_to_payload' do describe '#append_info_to_payload' do
let(:graphql_query) { graphql_query_for('project', { 'fullPath' => 'foo' }, %w(id name)) } let(:graphql_query) { graphql_query_for('project', { 'fullPath' => 'foo' }, %w(id name)) }
let(:mock_store) { { graphql_logs: { foo: :bar } } }
let(:log_payload) { {} } let(:log_payload) { {} }
before do before do
allow(RequestStore).to receive(:store).and_return(mock_store)
allow(controller).to receive(:append_info_to_payload).and_wrap_original do |method, *| allow(controller).to receive(:append_info_to_payload).and_wrap_original do |method, *|
method.call(log_payload) method.call(log_payload)
end end
...@@ -162,7 +164,7 @@ RSpec.describe GraphqlController do ...@@ -162,7 +164,7 @@ RSpec.describe GraphqlController do
post :execute, params: { query: graphql_query, operationName: 'Foo' } post :execute, params: { query: graphql_query, operationName: 'Foo' }
expect(controller).to have_received(:append_info_to_payload) expect(controller).to have_received(:append_info_to_payload)
expect(log_payload.dig(:metadata, :graphql, :operation_name)).to eq('Foo') expect(log_payload.dig(:metadata, :graphql)).to eq({ operation_name: 'Foo', foo: :bar })
end end
end end
end end
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