Allow to filter ClickHouse AI metrics by namespace path
What does this MR do and why?
This change adds a new filtering feature for AI analytics services that allows filtering data by namespace. The main improvements include:
-
New filtering capability: Added a feature flag called
use_ai_events_namespace_path_filterthat enables filtering AI usage data by specific namespaces/projects instead of looking at all data globally. -
Query modifications: Updated database queries in multiple analytics services to include namespace path filtering when the feature flag is enabled. This means the system can now show AI usage statistics for specific organizations or projects rather than everything mixed together.
-
Backward compatibility: The changes maintain existing behavior when the feature flag is disabled, ensuring no disruption to current functionality.
-
Test updates: Modified test cases to verify the new filtering works correctly, showing different results when filtering is enabled versus disabled.
The practical impact is that administrators can now get more targeted AI usage reports - for example, seeing how much AI code assistance is being used within a specific team or project, rather than across the entire platform. This provides better insights for understanding AI adoption patterns at different organizational levels.
References
How to set up and validate locally
q1. Assign your current user to a duo seat, or apply the following diff:
diff --git a/ee/app/models/ee/user.rb b/ee/app/models/ee/user.rb
index 1d350dc8bfc8..d8dee0783bcb 100644
--- a/ee/app/models/ee/user.rb
+++ b/ee/app/models/ee/user.rb
@@ -526,6 +526,8 @@ 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::AddOnPurchase
-
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
4 Run the following GraphQL queries for each project and its parent group and check if results are filtered correctly
query {
project(fullPath: PROJECT_ID) {
id
aiMetrics {
codeSuggestions {
shownLinesOfCode
shownCount
acceptedLinesOfCode
acceptedCount
acceptedLinesOfCode
contributorsCount
languages
}
duoAssignedUsersCount
duoChatContributorsCount
duoUsedCount
rootCauseAnalysisUsersCount
}
aiUserMetrics {
nodes {
codeSuggestionsAcceptedCount
duoChatInteractionsCount
user {
username
}
}
}
}
}
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.