Merge pull request #8637 from tchak/revert-graphql-trace

Revert "Merge pull request #8635 from tchak/graphql-with-traces"
This commit is contained in:
Paul Chavard 2023-02-16 10:14:29 +01:00 committed by GitHub
commit de11d97df9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,10 @@
class API::V2::GraphqlController < API::V2::BaseController
def execute
result = tracing? ? instrumented { perform_query } : perform_query
result = API::V2::Schema.execute(query,
variables: variables,
context: context,
operation_name: params[:operationName])
render json: result
rescue GraphQL::ParseError, JSON::ParserError => exception
handle_parse_error(exception)
@ -14,13 +18,6 @@ class API::V2::GraphqlController < API::V2::BaseController
private
def perform_query
API::V2::Schema.execute(query,
variables: variables,
context: context,
operation_name: params[:operationName])
end
def append_info_to_payload(payload)
super
@ -127,27 +124,4 @@ class API::V2::GraphqlController < API::V2::BaseController
data: nil
}, status: 500
end
def tracing?
params[:tracing].present? && (Rails.env.development? || manager?)
end
def manager?
administrateur_signed_in? && AdministrateursProcedure.exists?(administrateur: current_administrateur, manager: true)
end
def instrumented
events = []
ActiveSupport::Notifications.subscribed(-> (_name, start, finish, _id, payload) { events << { start: Time.zone.at(start), duration: (finish - start) * 1000, sql: payload[:sql] } }, "sql.active_record", monotonic: true) do
result = yield
result.merge(extensions: {
tracing: {
startTime: events.first[:start],
endTime: events.last[:start],
duration: events.sum { _1[:duration] },
events: events.sort_by { _1[:duration] }.reverse
}
})
end
end
end