Skip to content

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

  1. Persist code_suggestion_usages.namespace_path field on ClickHouse with namespace traversal path, for example, 1/2/3
  2. Persist namespace traversal path on PG field ai_code_suggestion_usages.namespace_path and ai_duo_chat_events.namespace_path.
  3. 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})))
  1. Update data queries from Analytics::AiAnalytics::AiMetricsService to filter by namespace path instead of users contributions.
  2. Update queries at Ai::CodeSuggestionEventsFinder to filter by namespace path instead of users contributions.
  3. All of the above needs to be handled behind a feature flag
Edited by 🤖 GitLab Bot 🤖