Commit eae5f187 authored by Alishan Ladhani's avatar Alishan Ladhani

Remove product analytics tracking

Changelog: removed
parent 03226ec9
---
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 ...@@ -13,7 +13,6 @@ module Gitlab
contexts = [Tracking::StandardContext.new(project: project, user: user, namespace: namespace, **extra).to_context, *context] 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) 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 rescue StandardError => error
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action) Gitlab::ErrorTracking.track_and_raise_for_dev_exception(error, snowplow_category: category, snowplow_action: action)
end end
...@@ -35,10 +34,6 @@ module Gitlab ...@@ -35,10 +34,6 @@ module Gitlab
def snowplow def snowplow
@snowplow ||= Gitlab::Tracking::Destinations::Snowplow.new @snowplow ||= Gitlab::Tracking::Destinations::Snowplow.new
end end
def product_analytics
@product_analytics ||= Gitlab::Tracking::Destinations::ProductAnalytics.new
end
end end
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 ...@@ -41,7 +41,6 @@ RSpec.describe Gitlab::Tracking do
shared_examples 'delegates to destination' do |klass| shared_examples 'delegates to destination' do |klass|
before do before do
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event) allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
end end
it "delegates to #{klass} destination" do it "delegates to #{klass} destination" do
...@@ -73,7 +72,6 @@ RSpec.describe Gitlab::Tracking do ...@@ -73,7 +72,6 @@ RSpec.describe Gitlab::Tracking do
end end
it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::Snowplow
it_behaves_like 'delegates to destination', Gitlab::Tracking::Destinations::ProductAnalytics
it 'tracks errors' do it 'tracks errors' do
expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with( expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(
......
...@@ -8,8 +8,6 @@ module StubSnowplow ...@@ -8,8 +8,6 @@ module StubSnowplow
host = 'localhost' host = 'localhost'
# rubocop:disable RSpec/AnyInstanceOf # rubocop:disable RSpec/AnyInstanceOf
allow_any_instance_of(Gitlab::Tracking::Destinations::ProductAnalytics).to receive(:event)
allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow) allow_any_instance_of(Gitlab::Tracking::Destinations::Snowplow)
.to receive(:emitter) .to receive(:emitter)
.and_return(SnowplowTracker::Emitter.new(host, buffer_size: buffer_size)) .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