Commit b0f56078 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch...

Merge branch '335674-track-events-with-redis-hll-if-usage-ping-enabled-or-if-license-usage-ping-is-enabled' into 'master'

Add license usage ping check to HLLRedisCounter

See merge request gitlab-org/gitlab!66056
parents 07fa7d33 ebf48094
...@@ -12,6 +12,11 @@ module EE ...@@ -12,6 +12,11 @@ module EE
def valid_context_list def valid_context_list
super + License.all_plans super + License.all_plans
end end
override :usage_ping_enabled?
def usage_ping_enabled?
::License.current&.customer_service_enabled? || super
end
end end
end end
end end
......
...@@ -96,4 +96,46 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s ...@@ -96,4 +96,46 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
end end
end 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 end
...@@ -117,7 +117,7 @@ module Gitlab ...@@ -117,7 +117,7 @@ module Gitlab
private private
def track(values, event_name, context: '', time: Time.zone.now) 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) event = event_for(event_name)
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(UnknownEvent.new("Unknown event #{event_name}")) unless event.present? Gitlab::ErrorTracking.track_and_raise_for_dev_exception(UnknownEvent.new("Unknown event #{event_name}")) unless event.present?
...@@ -131,6 +131,10 @@ module Gitlab ...@@ -131,6 +131,10 @@ module Gitlab
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e)
end end
def usage_ping_enabled?
Gitlab::CurrentSettings.usage_ping_enabled?
end
# The array of valid context on which we allow tracking # The array of valid context on which we allow tracking
def valid_context_list def valid_context_list
Plan.all_plans Plan.all_plans
......
...@@ -318,7 +318,8 @@ RSpec.describe EventCreateService do ...@@ -318,7 +318,8 @@ RSpec.describe EventCreateService do
specify { expect { result }.to change { Event.count }.by(8) } specify { expect { result }.to change { Event.count }.by(8) }
specify { expect { result }.not_to exceed_query_limit(1) } # An addditional query due to event tracking
specify { expect { result }.not_to exceed_query_limit(2) }
it 'creates 3 created design events' do it 'creates 3 created design events' do
ids = result.pluck('id') ids = result.pluck('id')
...@@ -347,7 +348,8 @@ RSpec.describe EventCreateService do ...@@ -347,7 +348,8 @@ RSpec.describe EventCreateService do
specify { expect { result }.to change { Event.count }.by(5) } specify { expect { result }.to change { Event.count }.by(5) }
specify { expect { result }.not_to exceed_query_limit(1) } # An addditional query due to event tracking
specify { expect { result }.not_to exceed_query_limit(2) }
it 'creates 5 destroyed design events' do it 'creates 5 destroyed design events' do
ids = result.pluck('id') ids = result.pluck('id')
......
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