Commit 0c1a5d1f authored by ggelatti's avatar ggelatti

Refactor pkg event name handling

Move testing for guest events out of the events class.
parent cfc4e738
...@@ -25,7 +25,7 @@ class Packages::Event < ApplicationRecord ...@@ -25,7 +25,7 @@ class Packages::Event < ApplicationRecord
enum originator_type: { user: 0, deploy_token: 1, guest: 2 } enum originator_type: { user: 0, deploy_token: 1, guest: 2 }
def self.allowed_event_name(event_scope, event_type, originator) def self.allowed_event_name(event_scope, event_type, originator)
return unless event_allowed?(event_scope, event_type, originator) return unless event_allowed?(event_type)
# remove `package` from the event name to avoid issues with HLLRedisCounter class parsing # remove `package` from the event name to avoid issues with HLLRedisCounter class parsing
"i_package_#{event_scope}_#{originator}_#{event_type.gsub(/_packages?/, "")}" "i_package_#{event_scope}_#{originator}_#{event_type.gsub(/_packages?/, "")}"
...@@ -33,8 +33,7 @@ class Packages::Event < ApplicationRecord ...@@ -33,8 +33,7 @@ class Packages::Event < ApplicationRecord
# Remove some of the events, for now, so we don't hammer Redis too hard. # Remove some of the events, for now, so we don't hammer Redis too hard.
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/280770 # See: https://gitlab.com/gitlab-org/gitlab/-/issues/280770
def self.event_allowed?(event_scope, event_type, originator) def self.event_allowed?(event_type)
return false if originator.to_sym == :guest
return true if UNIQUE_EVENTS_ALLOWED.include?(event_type.to_sym) return true if UNIQUE_EVENTS_ALLOWED.include?(event_type.to_sym)
false false
......
...@@ -4,7 +4,9 @@ module Packages ...@@ -4,7 +4,9 @@ module Packages
class CreateEventService < BaseService class CreateEventService < BaseService
def execute def execute
if Feature.enabled?(:collect_package_events_redis) && redis_event_name if Feature.enabled?(:collect_package_events_redis) && redis_event_name
::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(current_user.id, redis_event_name) unless guest?
::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(current_user.id, redis_event_name)
end
end end
if Feature.enabled?(:collect_package_events) && Gitlab::Database.read_write? if Feature.enabled?(:collect_package_events) && Gitlab::Database.read_write?
...@@ -45,5 +47,9 @@ module Packages ...@@ -45,5 +47,9 @@ module Packages
:guest :guest
end end
end end
def guest?
originator_type == :guest
end
end end
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