Commit 0beac0f8 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch '276948-check-feature-flag-in-hll-redis-counter' into 'master'

Use feature from know_events yml files for checking the features [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!53481
parents 682485e6 4c8616aa
...@@ -7,30 +7,26 @@ ...@@ -7,30 +7,26 @@
# #
# 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'
#
# 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
# #
# You can also pass custom conditions using `if:`, using the same format as with Rails callbacks. # You can also pass custom conditions using `if:`, using the same format as with Rails callbacks.
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:, feature_default_enabled: false, if: nil) def track_redis_hll_event(*controller_actions, name:, if: nil)
custom_conditions = Array.wrap(binding.local_variable_get('if')) custom_conditions = Array.wrap(binding.local_variable_get('if'))
conditions = [:trackable_request?, *custom_conditions] conditions = [:trackable_request?, *custom_conditions]
after_action only: controller_actions, if: conditions do after_action only: controller_actions, if: conditions do
track_unique_redis_hll_event(name, feature, feature_default_enabled) track_unique_redis_hll_event(name)
end end
end end
end end
private private
def track_unique_redis_hll_event(event_name, feature, feature_default_enabled) def track_unique_redis_hll_event(event_name)
return unless metric_feature_enabled?(feature, feature_default_enabled)
return unless visitor_id return unless visitor_id
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name, values: visitor_id) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name, values: visitor_id)
...@@ -40,10 +36,6 @@ module RedisTracking ...@@ -40,10 +36,6 @@ module RedisTracking
request.format.html? && request.headers['DNT'] != '1' request.format.html? && request.headers['DNT'] != '1'
end end
def metric_feature_enabled?(feature, default_enabled)
Feature.enabled?(feature, default_enabled: default_enabled)
end
def visitor_id def visitor_id
return cookies[:visitor_id] if cookies[:visitor_id].present? return cookies[:visitor_id] if cookies[:visitor_id].present?
return unless current_user return unless current_user
......
...@@ -15,7 +15,7 @@ module SnippetsActions ...@@ -15,7 +15,7 @@ module SnippetsActions
skip_before_action :verify_authenticity_token, skip_before_action :verify_authenticity_token,
if: -> { action_name == 'show' && js_request? } if: -> { action_name == 'show' && js_request? }
track_redis_hll_event :show, name: 'i_snippets_show', feature: :usage_data_i_snippets_show, feature_default_enabled: true track_redis_hll_event :show, name: 'i_snippets_show'
respond_to :html respond_to :html
end end
......
...@@ -36,8 +36,7 @@ module WikiActions ...@@ -36,8 +36,7 @@ module WikiActions
# NOTE: We want to include wiki page views in the same counter as the other # NOTE: We want to include wiki page views in the same counter as the other
# Event-based wiki actions tracked through TrackUniqueEvents, so we use the same event name. # Event-based wiki actions tracked through TrackUniqueEvents, so we use the same event name.
track_redis_hll_event :show, name: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION.to_s, track_redis_hll_event :show, name: Gitlab::UsageDataCounters::TrackUniqueEvents::WIKI_ACTION.to_s
feature: :track_unique_wiki_page_views, feature_default_enabled: true
helper_method :view_file_button, :diff_file_html_data helper_method :view_file_button, :diff_file_html_data
......
...@@ -35,7 +35,7 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -35,7 +35,7 @@ class Projects::BlobController < Projects::ApplicationController
record_experiment_user(:ci_syntax_templates, namespace_id: @project.namespace_id) if params[:file_name] == @project.ci_config_path_or_default record_experiment_user(:ci_syntax_templates, namespace_id: @project.namespace_id) if params[:file_name] == @project.ci_config_path_or_default
end end
track_redis_hll_event :create, :update, name: 'g_edit_by_sfe', feature: :track_editor_edit_actions, feature_default_enabled: true track_redis_hll_event :create, :update, name: 'g_edit_by_sfe'
feature_category :source_code_management feature_category :source_code_management
......
...@@ -5,7 +5,7 @@ class SearchController < ApplicationController ...@@ -5,7 +5,7 @@ class SearchController < ApplicationController
include SearchHelper include SearchHelper
include RedisTracking include RedisTracking
track_redis_hll_event :show, name: 'i_search_total', feature: :search_track_unique_users, feature_default_enabled: true track_redis_hll_event :show, name: 'i_search_total'
around_action :allow_gitaly_ref_name_caching around_action :allow_gitaly_ref_name_caching
......
...@@ -495,18 +495,17 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF ...@@ -495,18 +495,17 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
aggregation. aggregation.
- `aggregation`: may be set to a `:daily` or `:weekly` key. Defines how counting data is stored in Redis. - `aggregation`: may be set to a `:daily` or `:weekly` key. Defines how counting data is stored in Redis.
Aggregation on a `daily` basis does not pull more fine grained data. Aggregation on a `daily` basis does not pull more fine grained data.
- `feature_flag`: optional. For details, see our [GitLab internal Feature flags](feature_flags/) documentation. The feature flags are owned by the group adding the event tracking. - `feature_flag`: optional `default_enabled: :yaml`. If no feature flag is set then the tracking is enabled. For details, see our [GitLab internal Feature flags](feature_flags/) documentation. The feature flags are owned by the group adding the event tracking.
Use one of the following methods to track events: Use one of the following methods to track events:
1. Track event in controller using `RedisTracking` module with `track_redis_hll_event(*controller_actions, name:, feature:, feature_default_enabled: false)`. 1. Track event in controller using `RedisTracking` module with `track_redis_hll_event(*controller_actions, name:, if: nil)`.
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. - `if`: optional custom conditions, using the same format as with Rails callbacks.
- `feature_default_enabled`: feature flag is disabled by default, set to `true` for it to be enabled by default.
Example usage: Example usage:
...@@ -516,7 +515,7 @@ Use one of the following methods to track events: ...@@ -516,7 +515,7 @@ Use one of the following methods to track events:
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: 'g_compliance_example_feature_visitors', feature: :compliance_example_feature, feature_default_enabled: true track_redis_hll_event :index, :show, name: 'g_compliance_example_feature_visitors'
def index def index
render html: 'index' render html: 'index'
......
...@@ -7,13 +7,13 @@ module EE ...@@ -7,13 +7,13 @@ module EE
prepended do prepended do
# track unique users of advanced global search # track unique users of advanced global search
track_redis_hll_event :show, name: 'i_search_advanced', feature: :search_track_unique_users, feature_default_enabled: true, track_redis_hll_event :show, name: 'i_search_advanced',
if: :track_search_advanced? if: :track_search_advanced?
# 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_redis_hll_event :show, name: 'i_search_paid', feature: :search_track_unique_users, feature_default_enabled: true, track_redis_hll_event :show, name: 'i_search_paid',
if: :track_search_paid? if: :track_search_paid?
end end
......
...@@ -10,7 +10,7 @@ class Groups::Analytics::RepositoryAnalyticsController < Groups::Analytics::Appl ...@@ -10,7 +10,7 @@ class Groups::Analytics::RepositoryAnalyticsController < Groups::Analytics::Appl
before_action only: [:show] do before_action only: [:show] do
push_frontend_feature_flag(:usage_data_i_testing_group_code_coverage_project_click_total, @group, default_enabled: :yaml) push_frontend_feature_flag(:usage_data_i_testing_group_code_coverage_project_click_total, @group, default_enabled: :yaml)
end end
track_redis_hll_event :show, name: 'i_testing_group_code_coverage_visit_total', feature: :usage_data_i_testing_group_code_coverage_visit_total, feature_default_enabled: true track_redis_hll_event :show, name: 'i_testing_group_code_coverage_visit_total'
def show def show
track_event(**pageview_tracker_params) track_event(**pageview_tracker_params)
......
...@@ -10,8 +10,7 @@ module Projects ...@@ -10,8 +10,7 @@ module Projects
include RedisTracking include RedisTracking
track_redis_hll_event :index, track_redis_hll_event :index,
name: 'i_ecosystem_jira_service_list_issues', name: 'i_ecosystem_jira_service_list_issues'
feature: :usage_data_track_ecosystem_jira_service
before_action :check_feature_enabled! before_action :check_feature_enabled!
before_action :check_issues_show_enabled!, only: :show before_action :check_issues_show_enabled!, only: :show
......
...@@ -17,7 +17,7 @@ RSpec.describe SearchController do ...@@ -17,7 +17,7 @@ RSpec.describe SearchController do
end end
context 'i_search_advanced' do context 'i_search_advanced' do
it_behaves_like 'tracking unique hll events', :search_track_unique_users do it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: { scope: 'projects', search: 'term' } } subject(:request) { get :show, params: { scope: 'projects', search: 'term' } }
let(:target_id) { 'i_search_advanced' } let(:target_id) { 'i_search_advanced' }
...@@ -37,7 +37,7 @@ RSpec.describe SearchController do ...@@ -37,7 +37,7 @@ RSpec.describe SearchController do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end end
it_behaves_like 'tracking unique hll events', :search_track_unique_users do it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: request_params } subject(:request) { get :show, params: request_params }
let(:expected_type) { instance_of(String) } let(:expected_type) { instance_of(String) }
...@@ -54,7 +54,7 @@ RSpec.describe SearchController do ...@@ -54,7 +54,7 @@ RSpec.describe SearchController do
stub_licensed_features(elastic_search: true) stub_licensed_features(elastic_search: true)
end end
it_behaves_like 'tracking unique hll events', :search_track_unique_users do it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: request_params } subject(:request) { get :show, params: request_params }
let(:expected_type) { instance_of(String) } let(:expected_type) { instance_of(String) }
......
...@@ -38,7 +38,7 @@ RSpec.describe Groups::Analytics::RepositoryAnalyticsController do ...@@ -38,7 +38,7 @@ RSpec.describe Groups::Analytics::RepositoryAnalyticsController do
allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event) allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event)
end end
it_behaves_like 'tracking unique hll events', :usage_data_i_testing_group_code_coverage_visit_total do it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: { group_id: group } } subject(:request) { get :show, params: { group_id: group } }
let(:target_id) { 'i_testing_group_code_coverage_visit_total' } let(:target_id) { 'i_testing_group_code_coverage_visit_total' }
......
...@@ -129,6 +129,8 @@ module Gitlab ...@@ -129,6 +129,8 @@ module Gitlab
event = event_for(event_name) event = event_for(event_name)
raise UnknownEvent, "Unknown event #{event_name}" unless event.present? raise UnknownEvent, "Unknown event #{event_name}" unless event.present?
return unless feature_enabled?(event)
Gitlab::Redis::HLL.add(key: redis_key(event, time, context), value: values, expiry: expiry(event)) Gitlab::Redis::HLL.add(key: redis_key(event, time, context), value: values, expiry: expiry(event))
end end
...@@ -148,6 +150,12 @@ module Gitlab ...@@ -148,6 +150,12 @@ module Gitlab
redis_usage_data { Gitlab::Redis::HLL.count(keys: keys) } redis_usage_data { Gitlab::Redis::HLL.count(keys: keys) }
end end
def feature_enabled?(event)
return true if event[:feature_flag].blank?
Feature.enabled?(event[:feature_flag], default_enabled: :yaml)
end
# Allow to add totals for events that are in the same redis slot, category and have the same aggregation level # Allow to add totals for events that are in the same redis slot, category and have the same aggregation level
# and if there are more than 1 event # and if there are more than 1 event
def eligible_for_totals?(events_names) def eligible_for_totals?(events_names)
......
...@@ -3,18 +3,13 @@ ...@@ -3,18 +3,13 @@
require "spec_helper" require "spec_helper"
RSpec.describe RedisTracking do RSpec.describe RedisTracking do
let(:feature) { 'approval_rule' }
let(:user) { create(:user) } let(:user) { create(:user) }
before do
skip_feature_flags_yaml_validation
end
controller(ApplicationController) do controller(ApplicationController) 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: 'g_compliance_approval_rules', feature: :approval_rule, feature_default_enabled: true, track_redis_hll_event :index, :show, name: 'g_compliance_approval_rules',
if: [:custom_condition_one?, :custom_condition_two?] if: [:custom_condition_one?, :custom_condition_two?]
def index def index
...@@ -49,97 +44,75 @@ RSpec.describe RedisTracking do ...@@ -49,97 +44,75 @@ RSpec.describe RedisTracking do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event) expect(Gitlab::UsageDataCounters::HLLRedisCounter).not_to receive(:track_event)
end end
context 'with feature disabled' do context 'when user is logged in' do
it 'does not track the event' do
stub_feature_flags(feature => false)
expect_no_tracking
get :index
end
end
context 'with feature enabled' do
before do before do
stub_feature_flags(feature => true) sign_in(user)
end end
context 'when user is logged in' do it 'tracks the event' do
before do expect_tracking
sign_in(user)
end
it 'tracks the event' do
expect_tracking
get :index
end
it 'passes default_enabled flag' do
expect(controller).to receive(:metric_feature_enabled?).with(feature.to_sym, true)
get :index get :index
end end
it 'tracks the event if DNT is not enabled' do it 'tracks the event if DNT is not enabled' do
request.headers['DNT'] = '0' request.headers['DNT'] = '0'
expect_tracking expect_tracking
get :index get :index
end end
it 'does not track the event if DNT is enabled' do it 'does not track the event if DNT is enabled' do
request.headers['DNT'] = '1' request.headers['DNT'] = '1'
expect_no_tracking expect_no_tracking
get :index get :index
end end
it 'does not track the event if the format is not HTML' do it 'does not track the event if the format is not HTML' do
expect_no_tracking expect_no_tracking
get :index, format: :json get :index, format: :json
end end
it 'does not track the event if a custom condition returns false' do it 'does not track the event if a custom condition returns false' do
expect(controller).to receive(:custom_condition_two?).and_return(false) expect(controller).to receive(:custom_condition_two?).and_return(false)
expect_no_tracking expect_no_tracking
get :index get :index
end end
it 'does not track the event for untracked actions' do it 'does not track the event for untracked actions' do
expect_no_tracking expect_no_tracking
get :new get :new
end
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
let(:visitor_id) { SecureRandom.uuid } let(:visitor_id) { SecureRandom.uuid }
before do before do
routes.draw { get 'show' => 'anonymous#show' } routes.draw { get 'show' => 'anonymous#show' }
end end
it 'tracks the event' do it 'tracks the event' do
cookies[:visitor_id] = { value: visitor_id, expires: 24.months } cookies[:visitor_id] = { value: visitor_id, expires: 24.months }
expect_tracking expect_tracking
get :show get :show
end
end end
end
context 'when user is not logged in and there is no visitor_id' do context 'when user is not logged in and there is no visitor_id' do
it 'does not track the event' do it 'does not track the event' do
expect_no_tracking expect_no_tracking
get :index get :index
end
end end
end end
end end
...@@ -424,7 +424,7 @@ RSpec.describe Projects::BlobController do ...@@ -424,7 +424,7 @@ RSpec.describe Projects::BlobController do
end end
end end
it_behaves_like 'tracking unique hll events', :track_editor_edit_actions do it_behaves_like 'tracking unique hll events' do
subject(:request) { put :update, params: default_params } subject(:request) { put :update, params: default_params }
let(:target_id) { 'g_edit_by_sfe' } let(:target_id) { 'g_edit_by_sfe' }
...@@ -540,7 +540,7 @@ RSpec.describe Projects::BlobController do ...@@ -540,7 +540,7 @@ RSpec.describe Projects::BlobController do
sign_in(user) sign_in(user)
end end
it_behaves_like 'tracking unique hll events', :track_editor_edit_actions do it_behaves_like 'tracking unique hll events' do
subject(:request) { post :create, params: default_params } subject(:request) { post :create, params: default_params }
let(:target_id) { 'g_edit_by_sfe' } let(:target_id) { 'g_edit_by_sfe' }
......
...@@ -183,7 +183,7 @@ RSpec.describe SearchController do ...@@ -183,7 +183,7 @@ RSpec.describe SearchController do
allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event) allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event)
end end
it_behaves_like 'tracking unique hll events', :search_track_unique_users do it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: { scope: 'projects', search: 'term' } } subject(:request) { get :show, params: { scope: 'projects', search: 'term' } }
let(:target_id) { 'i_search_total' } let(:target_id) { 'i_search_total' }
......
...@@ -173,7 +173,7 @@ RSpec.describe SnippetsController do ...@@ -173,7 +173,7 @@ RSpec.describe SnippetsController do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
it_behaves_like 'tracking unique hll events', :usage_data_i_snippets_show do it_behaves_like 'tracking unique hll events' do
subject(:request) { get :show, params: { id: public_snippet.to_param } } subject(:request) { get :show, params: { id: public_snippet.to_param } }
let(:target_id) { 'i_snippets_show' } let(:target_id) { 'i_snippets_show' }
......
...@@ -8,7 +8,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do ...@@ -8,7 +8,7 @@ RSpec.describe Gitlab::UsageDataCounters::CiTemplateUniqueCounter do
describe '.track_unique_project_event' do describe '.track_unique_project_event' do
described_class::TEMPLATE_TO_EVENT.keys.each do |template| described_class::TEMPLATE_TO_EVENT.keys.each do |template|
context "when given template #{template}" do context "when given template #{template}" do
it_behaves_like 'tracking unique hll events', :usage_data_track_ci_templates_unique_projects do it_behaves_like 'tracking unique hll events' do
subject(:request) { described_class.track_unique_project_event(project_id: project_id, template: template) } subject(:request) { described_class.track_unique_project_event(project_id: project_id, template: template) }
let(:target_id) { "p_ci_templates_#{described_class::TEMPLATE_TO_EVENT[template]}" } let(:target_id) { "p_ci_templates_#{described_class::TEMPLATE_TO_EVENT[template]}" }
......
...@@ -48,6 +48,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -48,6 +48,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end end
describe 'known_events' do describe 'known_events' do
let(:feature) { 'test_hll_redis_counter_ff_check' }
let(:weekly_event) { 'g_analytics_contribution' } let(:weekly_event) { 'g_analytics_contribution' }
let(:daily_event) { 'g_analytics_search' } let(:daily_event) { 'g_analytics_search' }
let(:analytics_slot_event) { 'g_analytics_contribution' } let(:analytics_slot_event) { 'g_analytics_contribution' }
...@@ -67,7 +69,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -67,7 +69,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
let(:known_events) do let(:known_events) do
[ [
{ name: weekly_event, redis_slot: "analytics", category: analytics_category, expiry: 84, aggregation: "weekly" }, { name: weekly_event, redis_slot: "analytics", category: analytics_category, expiry: 84, aggregation: "weekly", feature_flag: feature },
{ name: daily_event, redis_slot: "analytics", category: analytics_category, expiry: 84, aggregation: "daily" }, { name: daily_event, redis_slot: "analytics", category: analytics_category, expiry: 84, aggregation: "daily" },
{ name: category_productivity_event, redis_slot: "analytics", category: productivity_category, aggregation: "weekly" }, { name: category_productivity_event, redis_slot: "analytics", category: productivity_category, aggregation: "weekly" },
{ name: compliance_slot_event, redis_slot: "compliance", category: compliance_category, aggregation: "weekly" }, { name: compliance_slot_event, redis_slot: "compliance", category: compliance_category, aggregation: "weekly" },
...@@ -78,6 +80,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -78,6 +80,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end end
before do before do
skip_feature_flags_yaml_validation
skip_default_enabled_yaml_check
allow(described_class).to receive(:known_events).and_return(known_events) allow(described_class).to receive(:known_events).and_return(known_events)
end end
...@@ -88,6 +92,32 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -88,6 +92,32 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end end
describe '.track_event' do describe '.track_event' do
context 'with feature flag set' do
it 'tracks the event when feature enabled' do
stub_feature_flags(feature => true)
expect(Gitlab::Redis::HLL).to receive(:add)
described_class.track_event(weekly_event, values: 1)
end
it 'does not track the event with feature flag disabled' do
stub_feature_flags(feature => false)
expect(Gitlab::Redis::HLL).not_to receive(:add)
described_class.track_event(weekly_event, values: 1)
end
end
context 'with no feature flag set' do
it 'tracks the event' do
expect(Gitlab::Redis::HLL).to receive(:add)
described_class.track_event(daily_event, values: 1)
end
end
context 'when usage_ping is disabled' do context 'when usage_ping is disabled' do
it 'does not track the event' do it 'does not track the event' do
stub_application_setting(usage_ping_enabled: false) stub_application_setting(usage_ping_enabled: false)
......
...@@ -39,7 +39,7 @@ RSpec.describe API::Terraform::State do ...@@ -39,7 +39,7 @@ RSpec.describe API::Terraform::State do
context 'with maintainer permissions' do context 'with maintainer permissions' do
let(:current_user) { maintainer } let(:current_user) { maintainer }
it_behaves_like 'tracking unique hll events', :usage_data_p_terraform_state_api_unique_users do it_behaves_like 'tracking unique hll events' do
let(:target_id) { 'p_terraform_state_api_unique_users' } let(:target_id) { 'p_terraform_state_api_unique_users' }
let(:expected_type) { instance_of(Integer) } let(:expected_type) { instance_of(Integer) }
end end
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# - expected_type # - expected_type
# - target_id # - target_id
RSpec.shared_examples 'tracking unique hll events' do |feature_flag| RSpec.shared_examples 'tracking unique hll events' do
it 'tracks unique event' do it 'tracks unique event' do
expect(Gitlab::UsageDataCounters::HLLRedisCounter).to( expect(Gitlab::UsageDataCounters::HLLRedisCounter).to(
receive(:track_event) receive(:track_event)
...@@ -15,14 +15,4 @@ RSpec.shared_examples 'tracking unique hll events' do |feature_flag| ...@@ -15,14 +15,4 @@ RSpec.shared_examples 'tracking unique hll events' do |feature_flag|
request request
end 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)
request
end
end
end end
...@@ -218,7 +218,7 @@ RSpec.shared_examples 'wiki controller actions' do ...@@ -218,7 +218,7 @@ RSpec.shared_examples 'wiki controller actions' do
end end
context 'page view tracking' do context 'page view tracking' do
it_behaves_like 'tracking unique hll events', :track_unique_wiki_page_views do it_behaves_like 'tracking unique hll events' do
let(:target_id) { 'wiki_action' } let(:target_id) { 'wiki_action' }
let(:expected_type) { instance_of(String) } let(:expected_type) { instance_of(String) }
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