Skip to content
代码片段 群组 项目
未验证 提交 622c940b 编辑于 作者: Tetiana Chupryna's avatar Tetiana Chupryna 提交者: GitLab
浏览文件

Merge branch 'log-graphql-request-with-expanded_ai_logging' into 'master'

Log GraphQL request with expanded_ai_logging feature flag

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/175074



Merged-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Approved-by: default avatarGosia Ksionek <mksionek@gitlab.com>
Approved-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Reviewed-by: default avatarGosia Ksionek <mksionek@gitlab.com>
Co-authored-by: default avatarShinya Maeda <shinya@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -5,6 +5,8 @@ module Ai
class Action < BaseMutation
graphql_name 'AiAction'
include ::Gitlab::Llm::Concerns::Logger
MUTUALLY_EXCLUSIVE_ARGUMENTS_ERROR = 'Only one method argument is required'
::Gitlab::Llm::Utils::AiFeaturesCatalogue.external.each_key do |method|
......@@ -47,9 +49,36 @@ def ready?(**args)
super
end
# rubocop:disable GraphQL/GraphqlName -- This is unrelated to GraphQL schema.
class UnsafeSanitizedPrinter < GraphQL::Language::SanitizedPrinter
def redact_argument_value?(...)
false
end
end
# rubocop:enable GraphQL/GraphqlName
def sanitized_query_string
return unless Feature.enabled?(:expanded_ai_logging, current_user)
# rubocop:disable GitlabSecurity/PublicSend -- Workaround for the GraphQL Ruby gem.
context.query.send(:with_prepared_ast) do
UnsafeSanitizedPrinter.new(context.query, inline_variables: true).sanitized_query_string
end
# rubocop:enable GitlabSecurity/PublicSend
end
def resolve(**attributes)
verify_rate_limit!
log_conditional_info(
current_user,
message: "Received AiAction mutation GraphQL query",
event_name: 'ai_action_mutation',
ai_component: 'abstraction_layer',
user_id: current_user.id,
graphql_query: sanitized_query_string
)
resource_id, method, options = extract_method_params!(attributes)
check_feature_flag_enabled!(method)
......
......@@ -46,7 +46,8 @@ module Logger
Attribute.new(:event_type, String),
Attribute.new(:error_type, String),
Attribute.new(:fragment, String),
Attribute.new(:ai_response_server, String)
Attribute.new(:ai_response_server, String),
Attribute.new(:graphql_query, String)
].freeze
def self.included(base)
......
......@@ -21,6 +21,36 @@
include_context 'with ai features enabled for group'
it 'logs expanded GraphQL mutation request' do
expect_next_instance_of(Mutations::Ai::Action) do |mutation|
expect(mutation).to receive(:log_conditional_info).with(
instance_of(User),
hash_including(graphql_query: instance_of(String))
)
end
post_graphql_mutation(mutation, current_user: current_user)
end
context 'when expanded_ai_logging feature flag is disabled' do
before do
stub_feature_flags(expanded_ai_logging: false)
end
it 'does not log expanded GraphQL mutation request' do
expect_next_instance_of(Mutations::Ai::Action) do |mutation|
expect(mutation).to receive(:log_conditional_info).with(
instance_of(User),
hash_including(graphql_query: nil)
)
end
expect(Mutations::Ai::Action::UnsafeSanitizedPrinter).not_to receive(:new)
post_graphql_mutation(mutation, current_user: current_user)
end
end
context 'when resource is nil' do
let(:resource) { nil }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册