Commit 88b6b83b authored by Patrick Bajao's avatar Patrick Bajao

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.
parent 648abf78
......@@ -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 @@ module Ci
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
......
---
title: Track projects using code intelligence
merge_request: 41881
author:
type: added
......@@ -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
......
......@@ -238,9 +238,24 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
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 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment