diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-26 06:10:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-26 06:10:34 +0000 |
commit | fb553bbc1899eddaddb07cd9685cdabffbed9962 (patch) | |
tree | 473f1ad59a01e98d6ee1a04f462e524bb585f1e4 /lib | |
parent | a51e52bf5b7a708255a858ca51de8d4a6e58b074 (diff) | |
download | gitlab-ce-fb553bbc1899eddaddb07cd9685cdabffbed9962.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
3 files changed, 87 insertions, 13 deletions
diff --git a/lib/gitlab/usage_data_counters/editor_unique_counter.rb b/lib/gitlab/usage_data_counters/editor_unique_counter.rb new file mode 100644 index 00000000000..251c83d3eed --- /dev/null +++ b/lib/gitlab/usage_data_counters/editor_unique_counter.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Gitlab + module UsageDataCounters + module EditorUniqueCounter + EDIT_BY_SNIPPET_EDITOR = :edit_by_snippet_editor + EDIT_BY_SFE = :edit_by_sfe + EDIT_BY_WEB_IDE = :edit_by_web_ide + + class << self + def track_web_ide_edit_action(author:, time: Time.zone.now) + track_unique_action(EDIT_BY_WEB_IDE, author, time) + end + + def count_web_ide_edit_actions(date_from:, date_to:) + count_unique(EDIT_BY_WEB_IDE, date_from, date_to) + end + + def track_sfe_edit_action(author:, time: Time.zone.now) + track_unique_action(EDIT_BY_SFE, author, time) + end + + def count_sfe_edit_actions(date_from:, date_to:) + count_unique(EDIT_BY_SFE, date_from, date_to) + end + + def track_snippet_editor_edit_action(author:, time: Time.zone.now) + track_unique_action(EDIT_BY_SNIPPET_EDITOR, author, time) + end + + def count_snippet_editor_edit_actions(date_from:, date_to:) + count_unique(EDIT_BY_SNIPPET_EDITOR, date_from, date_to) + end + + private + + def track_unique_action(action, author, time) + return unless Feature.enabled?(:track_editor_edit_actions) + + Gitlab::UsageDataCounters::TrackUniqueActions.track_action(action: action, author_id: author.id, time: time) + end + + def count_unique(action, date_from, date_to) + Gitlab::UsageDataCounters::TrackUniqueActions.count_unique(action: action, date_from: date_from, date_to: date_to) + end + end + end + end +end diff --git a/lib/gitlab/usage_data_counters/track_unique_actions.rb b/lib/gitlab/usage_data_counters/track_unique_actions.rb new file mode 100644 index 00000000000..97e85bef9a5 --- /dev/null +++ b/lib/gitlab/usage_data_counters/track_unique_actions.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module UsageDataCounters + module TrackUniqueActions + KEY_EXPIRY_LENGTH = 29.days + + class << self + def track_action(action:, author_id:, time: Time.zone.now) + return unless Gitlab::CurrentSettings.usage_ping_enabled + + target_key = key(action, time) + + add_key(target_key, author_id) + end + + def count_unique(action:, date_from:, date_to:) + keys = (date_from.to_date..date_to.to_date).map { |date| key(action, date) } + + Gitlab::Redis::HLL.count(keys: keys) + end + + private + + def key(action, date) + year_day = date.strftime('%G-%j') + "#{year_day}-{#{action}}" + end + + def add_key(key, value) + Gitlab::Redis::HLL.add(key: key, value: value, expiry: KEY_EXPIRY_LENGTH) + end + end + end + end +end diff --git a/lib/gitlab/usage_data_counters/track_unique_events.rb b/lib/gitlab/usage_data_counters/track_unique_events.rb index db18200f059..f2a217e980e 100644 --- a/lib/gitlab/usage_data_counters/track_unique_events.rb +++ b/lib/gitlab/usage_data_counters/track_unique_events.rb @@ -3,8 +3,6 @@ module Gitlab module UsageDataCounters module TrackUniqueEvents - KEY_EXPIRY_LENGTH = 29.days - WIKI_ACTION = :wiki_action DESIGN_ACTION = :design_action PUSH_ACTION = :project_action @@ -27,21 +25,17 @@ module Gitlab class << self def track_event(event_action:, event_target:, author_id:, time: Time.zone.now) - return unless Gitlab::CurrentSettings.usage_ping_enabled 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) - target_key = key(transformed_action, time) - Gitlab::Redis::HLL.add(key: target_key, value: author_id, expiry: KEY_EXPIRY_LENGTH) + Gitlab::UsageDataCounters::TrackUniqueActions.track_action(action: transformed_action, author_id: author_id, time: time) end def count_unique_events(event_action:, date_from:, date_to:) - keys = (date_from.to_date..date_to.to_date).map { |date| key(event_action, date) } - - Gitlab::Redis::HLL.count(keys: keys) + Gitlab::UsageDataCounters::TrackUniqueActions.count_unique(action: event_action, date_from: date_from, date_to: date_to) end private @@ -61,11 +55,6 @@ module Gitlab def valid_action?(action) Event.actions.key?(action) end - - def key(event_action, date) - year_day = date.strftime('%G-%j') - "#{year_day}-{#{event_action}}" - end end end end |