Add CodeSuggestions support to GLQL in GitLab UI
What does this MR do and why?
This MR integrates CodeSuggestions analytics into the GitLab UI, enabling users to query Code Suggestions usage data using GLQL in any markdown field. It depends on the backend GraphQL API Expose code suggestions AE to graphql (!226274 - merged) and GLQL MRs Add analytics aggregation support (glql!347 - merged) and Implement CodeSuggestions analytics source (glql!348 - merged).
TODO
- Create feature flag issue and update feature flag YAML
- Verify MR resolves all requirements for GLQL UI integration for CodeSuggestion analytics (#592262)
What Changed
- Bumps the GLQL package version to the version that supports CodeSuggestions and analytics mode
- Added percentage and number presenters for analytics data
- Updated GLQL parser to handle analytics mode (no default fields for analytics queries)
- Added transformer support for next pagination in analytics mode
- Created feature flag:
glql_code_suggestion_analytics_aggregation - Added frontend tests for new presenters and analytics parsing
References
- MR !228129
- Base Branch: expose-code-suggestions-ae-to-graphql
- GLQL MR !347 (Analytics Infrastructure)
- GLQL MR !348 (CodeSuggestions Source)
- Work Item 592262
- ClickHouse Setup Documentation
- GLQL User Documentation
Screenshots or screen recordings
| Scenario | GLQL query | Output |
|---|---|---|
| Every metric and dimension | ![]() |
![]() |
| In the Data Analyst Agent | Requires a lot of cajoling until Data Analyst agent integration for CodeSuggesti... (#592264) is complete | ![]() |
| With feature flag disabled | ![]() |
![]() |
| Trying to use it outside analytics mode | ![]() |
![]() |
Trying to use fields |
![]() |
![]() |
Trying to use dimensions or metrics in standard mode |
![]() |
![]() |
How to set up and validate locally
Prerequisites
- Setup clickhouse
- Make sure to run migrations:
bundle exec rake gitlab:clickhouse:migrate - Enable clickhouse analytics:
echo "Gitlab::CurrentSettings.current_application_settings.update(use_clickhouse_for_analytics: true)" | rails c - Seed test data:
FILTER=ai_usage_stats bundle exec rake db:seed_fu
UI Testing
-
Navigate to a seeded projects issue or merge request (by default this is the
toolboxgroup), and go to a markdown enabled field (comments or descriptions for instance) -
Test that without the feature flag enabled, the
CodeSuggestiontype returns an error:mode: analytics query: type = CodeSuggestion and timestamp >= -30d dimensions: language metrics: totalCount, acceptanceRate sort: totalCount desc limit: 10 -
Enable the feature flag:
echo "Feature.enable(:glql_code_suggestion_analytics_aggregation)" | rails c -
Refresh the page, test that the query no longer errors and returns results
-
Now test other variants like: Ide comparison by language
mode: analytics query: type = CodeSuggestion and language in ("ruby", "javascript", "python") dimensions: language, ideName metrics: totalCount, acceptedCount, rejectedCount, acceptanceRate sort: acceptanceRate descRecent activity
mode: analytics query: type = CodeSuggestion and timestamp >= -7d dimensions: language metrics: totalCount, usersCount, suggestionSizeSum sort: usersCount desc limit: 5User-specific
mode: analytics query: type = CodeSuggestion and user = 2 and timestamp >= -14d dimensions: language, ideName metrics: totalCount, acceptanceRate, acceptedCount sort: totalCount desc -
Also verify that percentage presenters like
acceptanceRateshow as percentages -
Also verify that number presenters like
totalCountformat according to your browser language (e.g. 1,234 or 1.234)
Rest API endpoint
Test the /api/v4/glql REST API endpoint:
# Get a personal access token from GitLab UI: User Settings > Access Tokens
curl -H "PRIVATE-TOKEN: your_token" \
-H "Content-Type: application/json" \
-d '{
"glql_yaml": "query: type = CodeSuggestion and language = \"ruby\"\nmode: \"analytics\"\ndimensions: \"language\"\nmetrics: \"totalCount, acceptanceRate\"\nproject: \"toolbox/gitlab-smoke-tests\""
}' \
http://gdk.test:8080/api/v4/glql 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 GLQL UI integration for CodeSuggestion analytics (#592262)











