Track SFE actions in BlobController

In this commit we track Single File Editor actions
when a blob is created or updated.
parent 146c43c9
......@@ -10,6 +10,8 @@ class Projects::BlobController < Projects::ApplicationController
include RedirectsForMissingPathOnTree
include SourcegraphDecorator
include DiffHelper
include RedisTracking
extend ::Gitlab::Utils::Override
prepend_before_action :authenticate_user!, only: [:edit]
......@@ -35,6 +37,8 @@ class Projects::BlobController < Projects::ApplicationController
push_frontend_feature_flag(:suggest_pipeline) if experiment_enabled?(:suggest_pipeline)
end
track_redis_hll_event :create, :update, name: 'g_edit_by_sfe', feature: :track_editor_edit_actions
def new
commit unless @repository.empty?
end
......@@ -256,4 +260,9 @@ class Projects::BlobController < Projects::ApplicationController
def diff_params
params.permit(:full, :since, :to, :bottom, :unfold, :offset, :indent)
end
override :visitor_id
def visitor_id
current_user&.id
end
end
---
title: Track SFE actions in BlobController
merge_request: 40846
author:
type: changed
......@@ -17,16 +17,11 @@ RSpec.describe SearchController do
end
context 'i_search_advanced' do
let(:target_id) { 'i_search_advanced' }
let(:request_params) { { scope: 'projects', search: 'term' } }
it_behaves_like 'tracking unique hll events', :show
it 'does not track if feature flag is disabled' do
stub_feature_flags(search_track_unique_users: false)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(instance_of(String), target_id)
it_behaves_like 'tracking unique hll events', :search_track_unique_users do
subject { get :show, params: { scope: 'projects', search: 'term' }, format: format }
get :show, params: request_params, format: :html
let(:target_id) { 'i_search_advanced' }
let(:expected_type) { instance_of(String) }
end
end
......@@ -42,13 +37,10 @@ RSpec.describe SearchController do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end
it_behaves_like 'tracking unique hll events', :show
it_behaves_like 'tracking unique hll events', :search_track_unique_users do
subject { get :show, params: request_params, format: format }
it 'does not track if feature flag is disabled' do
stub_feature_flags(search_track_unique_users: false)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(instance_of(String), target_id)
get :show, params: request_params, format: :html
let(:expected_type) { instance_of(String) }
end
end
......@@ -62,13 +54,10 @@ RSpec.describe SearchController do
stub_licensed_features(elastic_search: true)
end
it_behaves_like 'tracking unique hll events', :show
it_behaves_like 'tracking unique hll events', :search_track_unique_users do
subject { get :show, params: request_params, format: format }
it 'does not track if feature flag is disabled' do
stub_feature_flags(search_track_unique_users: false)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(instance_of(String), target_id)
get :show, params: request_params, format: :html
let(:expected_type) { instance_of(String) }
end
end
......
......@@ -347,6 +347,13 @@ RSpec.describe Projects::BlobController do
end
end
end
it_behaves_like 'tracking unique hll events', :track_editor_edit_actions do
subject { put :update, params: default_params, format: format }
let(:target_id) { 'g_edit_by_sfe' }
let(:expected_type) { instance_of(Integer) }
end
end
describe 'DELETE destroy' do
......@@ -436,4 +443,32 @@ RSpec.describe Projects::BlobController do
end
end
end
describe 'POST create' do
let(:user) { create(:user) }
let(:default_params) do
{
namespace_id: project.namespace,
project_id: project,
id: 'master',
branch_name: 'master',
file_name: 'docs/EXAMPLE_FILE',
content: 'Added changes',
commit_message: 'Create CHANGELOG'
}
end
before do
project.add_developer(user)
sign_in(user)
end
it_behaves_like 'tracking unique hll events', :track_editor_edit_actions do
subject { post :create, params: default_params, format: format }
let(:target_id) { 'g_edit_by_sfe' }
let(:expected_type) { instance_of(Integer) }
end
end
end
......@@ -154,9 +154,11 @@ RSpec.describe SearchController do
allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event)
end
it_behaves_like 'tracking unique hll events', :show do
let(:request_params) { { scope: 'projects', search: 'term' } }
it_behaves_like 'tracking unique hll events', :search_track_unique_users do
subject { get :show, params: { scope: 'projects', search: 'term' }, format: format }
let(:target_id) { 'i_search_total' }
let(:expected_type) { instance_of(String) }
end
end
......
# frozen_string_literal: true
RSpec.shared_examples 'tracking unique hll events' do |method|
it 'tracks unique event if the format is HTML' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(instance_of(String), target_id)
RSpec.shared_examples 'tracking unique hll events' do |feature_flag|
context 'when format is HTML' do
let(:format) { :html }
get method, params: request_params, format: :html
it 'tracks unique event' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(expected_type, target_id)
subject
end
it 'tracks unique event if DNT is not enabled' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(instance_of(String), target_id)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event).with(expected_type, target_id)
request.headers['DNT'] = '0'
get method, params: request_params, format: :html
subject
end
it 'does not track unique event if DNT is enabled' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(instance_of(String), target_id)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(expected_type, target_id)
request.headers['DNT'] = '1'
get method, params: request_params, format: :html
subject
end
context 'when feature flag is disabled' do
it 'does not track unique event' do
stub_feature_flags(feature_flag => false)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(expected_type, target_id)
subject
end
end
end
context 'when format is JSON' do
let(:format) { :json }
it 'does not track unique event if the format is JSON' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(instance_of(String), target_id)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(expected_type, target_id)
get method, params: request_params, format: :json
subject
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