Module: Gitlab::UsageDataCounters::TrackUniqueEvents

Defined in:
lib/gitlab/usage_data_counters/track_unique_events.rb

Constant Summary collapse

WIKI_ACTION =
:wiki_action
DESIGN_ACTION =
:design_action
PUSH_ACTION =
:project_action
MERGE_REQUEST_ACTION =
:merge_request_action
GIT_WRITE_ACTIONS =
[WIKI_ACTION, DESIGN_ACTION, PUSH_ACTION].freeze
GIT_WRITE_ACTION =
:git_write_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
  },
  merge_request: {
    closed: MERGE_REQUEST_ACTION,
    merged: MERGE_REQUEST_ACTION,
    created: MERGE_REQUEST_ACTION,
    commented: MERGE_REQUEST_ACTION
  }
}).freeze

Class Method Summary collapse

Class Method Details

.count_unique_events(event_action:, date_from:, date_to:) ⇒ Object


51
52
53
# File 'lib/gitlab/usage_data_counters/track_unique_events.rb', line 51

def count_unique_events(event_action:, date_from:, date_to:)
  Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: event_action.to_s, start_date: date_from, end_date: date_to)
end

.track_event(event_action:, event_target:, author_id:, time: Time.zone.now) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/gitlab/usage_data_counters/track_unique_events.rb', line 37

def track_event(event_action:, event_target:, author_id:, time: Time.zone.now)
  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)

  return unless Gitlab::UsageDataCounters::HLLRedisCounter.known_event?(transformed_action.to_s)

  Gitlab::UsageDataCounters::HLLRedisCounter.track_event(transformed_action.to_s, values: author_id, time: time)

  track_git_write_action(author_id, transformed_action, time)
end