Commit 69eef2e7 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch...

Merge branch '339706-move-snowplow-logic-from-gitlab-tracking-module-to-gitlab-tracking-destinations-snowplow' into 'master'

Refactor Gitlab::Tracking module

See merge request gitlab-org/gitlab!75362
parents 363798e3 010f4725
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
module Gitlab module Gitlab
module Tracking module Tracking
SNOWPLOW_NAMESPACE = 'gl'
class << self class << self
def enabled? def enabled?
snowplow_micro_enabled? || Gitlab::CurrentSettings.snowplow_enabled? snowplow.enabled?
end end
def event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists def event(category, action, label: nil, property: nil, value: nil, context: [], project: nil, user: nil, namespace: nil, **extra) # rubocop:disable Metrics/ParameterLists
......
...@@ -8,6 +8,8 @@ module Gitlab ...@@ -8,6 +8,8 @@ module Gitlab
class Snowplow < Base class Snowplow < Base
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
SNOWPLOW_NAMESPACE = 'gl'
override :event override :event
def event(category, action, label: nil, property: nil, value: nil, context: nil) def event(category, action, label: nil, property: nil, value: nil, context: nil)
return unless enabled? return unless enabled?
...@@ -19,7 +21,7 @@ module Gitlab ...@@ -19,7 +21,7 @@ module Gitlab
def options(group) def options(group)
additional_features = Feature.enabled?(:additional_snowplow_tracking, group, type: :ops) additional_features = Feature.enabled?(:additional_snowplow_tracking, group, type: :ops)
{ {
namespace: Gitlab::Tracking::SNOWPLOW_NAMESPACE, namespace: SNOWPLOW_NAMESPACE,
hostname: hostname, hostname: hostname,
cookie_domain: cookie_domain, cookie_domain: cookie_domain,
app_id: app_id, app_id: app_id,
...@@ -28,16 +30,16 @@ module Gitlab ...@@ -28,16 +30,16 @@ module Gitlab
}.transform_keys! { |key| key.to_s.camelize(:lower).to_sym } }.transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
end end
def enabled?
Gitlab::CurrentSettings.snowplow_enabled?
end
def hostname def hostname
Gitlab::CurrentSettings.snowplow_collector_hostname Gitlab::CurrentSettings.snowplow_collector_hostname
end end
private private
def enabled?
Gitlab::Tracking.enabled?
end
def app_id def app_id
Gitlab::CurrentSettings.snowplow_app_id Gitlab::CurrentSettings.snowplow_app_id
end end
...@@ -54,7 +56,7 @@ module Gitlab ...@@ -54,7 +56,7 @@ module Gitlab
@tracker ||= SnowplowTracker::Tracker.new( @tracker ||= SnowplowTracker::Tracker.new(
emitter, emitter,
SnowplowTracker::Subject.new, SnowplowTracker::Subject.new,
Gitlab::Tracking::SNOWPLOW_NAMESPACE, SNOWPLOW_NAMESPACE,
app_id app_id
) )
end end
......
...@@ -18,6 +18,11 @@ module Gitlab ...@@ -18,6 +18,11 @@ module Gitlab
).transform_keys! { |key| key.to_s.camelize(:lower).to_sym } ).transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
end end
override :enabled?
def enabled?
true
end
override :hostname override :hostname
def hostname def hostname
"#{uri.host}:#{uri.port}" "#{uri.host}:#{uri.port}"
......
...@@ -29,7 +29,7 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do ...@@ -29,7 +29,7 @@ RSpec.describe Gitlab::Tracking::Destinations::Snowplow do
expect(SnowplowTracker::Tracker) expect(SnowplowTracker::Tracker)
.to receive(:new) .to receive(:new)
.with(emitter, an_instance_of(SnowplowTracker::Subject), Gitlab::Tracking::SNOWPLOW_NAMESPACE, '_abc123_') .with(emitter, an_instance_of(SnowplowTracker::Subject), described_class::SNOWPLOW_NAMESPACE, '_abc123_')
.and_return(tracker) .and_return(tracker)
end end
......
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