2020-07-15 15:09:21 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module UsageDataCounters
|
2020-08-20 15:10:18 +00:00
|
|
|
module TrackUniqueEvents
|
2020-07-15 15:09:21 +00:00
|
|
|
WIKI_ACTION = :wiki_action
|
|
|
|
DESIGN_ACTION = :design_action
|
|
|
|
PUSH_ACTION = :project_action
|
|
|
|
|
|
|
|
ACTION_TRANSFORMATIONS = HashWithIndifferentAccess.new({
|
|
|
|
wiki: {
|
|
|
|
created: WIKI_ACTION,
|
|
|
|
updated: WIKI_ACTION,
|
|
|
|
destroyed: WIKI_ACTION
|
|
|
|
},
|
|
|
|
design: {
|
|
|
|
created: DESIGN_ACTION,
|
|
|
|
updated: DESIGN_ACTION,
|
|
|
|
destroyed: DESIGN_ACTION
|
|
|
|
},
|
|
|
|
project: {
|
|
|
|
pushed: PUSH_ACTION
|
|
|
|
}
|
|
|
|
}).freeze
|
|
|
|
|
|
|
|
class << self
|
2020-08-17 09:10:08 +00:00
|
|
|
def track_event(event_action:, event_target:, author_id:, time: Time.zone.now)
|
2020-07-15 15:09:21 +00:00
|
|
|
return unless valid_target?(event_target)
|
|
|
|
return unless valid_action?(event_action)
|
|
|
|
|
|
|
|
transformed_target = transform_target(event_target)
|
|
|
|
transformed_action = transform_action(event_action, transformed_target)
|
|
|
|
|
2020-08-26 06:10:34 +00:00
|
|
|
Gitlab::UsageDataCounters::TrackUniqueActions.track_action(action: transformed_action, author_id: author_id, time: time)
|
2020-07-15 15:09:21 +00:00
|
|
|
end
|
|
|
|
|
2020-08-20 15:10:18 +00:00
|
|
|
def count_unique_events(event_action:, date_from:, date_to:)
|
2020-08-26 06:10:34 +00:00
|
|
|
Gitlab::UsageDataCounters::TrackUniqueActions.count_unique(action: event_action, date_from: date_from, date_to: date_to)
|
2020-07-15 15:09:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def transform_action(event_action, event_target)
|
|
|
|
ACTION_TRANSFORMATIONS.dig(event_target, event_action) || event_action
|
|
|
|
end
|
|
|
|
|
|
|
|
def transform_target(event_target)
|
|
|
|
Event::TARGET_TYPES.key(event_target)
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_target?(target)
|
|
|
|
Event::TARGET_TYPES.value?(target)
|
|
|
|
end
|
|
|
|
|
|
|
|
def valid_action?(action)
|
|
|
|
Event.actions.key?(action)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|