Commit b7fc6635 authored by Dmitry Gruzd's avatar Dmitry Gruzd Committed by Vitali Tatarintev

Feature flag rollout `search_track_unique_users`

parent 95a1e91c
...@@ -8,29 +8,32 @@ ...@@ -8,29 +8,32 @@
# include RedisTracking # include RedisTracking
# #
# track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :my_feature # track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :my_feature
#
# if the feature flag is enabled by default you should use
# track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :my_feature, feature_default_enabled: true
module RedisTracking module RedisTracking
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do
def track_redis_hll_event(*controller_actions, name:, feature:) def track_redis_hll_event(*controller_actions, name:, feature:, feature_default_enabled: false)
after_action only: controller_actions, if: -> { request.format.html? && request.headers['DNT'] != '1' } do after_action only: controller_actions, if: -> { request.format.html? && request.headers['DNT'] != '1' } do
track_unique_redis_hll_event(name, feature) track_unique_redis_hll_event(name, feature, feature_default_enabled)
end end
end end
end end
private private
def track_unique_redis_hll_event(event_name, feature) def track_unique_redis_hll_event(event_name, feature, feature_default_enabled)
return unless metric_feature_enabled?(feature) return unless metric_feature_enabled?(feature, feature_default_enabled)
return unless Gitlab::CurrentSettings.usage_ping_enabled? return unless Gitlab::CurrentSettings.usage_ping_enabled?
return unless visitor_id return unless visitor_id
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(visitor_id, event_name) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(visitor_id, event_name)
end end
def metric_feature_enabled?(feature) def metric_feature_enabled?(feature, default_enabled)
Feature.enabled?(feature) Feature.enabled?(feature, default_enabled: default_enabled)
end end
def visitor_id def visitor_id
......
...@@ -11,7 +11,7 @@ class SearchController < ApplicationController ...@@ -11,7 +11,7 @@ class SearchController < ApplicationController
issues: :with_web_entity_associations issues: :with_web_entity_associations
}.freeze }.freeze
track_redis_hll_event :show, name: 'i_search_total', feature: :search_track_unique_users track_redis_hll_event :show, name: 'i_search_total', feature: :search_track_unique_users, feature_default_enabled: true
around_action :allow_gitaly_ref_name_caching around_action :allow_gitaly_ref_name_caching
......
---
title: Enable unique search users usage ping HLL metric by default
merge_request: 41739
author:
type: added
...@@ -4,4 +4,4 @@ introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40134 ...@@ -4,4 +4,4 @@ introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/40134
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/240906 rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/240906
group: group::global search group: group::global search
type: development type: development
default_enabled: false default_enabled: true
...@@ -256,13 +256,14 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF ...@@ -256,13 +256,14 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
keys for data storage. For `daily` we keep a key for metric per day of the year, for `weekly` we keys for data storage. For `daily` we keep a key for metric per day of the year, for `weekly` we
keep a key for metric per week of the year. keep a key for metric per week of the year.
1. Track event in controller using `RedisTracking` module with `track_redis_hll_event(*controller_actions, name:, feature:)`. 1. Track event in controller using `RedisTracking` module with `track_redis_hll_event(*controller_actions, name:, feature:, feature_default_enabled: false)`.
Arguments: Arguments:
- `controller_actions`: controller actions we want to track. - `controller_actions`: controller actions we want to track.
- `name`: event name. - `name`: event name.
- `feature`: feature name, all metrics we track should be under feature flag. - `feature`: feature name, all metrics we track should be under feature flag.
- `feature_default_enabled`: feature flag is disabled by default, set to `true` for it to be enabled by default.
Example usage: Example usage:
...@@ -272,7 +273,7 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF ...@@ -272,7 +273,7 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
include RedisTracking include RedisTracking
skip_before_action :authenticate_user!, only: :show skip_before_action :authenticate_user!, only: :show
track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :g_compliance_dashboard_feature track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :g_compliance_dashboard_feature, feature_default_enabled: true
def index def index
render html: 'index' render html: 'index'
......
...@@ -5,19 +5,19 @@ module EE ...@@ -5,19 +5,19 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
before_action :track_advanced_search, only: :show, if: -> { ::Feature.enabled?(:search_track_unique_users) && request.format.html? && request.headers['DNT'] != '1' } before_action :track_advanced_search, only: :show, if: -> { ::Feature.enabled?(:search_track_unique_users, default_enabled: true) && request.format.html? && request.headers['DNT'] != '1' }
end end
private private
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, true) if search_service.use_elasticsearch?
# track unique paid users (users who already use elasticsearch and users who could use it if they enable elasticsearch integration) # 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 gitlab.com we check if the search uses elasticsearch
# for self-managed we check if the licensed feature available # 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)) track_unique_redis_hll_event('i_search_paid', :search_track_unique_users, true) if (::Gitlab.com? && search_service.use_elasticsearch?) || (!::Gitlab.com? && License.feature_available?(:elastic_search))
end end
end end
end end
...@@ -11,7 +11,7 @@ RSpec.describe RedisTracking do ...@@ -11,7 +11,7 @@ RSpec.describe RedisTracking do
include RedisTracking include RedisTracking
skip_before_action :authenticate_user!, only: :show skip_before_action :authenticate_user!, only: :show
track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :g_compliance_dashboard_feature track_redis_hll_event :index, :show, name: 'i_analytics_dev_ops_score', feature: :g_compliance_dashboard_feature, feature_default_enabled: true
def index def index
render html: 'index' render html: 'index'
...@@ -61,6 +61,14 @@ RSpec.describe RedisTracking do ...@@ -61,6 +61,14 @@ RSpec.describe RedisTracking do
get :index get :index
end end
it 'passes default_enabled flag' do
sign_in(user)
expect(controller).to receive(:metric_feature_enabled?).with(feature.to_sym, true)
get :index
end
end end
context 'when user is not logged in and there is a visitor_id' do context 'when user is not logged in and there is a visitor_id' 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