diff --git a/app/services/ci/create_job_artifacts_service.rb b/app/services/ci/create_job_artifacts_service.rb index 2cfde1a8bfecac5377cd06cdfcc54ea140c3d004..81586332f513d0d7ec13d194606f35cf8f308604 100644 --- a/app/services/ci/create_job_artifacts_service.rb +++ b/app/services/ci/create_job_artifacts_service.rb @@ -2,6 +2,8 @@ module Ci class CreateJobArtifactsService < ::BaseService + include Gitlab::Utils::UsageData + ArtifactsExistError = Class.new(StandardError) LSIF_ARTIFACT_TYPE = 'lsif' @@ -22,7 +24,11 @@ def authorize(artifact_type:, filesize: nil) return result unless result[:status] == :success headers = JobArtifactUploader.workhorse_authorize(has_length: false, maximum_size: max_size(artifact_type)) - headers[:ProcessLsif] = lsif?(artifact_type) + + if lsif?(artifact_type) + headers[:ProcessLsif] = true + track_usage_event('i_source_code_code_intelligence', project) + end success(headers: headers) end diff --git a/changelogs/unreleased/237793-code-intelligence-usage-ping.yml b/changelogs/unreleased/237793-code-intelligence-usage-ping.yml new file mode 100644 index 0000000000000000000000000000000000000000..e770b3a938d896eae2669655a7abcd07e2261c19 --- /dev/null +++ b/changelogs/unreleased/237793-code-intelligence-usage-ping.yml @@ -0,0 +1,5 @@ +--- +title: Track projects using code intelligence +merge_request: 41881 +author: +type: added diff --git a/lib/gitlab/usage_data_counters/known_events.yml b/lib/gitlab/usage_data_counters/known_events.yml index a0f20405bb8be9e70e185ac067112ec8d0b0881a..05514d55e92eb4f7c9ab5101995dd9177844ffd0 100644 --- a/lib/gitlab/usage_data_counters/known_events.yml +++ b/lib/gitlab/usage_data_counters/known_events.yml @@ -116,6 +116,10 @@ - name: merge_request_action category: source_code aggregation: daily +- name: i_source_code_code_intelligence + redis_slot: source_code + category: source_code + aggregation: daily # Incident management - name: incident_management_alert_status_changed redis_slot: incident_management diff --git a/spec/requests/api/ci/runner/jobs_artifacts_spec.rb b/spec/requests/api/ci/runner/jobs_artifacts_spec.rb index 77ff561bbdf7c7bb65aa72586212d7f7277c988f..97110b63ff6dee89bf0416de96080c2162b8c59d 100644 --- a/spec/requests/api/ci/runner/jobs_artifacts_spec.rb +++ b/spec/requests/api/ci/runner/jobs_artifacts_spec.rb @@ -238,9 +238,24 @@ expect(json_response['ProcessLsif']).to be_truthy end + it 'tracks code_intelligence usage ping' do + tracking_params = { + event_names: 'i_source_code_code_intelligence', + start_date: Date.yesterday, + end_date: Date.today + } + + expect { authorize_artifacts_with_token_in_headers(artifact_type: :lsif) } + .to change { Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(tracking_params) } + .by(1) + end + context 'code_navigation feature flag is disabled' do - it 'responds with a forbidden error' do + before do stub_feature_flags(code_navigation: false) + end + + it 'responds with a forbidden error' do authorize_artifacts_with_token_in_headers(artifact_type: :lsif) aggregate_failures do @@ -248,6 +263,17 @@ expect(json_response['ProcessLsif']).to be_falsy end end + + it 'does not track code_intelligence usage ping' do + tracking_params = { + event_names: 'i_source_code_code_intelligence', + start_date: Date.yesterday, + end_date: Date.today + } + + expect { authorize_artifacts_with_token_in_headers(artifact_type: :lsif) } + .not_to change { Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(tracking_params) } + end end end