From 88b6b83b3707ba40e570d75b31e3a51ce22e00a3 Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Mon, 14 Sep 2020 22:15:01 +0800 Subject: [PATCH] Track projects using code intelligence We need to track the usage of code intelligence. The authorize endpoint is called by workhorse to determine if it needs to parse LSIF which is needed for code intelligence feature to work. This adds tracking of `i_source_code_code_intelligence` event whenever it's determined that we are parsing LSIF. Uses the HLL counter so we get distinct count of projects. --- .../ci/create_job_artifacts_service.rb | 8 +++++- .../237793-code-intelligence-usage-ping.yml | 5 ++++ .../usage_data_counters/known_events.yml | 4 +++ .../api/ci/runner/jobs_artifacts_spec.rb | 28 ++++++++++++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/237793-code-intelligence-usage-ping.yml diff --git a/app/services/ci/create_job_artifacts_service.rb b/app/services/ci/create_job_artifacts_service.rb index 2cfde1a8bfecac..81586332f513d0 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 00000000000000..e770b3a938d896 --- /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 a0f20405bb8be9..05514d55e92eb4 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 77ff561bbdf7c7..97110b63ff6dee 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 -- GitLab