Commit 3f36a20a authored by Sean McGivern's avatar Sean McGivern

Merge branch '245247-check-for-usage-ping-enabled-when-tracking-using-redis-hll' into 'master'

Check for usage ping enabled when tracking using Redis HLL

Closes #245247

See merge request gitlab-org/gitlab!41562
parents 4601aae9 b6cb0e6e
---
title: Check if usage ping enabled for all tracking using Redis HLL
merge_request: 41562
author:
type: added
......@@ -34,6 +34,8 @@ module Gitlab
# * Get unique counts per user: Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: 'g_compliance_dashboard', start_date: 28.days.ago, end_date: Date.current)
class << self
def track_event(entity_id, event_name, time = Time.zone.now)
return unless Gitlab::CurrentSettings.usage_ping_enabled?
event = event_for(event_name)
raise UnknownEvent.new("Unknown event #{event_name}") unless event.present?
......
......@@ -62,6 +62,21 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end
describe '.track_event' do
context 'when usage_ping is disabled' do
it 'does not track the event' do
stub_application_setting(usage_ping_enabled: false)
described_class.track_event(entity1, weekly_event, Date.current)
expect(Gitlab::Redis::HLL).not_to receive(:add)
end
end
context 'when usage_ping is enabled' do
before do
stub_application_setting(usage_ping_enabled: true)
end
it "raise error if metrics don't have same aggregation" do
expect { described_class.track_event(entity1, different_aggregation, Date.current) } .to raise_error(Gitlab::UsageDataCounters::HLLRedisCounter::UnknownAggregation)
end
......@@ -126,6 +141,7 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end
end
end
end
describe '.unique_events' do
before 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