Commit 5f1a5cbe authored by Patrick Bajao's avatar Patrick Bajao

Merge branch 'fix-search-paid-metric' into 'master'

Re-enable HLL event `i_search_paid` metric

See merge request gitlab-org/gitlab!40861
parents 67aa3479 950f9881
......@@ -12,11 +12,12 @@ module EE
def track_advanced_search
# track unique users of advanced global search
track_unique_redis_hll_event("i_search_advanced", :search_track_unique_users) if search_service.use_elasticsearch?
track_unique_redis_hll_event('i_search_advanced', :search_track_unique_users) if search_service.use_elasticsearch?
# track unique users who search against paid groups/projects
# this line is commented out because of https://gitlab.com/gitlab-org/gitlab/-/issues/243486
# track_unique_redis_hll_event("i_search_paid", :search_track_unique_users) if (search_service.project || search_service.group)&.feature_available?(:elastic_search)
# track unique paid users (users who already use elasticsearch and users who could use it if they enable elasticsearch integration)
# for gitlab.com we check if the search uses elasticsearch
# for self-managed we check if the licensed feature available
track_unique_redis_hll_event('i_search_paid', :search_track_unique_users) if (::Gitlab.com? && search_service.use_elasticsearch?) || (!::Gitlab.com? && License.feature_available?(:elastic_search))
end
end
end
......@@ -30,25 +30,56 @@ RSpec.describe SearchController do
end
end
# i_search_paid is commented out because of https://gitlab.com/gitlab-org/gitlab/-/issues/243486
# context 'i_search_paid' do
# let(:group) { create(:group) }
# let(:request_params) { { group_id: group.id, scope: 'blobs', search: 'term' } }
# let(:target_id) { 'i_search_paid' }
context 'i_search_paid' do
let_it_be(:group) { create(:group) }
# before do
# allow(group).to receive(:feature_available?).with(:elastic_search).and_return(true)
# end
let(:request_params) { { group_id: group.id, scope: 'blobs', search: 'term' } }
let(:target_id) { 'i_search_paid' }
# it_behaves_like 'tracking unique hll events', :show
context 'on Gitlab.com' do
before do
allow(::Gitlab).to receive(:com?).and_return(true)
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end
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)
get :show, params: request_params, format: :html
end
end
context 'self-managed instance' do
before do
allow(::Gitlab).to receive(:com?).and_return(false)
end
context 'license is available' do
before do
stub_licensed_features(elastic_search: true)
end
# 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', :show
# get :show, params: request_params, format: :html
# end
# end
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
end
end
it 'does not track if there is no license available' do
stub_licensed_features(elastic_search: false)
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event).with(instance_of(String), target_id)
get :show, params: request_params, format: :html
end
end
end
end
end
end
......@@ -149,10 +149,16 @@ RSpec.describe SearchController do
expect(assigns[:search_objects].first).to eq note
end
context 'unique users tracking' do
before 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' } }
let(:target_id) { 'i_search_total' }
end
end
context 'on restricted projects' do
context 'when signed out' do
......
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