Commit 950f9881 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Fix i_search_paid metric

parent d8e6347d
...@@ -12,11 +12,12 @@ module EE ...@@ -12,11 +12,12 @@ module EE
def track_advanced_search def track_advanced_search
# track unique users of advanced global 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 # track unique paid users (users who already use elasticsearch and users who could use it if they enable elasticsearch integration)
# this line is commented out because of https://gitlab.com/gitlab-org/gitlab/-/issues/243486 # for gitlab.com we check if the search uses elasticsearch
# track_unique_redis_hll_event("i_search_paid", :search_track_unique_users) if (search_service.project || search_service.group)&.feature_available?(:elastic_search) # 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 end
end end
...@@ -30,25 +30,56 @@ RSpec.describe SearchController do ...@@ -30,25 +30,56 @@ RSpec.describe SearchController do
end end
end end
# i_search_paid is commented out because of https://gitlab.com/gitlab-org/gitlab/-/issues/243486 context 'i_search_paid' do
# context 'i_search_paid' do let_it_be(:group) { create(:group) }
# let(:group) { create(:group) }
# let(:request_params) { { group_id: group.id, scope: 'blobs', search: 'term' } }
# let(:target_id) { 'i_search_paid' }
# before do let(:request_params) { { group_id: group.id, scope: 'blobs', search: 'term' } }
# allow(group).to receive(:feature_available?).with(:elastic_search).and_return(true) let(:target_id) { 'i_search_paid' }
# end
# 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 'does not track if feature flag is disabled' do it_behaves_like 'tracking unique hll events', :show
# 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 it 'does not track if feature flag is disabled' do
# end stub_feature_flags(search_track_unique_users: false)
# end 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_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
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 end
end end
...@@ -149,9 +149,15 @@ RSpec.describe SearchController do ...@@ -149,9 +149,15 @@ RSpec.describe SearchController do
expect(assigns[:search_objects].first).to eq note expect(assigns[:search_objects].first).to eq note
end end
it_behaves_like 'tracking unique hll events', :show do context 'unique users tracking' do
let(:request_params) { { scope: 'projects', search: 'term' } } before do
let(:target_id) { 'i_search_total' } 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 end
context 'on restricted projects' do context 'on restricted projects' 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