581293 - AI User Metrics Sorting Service Changes
What does this MR do and why?
This code change adds sorting functionality to an AI analytics service that tracks user metrics. This MR is the first part for enabling users to query the results in sortable way introducded in this draft MR
References
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
- Checkout the service file changes under the branch in the other branch in !213812
- Run query that can look like that (this is very inclusive query, feel free to take small part of it for testing)
query getUserAiUserMetrics($fullPath: ID!, $startDate: Date!, $endDate: Date!) {
group(fullPath: $fullPath) {
id
aiUserMetrics(startDate: $startDate, endDate: $endDate, sort: TOTAL_EVENTS_COUNT_DESC) {
nodes {
user {
id
name
}
totalEventCount
# codeSuggestionsAcceptedCount
codeSuggestions {
codeSuggestionShownInIdeEventCount
codeSuggestionAcceptedInIdeEventCount
codeSuggestionRejectedInIdeEventCount
totalEventCount
}
chat {
requestDuoChatResponseEventCount
totalEventCount
}
codeReview {
totalEventCount
encounterDuoCodeReviewErrorDuringReviewEventCount
findNoIssuesDuoCodeReviewAfterReviewEventCount
findNothingToReviewDuoCodeReviewOnMrEventCount
postCommentDuoCodeReviewOnDiffEventCount
reactThumbsUpOnDuoCodeReviewCommentEventCount
reactThumbsDownOnDuoCodeReviewCommentEventCount
requestReviewDuoCodeReviewOnMrByAuthorEventCount
requestReviewDuoCodeReviewOnMrByNonAuthorEventCount
excludedFilesFromDuoCodeReviewEventCount
}
agentPlatform {
agentPlatformSessionCreatedEventCount
agentPlatformSessionStartedEventCount
agentPlatformSessionFinishedEventCount
agentPlatformSessionDroppedEventCount
agentPlatformSessionStoppedEventCount
agentPlatformSessionResumedEventCount
}
troubleshootJob{
troubleshootJobEventCount
}
}
}
}
}
- Might need to bypass the
read_enterprise_ai_analyticsauthroization check (comment it out) inee/app/graphql/resolvers/analytics/ai_metrics/user_metrics_resolver.rb
Query:
SELECT `ai_usage_events_daily`.`user_id`, sumIf(occurrences, `ai_usage_events_daily`.`event` = 1) AS code_suggestions_requested_event_count, sumIf(occurrences, `ai_usage_events_daily`.`event` = 2) AS code_suggestion_shown_in_ide_event_count, sumIf(occurrences, `ai_usage_events_daily`.`event` = 3) AS code_suggestion_accepted_in_ide_event_count, sumIf(occurrences, `ai_usage_events_daily`.`event` = 4) AS code_suggestion_rejected_in_ide_event_count, sumIf(occurrences, `ai_usage_events_daily`.`event` = 5) AS code_suggestion_direct_access_token_refresh_event_count, sumIf(occurrences, `ai_usage_events_daily`.`event` IN (1, 2, 3, 4, 5)) AS sort_count FROM `ai_usage_events_daily` WHERE `ai_usage_events_daily`.`date` >= '2025-11-18' AND `ai_usage_events_daily`.`date` <= '2025-12-01' AND startsWith(`ai_usage_events_daily`.`namespace_path`, '466/') GROUP BY user_id ORDER BY sort_count DESC
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.
Related to #581293
Edited by Amr Taha