Commit bc095759 authored by Piotr Skorupa's avatar Piotr Skorupa

Add license usage ping check to HLLRedisCounter

parent 7803c691
......@@ -12,6 +12,11 @@ module EE
def valid_context_list
super + License.all_plans
end
override :usage_ping_enabled?
def usage_ping_enabled?
::License.current&.customer_service_enabled? || super
end
end
end
end
......
......@@ -96,4 +96,46 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end
end
end
describe '.track_event' do
context 'with settings usage ping disabled' do
before do
stub_application_setting(usage_ping_enabled: false)
end
context 'with license usage ping disabled' do
before do
# License.current.customer_service_enabled? == true
create_current_license(operational_metrics_enabled: false)
end
it 'does not track the event' do
expect(Gitlab::Redis::HLL).not_to receive(:add)
described_class.track_event(context_event, values: entity1, time: Date.current)
end
end
context 'with license usage ping enabled' do
before do
# License.current.customer_service_enabled? == true
create_current_license(operational_metrics_enabled: true)
end
it 'tracks the event' do
expect(Gitlab::Redis::HLL).to receive(:add)
described_class.track_event(context_event, values: entity1, time: Date.current)
end
end
context 'without a license', :without_license do
it 'does not track the event' do
expect(Gitlab::Redis::HLL).not_to receive(:add)
described_class.track_event(context_event, values: entity1, time: Date.current)
end
end
end
end
end
......@@ -117,7 +117,7 @@ module Gitlab
private
def track(values, event_name, context: '', time: Time.zone.now)
return unless Gitlab::CurrentSettings.usage_ping_enabled?
return unless usage_ping_enabled?
event = event_for(event_name)
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(UnknownEvent.new("Unknown event #{event_name}")) unless event.present?
......@@ -131,6 +131,10 @@ module Gitlab
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
end
def usage_ping_enabled?
Gitlab::CurrentSettings.usage_ping_enabled?
end
# The array of valid context on which we allow tracking
def valid_context_list
Plan.all_plans
......
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