Commit 4cf203d1 authored by alinamihaila's avatar alinamihaila Committed by Alper Akgun

Add redis_hll_tracking ops feature flag

  - Add a global feature for tracking using Redis HLL
  and for adding the Redis data in Usage Ping
  - Add this feature to protect in case of performance
  issues as feature flags specifc per event are removed
parent 5e6383d4
---
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 ...@@ -711,6 +711,8 @@ module Gitlab
end end
def redis_hll_counters 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 } { redis_hll_counters: ::Gitlab::UsageDataCounters::HLLRedisCounter.unique_events_data }
end end
......
...@@ -157,7 +157,7 @@ module Gitlab ...@@ -157,7 +157,7 @@ module Gitlab
def feature_enabled?(event) def feature_enabled?(event)
return true if event[:feature_flag].blank? 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 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
......
...@@ -93,7 +93,25 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -93,7 +93,25 @@ 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 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 it 'tracks the event when feature enabled' do
stub_feature_flags(feature => true) stub_feature_flags(feature => true)
...@@ -111,7 +129,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -111,7 +129,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end end
end end
context 'with no feature flag set' do context 'with no event feature flag set' do
it 'tracks the event' do it 'tracks the event' do
expect(Gitlab::Redis::HLL).to receive(:add) expect(Gitlab::Redis::HLL).to receive(:add)
......
...@@ -1361,7 +1361,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1361,7 +1361,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
%w[source_code ci_secrets_management incident_management_alerts snippets terraform] %w[source_code ci_secrets_management incident_management_alerts snippets terraform]
end end
context 'with redis_hll_tracking feature enabled' do
it 'has all known_events' do it 'has all known_events' do
stub_feature_flags(redis_hll_tracking: true)
expect(subject).to have_key(:redis_hll_counters) expect(subject).to have_key(:redis_hll_counters)
expect(subject[:redis_hll_counters].keys).to match_array(categories) expect(subject[:redis_hll_counters].keys).to match_array(categories)
...@@ -1380,6 +1383,15 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1380,6 +1383,15 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end end
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 describe '.aggregated_metrics_data' do
it 'uses ::Gitlab::Usage::Metrics::Aggregates::Aggregate methods', :aggregate_failures do it 'uses ::Gitlab::Usage::Metrics::Aggregates::Aggregate methods', :aggregate_failures do
expected_payload = { 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