Add analytics presenters for CodeSuggestion data
What does this MR do and why?
Adds formatted presenters for CodeSuggestion analytics dimensions and metrics. This is the second MR in a stack that adds CodeSuggestion analytics support to the GitLab UI.
All presenter components and field key mappings live in FOSS, gated behind the feature flag added in !233396 (merged).
What Changed
New presenter components
- NumberPresenter: formats numbers with locale-aware separators using
formatNumber(e.g.1,234,567) - PercentagePresenter: converts decimal ratios to percentages, strips trailing
.0for whole numbers (e.g.0.425→42.5%,1→100%) - UserAvatarPresenter: renders user dimensions as labeled avatars with
GlAvatarLabeled, parsing numeric entity IDs from GID strings
Field key mappings
- Added analytics field keys to
presentersByFieldKeyinfield.vue:acceptanceRate,totalCount,acceptedCount,rejectedCount,shownCount,usersCount,suggestionSizeSum,user - Reordered
componentForFieldto check field key mappings before object type mappings (needed foruserfield key to resolve toUserAvatarPresenterinstead ofUserPresenterfor analytics dimensions)
Tests
- Added specs for
NumberPresenter,PercentagePresenter, andUserAvatarPresenter - Added analytics field key test rows to
field_spec.js - Added
MOCK_ANALYTICS_USERandMOCK_DIMENSIONStest fixtures
MR Stack
- !233396 (merged) — Backend + GLQL pipeline
- This MR — Analytics presenters
- !233398 (merged) — ListBasePresenter extraction + ListDimensionsPresenter
References
- GLQL UI integration for CodeSuggestion analytics (#592262)
- Add CodeSuggestions support to GLQL in GitLab UI (!228129 - closed)
- GLQL MR !347 (Analytics Infrastructure)
- GLQL MR !348 (CodeSuggestions Source)
- Work Item 592262
- GLQL User Documentation
Screenshots or screen recordings
| Scenario | GLQL query | Output |
|---|---|---|
| Every metric and dimension | ![]() |
![]() |
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 - Enable the feature flag:
echo "Feature.enable(:glql_code_suggestion_analytics_aggregation)" | rails c
UI Testing
- Navigate to a seeded project and open a markdown-enabled field (issue description, comment, etc.)
- Enter a GLQL analytics query and verify the presenters render correctly:
mode: analytics query: type = CodeSuggestion and timestamp >= -30d dimensions: language metrics: totalCount, acceptanceRate sort: totalCount desc limit: 10 - Verify that
acceptanceRateshows as a percentage (e.g.85%) - Verify that
totalCountformats with locale-aware separators (e.g.1,234) - Verify that user dimensions render as labeled avatars
Edited by Robert Hunt

