Commit 6d932fa7 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak

Merge branch 'ali/remove-product-analytics-tracker' into 'master'

Remove Product Analytics tracking destination

See merge request gitlab-org/gitlab!72042
parents 9e4c1343 eae5f187
---
name: product_analytics_tracking
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/46482
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/285519
milestone: '13.7'
type: ops
group: group::product intelligence
default_enabled: false
......@@ -13,7 +13,6 @@ module Gitlab
contexts = [Tracking::StandardContext.new(project: project, user: user, namespace: namespace, **extra).to_context, *context]
snowplow.event(category, action, label: label, property: property, value: value, context: contexts)
product_analytics.event(category, action, label: label, property: property, value: value, context: contexts)
rescue StandardError => error
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
end
......@@ -35,10 +34,6 @@ module Gitlab
def snowplow
@snowplow ||= Gitlab::Tracking::Destinations::Snowplow.new
end
def product_analytics
@product_analytics ||= Gitlab::Tracking::Destinations::ProductAnalytics.new
end
end
end
end
# frozen_string_literal: true
module Gitlab
module Tracking
module Destinations
class ProductAnalytics < Base
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
override :event
def event(category, action, label: nil, property: nil, value: nil, context: nil)
return unless event_allowed?(category, action)
return unless enabled?
tracker.track_struct_event(category, action, label, property, value, context, (Time.now.to_f * 1000).to_i)
end
private
def event_allowed?(category, action)
category == 'epics' && action == 'promote'
end
def enabled?
Feature.enabled?(:product_analytics_tracking, type: :ops) &&
Gitlab::CurrentSettings.usage_ping_enabled? &&
Gitlab::CurrentSettings.self_monitoring_project_id.present?
end
def tracker
@tracker ||= SnowplowTracker::Tracker.new(
SnowplowTracker::AsyncEmitter.new(::ProductAnalytics::Tracker::COLLECTOR_URL, protocol: Gitlab.config.gitlab.protocol),
SnowplowTracker::Subject.new,
Gitlab::Tracking::SNOWPLOW_NAMESPACE,
Gitlab::CurrentSettings.self_monitoring_project_id.to_s
)
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Tracking::Destinations::ProductAnalytics do
let(:emitter) { SnowplowTracker::Emitter.new('localhost', buffer_size: 1) }
let(:tracker) { SnowplowTracker::Tracker.new(emitter, SnowplowTracker::Subject.new, 'namespace', 'app_id') }
describe '#event' do
shared_examples 'does not send an event' do
it 'does not send an event' do
expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_struct_event)
subject.event(allowed_category, allowed_action)
end
end
let(:allowed_category) { 'epics' }
let(:allowed_action) { 'promote' }
let(:self_monitoring_project) { create(:project) }
before do
stub_feature_flags(product_analytics_tracking: true)
stub_application_setting(self_monitoring_project_id: self_monitoring_project.id)
stub_application_setting(usage_ping_enabled: true)
end
context 'with allowed event' do
it 'sends an event to Product Analytics snowplow collector' do
expect(SnowplowTracker::AsyncEmitter)
.to receive(:new)
.with(ProductAnalytics::Tracker::COLLECTOR_URL, protocol: Gitlab.config.gitlab.protocol)
.and_return(emitter)
expect(SnowplowTracker::Tracker)
.to receive(:new)
.with(emitter, an_instance_of(SnowplowTracker::Subject), Gitlab::Tracking::SNOWPLOW_NAMESPACE, self_monitoring_project.id.to_s)
.and_return(tracker)
freeze_time do
expect(tracker)
.to receive(:track_struct_event)
.with(allowed_category, allowed_action, 'label', 'property', 1.5, nil, (Time.now.to_f * 1000).to_i)
subject.event(allowed_category, allowed_action, label: 'label', property: 'property', value: 1.5)
end
end
end
context 'with non-allowed event' do
it 'does not send an event' do
expect_any_instance_of(SnowplowTracker::Tracker).not_to receive(:track_struct_event)
subject.event('category', 'action')
subject.event(allowed_category, 'action')
subject.event('category', allowed_action)
end
end
context 'when self-monitoring project does not exist' do
before do
stub_application_setting(self_monitoring_project_id: nil)
end
include_examples 'does not send an event'
end
context 'when product_analytics_tracking FF is disabled' do
before do
stub_feature_flags(product_analytics_tracking: false)
end
include_examples 'does not send an event'
end
context 'when usage ping is disabled' do
before do
stub_application_setting(usage_ping_enabled: false)
end
include_examples 'does not send an event'
end
end
end
......@@ -41,7 +41,6 @@ RSpec.describe Gitlab::Tracking do
shared_examples 'delegates to destination' do |klass|
before do
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
end
it "delegates to #{klass} destination" do
......@@ -73,7 +72,6 @@ RSpec.describe Gitlab::Tracking do
end
it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow
it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::ProductAnalytics
it 'tracks errors' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(
......
......@@ -8,8 +8,6 @@ module StubSnowplow
host = 'localhost'
# rubocop:disable RSpec/AnyInstanceOf
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow)
.to receive(:emitter)
.and_return(SnowplowTracker::Emitter.new(host, buffer_size: buffer_size))
......
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