Allow to filter PG code suggestions by namespace path
What does this MR do and why?
This change introduces a new feature flag called use_ai_events_namespace_path_filter
that improves how the system finds and filters AI code suggestion events.
Previously, the system used a basic database query that looked up events by user IDs, which wasn't very efficient. The new approach uses a more sophisticated filtering method that can directly find events based on projects or groups using their namespace paths, making queries faster and more accurate.
When the feature flag is enabled, the system uses an optimized query builder that can handle large datasets more efficiently. When disabled, it falls back to the old method for safety during the transition period.
The change also updates the GraphQL API resolver to work with both filtering approaches and removes some error conditions that were previously blocking certain queries from working with projects and non-root groups.
References
related to #490601 (closed)
How to set up and validate locally
- Assign current user to a Duo Enterprise seat, or apply this diff:
diff --git a/ee/app/models/ee/user.rb b/ee/app/models/ee/user.rb
index 1d350dc8bfc8..7b106bc88650 100644
--- a/ee/app/models/ee/user.rb
+++ b/ee/app/models/ee/user.rb
@@ -526,6 +526,7 @@ def using_gitlab_com_seat?(namespace)
end
def assigned_to_duo_enterprise?(container)
+ return true
namespace = ::Gitlab::Saas.feature_available?(:gitlab_duo_saas_only) ? container.root_ancestor : nil
GitlabSubscriptions::AddOnPurchaseq
- Enable feature flag
echo "Feature.enable :use_ai_events_namespace_path_filter" | rails c
- Take two projects inside a group and run
PROJECT_ID=X FILTER=ai_usage_stats bundle exec rake db:seed_fu
for each - Run the following GraphQL query for each project and its parent group and check if results are filtered correctly
query {
project(fullPath: PROJECT_PATH) {
id
aiUsageData {
codeSuggestionEvents {
nodes {
event
suggestionSize
}
}
}
}
}
query {
group(fullPath: PARENT_GROUP_PATH) {
id
aiUsageData {
codeSuggestionEvents {
nodes {
event
suggestionSize
}
}
}
}
}
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.