diff options
Diffstat (limited to 'lib/gitlab/tracking')
-rw-r--r-- | lib/gitlab/tracking/destinations/product_analytics.rb | 41 | ||||
-rw-r--r-- | lib/gitlab/tracking/destinations/snowplow.rb | 36 | ||||
-rw-r--r-- | lib/gitlab/tracking/destinations/snowplow_micro.rb | 48 | ||||
-rw-r--r-- | lib/gitlab/tracking/standard_context.rb | 15 |
4 files changed, 81 insertions, 59 deletions
diff --git a/lib/gitlab/tracking/destinations/product_analytics.rb b/lib/gitlab/tracking/destinations/product_analytics.rb deleted file mode 100644 index cacedbc5b83..00000000000 --- a/lib/gitlab/tracking/destinations/product_analytics.rb +++ /dev/null @@ -1,41 +0,0 @@ -# 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 diff --git a/lib/gitlab/tracking/destinations/snowplow.rb b/lib/gitlab/tracking/destinations/snowplow.rb index 07a53b0892b..5596e9acd30 100644 --- a/lib/gitlab/tracking/destinations/snowplow.rb +++ b/lib/gitlab/tracking/destinations/snowplow.rb @@ -16,25 +16,53 @@ module Gitlab increment_total_events_counter end + def options(group) + additional_features = Feature.enabled?(:additional_snowplow_tracking, group, type: :ops) + { + namespace: Gitlab::Tracking::SNOWPLOW_NAMESPACE, + hostname: hostname, + cookie_domain: cookie_domain, + app_id: app_id, + form_tracking: additional_features, + link_click_tracking: additional_features + }.transform_keys! { |key| key.to_s.camelize(:lower).to_sym } + end + + def hostname + Gitlab::CurrentSettings.snowplow_collector_hostname + end + private def enabled? Gitlab::Tracking.enabled? end + def app_id + Gitlab::CurrentSettings.snowplow_app_id + end + + def protocol + 'https' + end + + def cookie_domain + Gitlab::CurrentSettings.snowplow_cookie_domain + end + def tracker @tracker ||= SnowplowTracker::Tracker.new( emitter, SnowplowTracker::Subject.new, Gitlab::Tracking::SNOWPLOW_NAMESPACE, - Gitlab::CurrentSettings.snowplow_app_id + app_id ) end def emitter SnowplowTracker::AsyncEmitter.new( - Gitlab::CurrentSettings.snowplow_collector_hostname, - protocol: 'https', + hostname, + protocol: protocol, on_success: method(:increment_successful_events_emissions), on_failure: method(:failure_callback) ) @@ -68,8 +96,6 @@ module Gitlab end def log_failures(failures) - hostname = Gitlab::CurrentSettings.snowplow_collector_hostname - failures.each do |failure| Gitlab::AppLogger.error("#{failure["se_ca"]} #{failure["se_ac"]} failed to be reported to collector at #{hostname}") end diff --git a/lib/gitlab/tracking/destinations/snowplow_micro.rb b/lib/gitlab/tracking/destinations/snowplow_micro.rb new file mode 100644 index 00000000000..b818d349a6d --- /dev/null +++ b/lib/gitlab/tracking/destinations/snowplow_micro.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true +# +module Gitlab + module Tracking + module Destinations + class SnowplowMicro < Snowplow + include ::Gitlab::Utils::StrongMemoize + extend ::Gitlab::Utils::Override + + DEFAULT_URI = 'http://localhost:9090' + + override :options + def options(group) + super.update( + protocol: uri.scheme, + port: uri.port, + force_secure_tracker: false + ) + end + + override :hostname + def hostname + "#{uri.host}:#{uri.port}" + end + + private + + def uri + strong_memoize(:snowplow_uri) do + uri = URI(ENV['SNOWPLOW_MICRO_URI'] || DEFAULT_URI) + uri = URI("http://#{ENV['SNOWPLOW_MICRO_URI']}") unless %w[http https].include?(uri.scheme) + uri + end + end + + override :cookie_domain + def cookie_domain + '.gitlab.com' + end + + override :protocol + def protocol + uri.scheme + end + end + end + end +end diff --git a/lib/gitlab/tracking/standard_context.rb b/lib/gitlab/tracking/standard_context.rb index df62e8bbbe6..837390b91fb 100644 --- a/lib/gitlab/tracking/standard_context.rb +++ b/lib/gitlab/tracking/standard_context.rb @@ -43,15 +43,8 @@ module Gitlab environment: environment, source: source, plan: plan, - extra: extra - }.merge(project_and_namespace) - .merge(user_data) - end - - def project_and_namespace - return {} unless ::Feature.enabled?(:add_namespace_and_project_to_snowplow_tracking, default_enabled: :yaml) - - { + extra: extra, + user_id: user&.id, namespace_id: namespace&.id, project_id: project_id } @@ -60,10 +53,6 @@ module Gitlab def project_id project.is_a?(Integer) ? project : project&.id end - - def user_data - ::Feature.enabled?(:add_actor_based_user_to_snowplow_tracking, user) ? { user_id: user&.id } : {} - end end end end |