Allow to filter AI events by project group
We plan to expose raw code suggestion events in a GraphQL endpoint for projects and groups, but right now we do not have a way to filter records by a single group or a project. The data to be exposed on the API endpoint is backfilled from ClickHouse into Postgres in a table called ai_code_suggestion_events, but does not have association with a container by any means via project_id or group_id columns.
Solution
- Persist
code_suggestion_usages.namespace_pathfield on ClickHouse with namespace traversal path, for example,1/2/3 - Persist namespace traversal path on PG field
ai_code_suggestion_usages.namespace_pathandai_duo_chat_events.namespace_path. - Create an index on PG to support filtering by namespace path on both tables:
CREATE INDEX index_name ON ai_code_suggestion_events (((regexp_replace(namespace_path, '.*/([0-9]+)[^0-9]*$', '\1'))::bigint))
This will support queries like:
Ai::CodeSuggestion_event.where(((regexp_replace(namespace_path, '.*/([0-9]+)[^0-9]*$', '\1'))::bigint) IN (#{group.all_projects.select(:project_namespace_id).to_sql})))
- Update data queries from
Analytics::AiAnalytics::AiMetricsServiceto filter by namespace path instead of users contributions. - Update queries at
Ai::CodeSuggestionEventsFinderto filter by namespace path instead of users contributions. - All of the above needs to be handled behind a feature flag
Edited by 🤖 GitLab Bot 🤖