Commit d50d836e authored by Alper Akgun's avatar Alper Akgun

Merge branch '325290-add-a-generic-feature-flag-for-tracking-using-redis-hll' into 'master'

Add a global feature flag for tracking using Redis HLL [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!56970
parents d3d72aa0 4cf203d1
---
name: redis_hll_tracking
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56970
rollout_issue_url:
milestone: '13.11'
type: ops
group: group::product intelligence
default_enabled: true
......@@ -711,6 +711,8 @@ module Gitlab
end
def redis_hll_counters
return {} unless Feature.enabled?(:redis_hll_tracking, type: :ops, default_enabled: :yaml)
{ redis_hll_counters: ::Gitlab::UsageDataCounters::HLLRedisCounter.unique_events_data }
end
......
......@@ -157,7 +157,7 @@ module Gitlab
def feature_enabled?(event)
return true if event[:feature_flag].blank?
Feature.enabled?(event[:feature_flag], default_enabled: :yaml)
Feature.enabled?(event[:feature_flag], default_enabled: :yaml) && Feature.enabled?(:redis_hll_tracking, type: :ops, default_enabled: :yaml)
end
# Allow to add totals for events that are in the same redis slot, category and have the same aggregation level
......
......@@ -93,7 +93,25 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end
describe '.track_event' do
context 'with feature flag set' do
context 'with redis_hll_tracking' do
it 'tracks the event when feature enabled' do
stub_feature_flags(redis_hll_tracking: 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(redis_hll_tracking: false)
expect(Gitlab::Redis::HLL).not_to receive(:add)
described_class.track_event(weekly_event, values: 1)
end
end
context 'with event feature flag set' do
it 'tracks the event when feature enabled' do
stub_feature_flags(feature => true)
......@@ -111,7 +129,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end
end
context 'with no feature flag set' do
context 'with no event feature flag set' do
it 'tracks the event' do
expect(Gitlab::Redis::HLL).to receive(:add)
......
......@@ -1361,7 +1361,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
%w[source_code ci_secrets_management incident_management_alerts snippets terraform]
end
context 'with redis_hll_tracking feature enabled' do
it 'has all known_events' do
stub_feature_flags(redis_hll_tracking: true)
expect(subject).to have_key(:redis_hll_counters)
expect(subject[:redis_hll_counters].keys).to match_array(categories)
......@@ -1380,6 +1383,15 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'with redis_hll_tracking disabled' do
it 'does not have redis_hll_tracking key' do
stub_feature_flags(redis_hll_tracking: false)
expect(subject).not_to have_key(:redis_hll_counters)
end
end
end
describe '.aggregated_metrics_data' do
it 'uses ::Gitlab::Usage::Metrics::Aggregates::Aggregate methods', :aggregate_failures do
expected_payload = {
......
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