aiMetrics: Remove legacy contributors-based filtering code after namespace_path migration
Summary
Clean up legacy contributors-based filtering code after the use_ai_events_namespace_path_filter feature flag has been enabled globally and proven stable.
Background
Multiple services currently maintain both legacy contributors-based filtering and new namespace_path filtering behind the feature flag. Once the migration is complete, we should remove the legacy code to reduce complexity and maintenance burden.
Code to Remove
Services with legacy QUERY constants:
-
CodeSuggestionUsageService (
ee/app/services/analytics/ai_analytics/code_suggestion_usage_service.rb)- Remove
QUERYconstant (lines with contributors CTE) - Remove
NEW_QUERYconstant - Remove deprecated field queries:
CODE_CONTRIBUTORS_COUNT_QUERY,CODE_SUGGESTIONS_CONTRIBUTORS_COUNT_QUERY,CODE_SUGGESTIONS_SHOWN_COUNT_QUERY,CODE_SUGGESTIONS_ACCEPTED_COUNT_QUERY
- Remove
-
DuoChatUsageService (
ee/app/services/analytics/ai_analytics/duo_chat_usage_service.rb)- Remove
QUERYconstant - Remove
NEW_QUERYconstant - Remove
CONTRIBUTORS_COUNT_QUERY
- Remove
-
DuoUsageService (
ee/app/services/analytics/ai_analytics/duo_usage_service.rb)- Remove
QUERYconstant - Remove
NEW_QUERYconstant
- Remove
-
CommonUsageService (
ee/app/services/analytics/ai_analytics/common_usage_service.rb)- Remove
CONTRIBUTORS_FILTER_REGEX_PATTERN - Remove
replace_contributors_filtermethod - Remove
base_querymethod - Remove
fetch_contributions_from_new_table?method - Simplify
raw_queryto not use format with base_query
- Remove
-
AiUserMetricsService (
ee/app/services/analytics/ai_analytics/ai_user_metrics_service.rb)- Remove
filter_by_namespace_path_enabled?method - Simplify
placeholdersmethod to always usenamespace.traversal_path(remove conditional logic)
- Remove
-
Ai::CodeSuggestionEventsFinder (
ee/app/finders/ai/code_suggestion_events_finder.rb)- Remove
CONTRIBUTORS_IDS_QUERY - Remove
CONTRIBUTORS_IDS_NEW_QUERY - Remove
contributors_idsmethod - Remove
contributors_ids_from_postgresqlmethod - Remove
contributors_ids_from_chmethod - Remove
ch_contributors_ids_querymethod - Remove
fetch_contributions_from_new_table?method - Simplify initializer to not set
@usersor clear@namespace
- Remove
GraphQL Resolvers:
-
CodeSuggestionEventsResolver (
ee/app/graphql/resolvers/analytics/ai_usage/code_suggestion_events_resolver.rb)- Remove
should_raise_error?method (lines 31-36) - Remove the
ready?method override that callsshould_raise_error? - Remove related comments about feature flag
- Remove
Feature Flag References:
- Remove feature flag definition:
ee/config/feature_flags/wip/use_ai_events_namespace_path_filter.yml - Remove all
Feature.enabled?(:use_ai_events_namespace_path_filter)checks
Tests to Update:
-
ee/spec/finders/ai/code_suggestion_events_finder_spec.rb- Remove contexts testing with feature flag disabled
- Remove
stub_feature_flags(use_ai_events_namespace_path_filter: false)calls
-
ee/spec/services/analytics/ai_analytics/duo_usage_service_spec.rb- Remove feature flag contexts and stubs
- Update expected results to only test namespace_path filtering
-
ee/spec/services/analytics/ai_analytics/duo_chat_usage_service_spec.rb- Remove feature flag contexts and stubs
- Update expected results to only test namespace_path filtering
-
ee/spec/services/analytics/ai_analytics/ai_user_metrics_service_spec.rb- Remove feature flag contexts and stubs
-
ee/spec/graphql/resolvers/analytics/ai_usage/code_suggestion_events_resolver_spec.rb- Remove tests for
should_raise_error?method - Update tests to work without feature flag checks
- Remove tests for
Services to Review (likely no changes needed):
-
TroubleshootUsageService (
ee/app/services/analytics/ai_analytics/troubleshoot_usage_service.rb)- Already uses namespace_path filtering directly in its QUERY
- Overrides
fetch_contributions_from_new_table?to return false - Review to confirm no changes needed
Prerequisites
-
use_ai_events_namespace_path_filterenabled globally for at least 1 milestone -
No incidents or data accuracy issues reported -
Metrics show namespace_path filtering is working correctly
Implementation Steps
- Create MR to remove legacy code
- Update all related tests
- Update documentation if needed
- Get review from team
- Merge and monitor