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,21 +1361,33 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -1361,21 +1361,33 @@ 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
it 'has all known_events' do context 'with redis_hll_tracking feature enabled' do
expect(subject).to have_key(:redis_hll_counters) it 'has all known_events' do
stub_feature_flags(redis_hll_tracking: true)
expect(subject[:redis_hll_counters].keys).to match_array(categories) expect(subject).to have_key(:redis_hll_counters)
categories.each do |category| expect(subject[:redis_hll_counters].keys).to match_array(categories)
keys = ::Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category(category)
metrics = keys.map { |key| "#{key}_weekly" } + keys.map { |key| "#{key}_monthly" } categories.each do |category|
keys = ::Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category(category)
if ineligible_total_categories.exclude?(category) metrics = keys.map { |key| "#{key}_weekly" } + keys.map { |key| "#{key}_monthly" }
metrics.append("#{category}_total_unique_counts_weekly", "#{category}_total_unique_counts_monthly")
if ineligible_total_categories.exclude?(category)
metrics.append("#{category}_total_unique_counts_weekly", "#{category}_total_unique_counts_monthly")
end
expect(subject[:redis_hll_counters][category].keys).to match_array(metrics)
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[:redis_hll_counters][category].keys).to match_array(metrics) expect(subject).not_to have_key(:redis_hll_counters)
end end
end end
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