diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /lib/gitlab/usage_data_counters | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'lib/gitlab/usage_data_counters')
-rw-r--r-- | lib/gitlab/usage_data_counters/base_counter.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/usage_data_counters/designs_counter.rb | 42 | ||||
-rw-r--r-- | lib/gitlab/usage_data_counters/note_counter.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/usage_data_counters/search_counter.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/usage_data_counters/web_ide_counter.rb | 52 |
5 files changed, 89 insertions, 29 deletions
diff --git a/lib/gitlab/usage_data_counters/base_counter.rb b/lib/gitlab/usage_data_counters/base_counter.rb index 33111b46381..96898e5189c 100644 --- a/lib/gitlab/usage_data_counters/base_counter.rb +++ b/lib/gitlab/usage_data_counters/base_counter.rb @@ -22,11 +22,19 @@ module Gitlab::UsageDataCounters end def totals - known_events.map { |e| ["#{prefix}_#{e}".to_sym, read(e)] }.to_h + known_events.map { |event| [counter_key(event), read(event)] }.to_h + end + + def fallback_totals + known_events.map { |event| [counter_key(event), -1] }.to_h end private + def counter_key(event) + "#{prefix}_#{event}".to_sym + end + def known_events self::KNOWN_EVENTS end diff --git a/lib/gitlab/usage_data_counters/designs_counter.rb b/lib/gitlab/usage_data_counters/designs_counter.rb new file mode 100644 index 00000000000..801fb8f3b3d --- /dev/null +++ b/lib/gitlab/usage_data_counters/designs_counter.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +module Gitlab::UsageDataCounters + class DesignsCounter + extend Gitlab::UsageDataCounters::RedisCounter + + KNOWN_EVENTS = %w[create update delete].map(&:freeze).freeze + + UnknownEvent = Class.new(StandardError) + + class << self + # Each event gets a unique Redis key + def redis_key(event) + raise UnknownEvent, event unless KNOWN_EVENTS.include?(event.to_s) + + "USAGE_DESIGN_MANAGEMENT_DESIGNS_#{event}".upcase + end + + def count(event) + increment(redis_key(event)) + end + + def read(event) + total_count(redis_key(event)) + end + + def totals + KNOWN_EVENTS.map { |event| [counter_key(event), read(event)] }.to_h + end + + def fallback_totals + KNOWN_EVENTS.map { |event| [counter_key(event), -1] }.to_h + end + + private + + def counter_key(event) + "design_management_designs_#{event}".to_sym + end + end + end +end diff --git a/lib/gitlab/usage_data_counters/note_counter.rb b/lib/gitlab/usage_data_counters/note_counter.rb index 672450ec82b..7a76180cb08 100644 --- a/lib/gitlab/usage_data_counters/note_counter.rb +++ b/lib/gitlab/usage_data_counters/note_counter.rb @@ -25,12 +25,20 @@ module Gitlab::UsageDataCounters def totals COUNTABLE_TYPES.map do |countable_type| - [:"#{countable_type.underscore}_comment", read(:create, countable_type)] + [counter_key(countable_type), read(:create, countable_type)] end.to_h end + def fallback_totals + COUNTABLE_TYPES.map { |counter_key| [counter_key(counter_key), -1] }.to_h + end + private + def counter_key(countable_type) + "#{countable_type.underscore}_comment".to_sym + end + def countable?(noteable_type) COUNTABLE_TYPES.include?(noteable_type.to_s) end diff --git a/lib/gitlab/usage_data_counters/search_counter.rb b/lib/gitlab/usage_data_counters/search_counter.rb index 5f0735347e1..b9e3a5c0104 100644 --- a/lib/gitlab/usage_data_counters/search_counter.rb +++ b/lib/gitlab/usage_data_counters/search_counter.rb @@ -21,6 +21,10 @@ module Gitlab navbar_searches: total_navbar_searches_count } end + + def fallback_totals + { navbar_searches: -1 } + end end end end diff --git a/lib/gitlab/usage_data_counters/web_ide_counter.rb b/lib/gitlab/usage_data_counters/web_ide_counter.rb index c012a6c96df..00fcd42a9af 100644 --- a/lib/gitlab/usage_data_counters/web_ide_counter.rb +++ b/lib/gitlab/usage_data_counters/web_ide_counter.rb @@ -4,54 +4,52 @@ module Gitlab module UsageDataCounters class WebIdeCounter extend RedisCounter - - COMMITS_COUNT_KEY = 'WEB_IDE_COMMITS_COUNT' - MERGE_REQUEST_COUNT_KEY = 'WEB_IDE_MERGE_REQUESTS_COUNT' - VIEWS_COUNT_KEY = 'WEB_IDE_VIEWS_COUNT' - PREVIEW_COUNT_KEY = 'WEB_IDE_PREVIEWS_COUNT' + KNOWN_EVENTS = %i[commits views merge_requests previews terminals pipelines].freeze + PREFIX = 'web_ide' class << self def increment_commits_count - increment(COMMITS_COUNT_KEY) - end - - def total_commits_count - total_count(COMMITS_COUNT_KEY) + increment(redis_key('commits')) end def increment_merge_requests_count - increment(MERGE_REQUEST_COUNT_KEY) + increment(redis_key('merge_requests')) end - def total_merge_requests_count - total_count(MERGE_REQUEST_COUNT_KEY) + def increment_views_count + increment(redis_key('views')) end - def increment_views_count - increment(VIEWS_COUNT_KEY) + def increment_terminals_count + increment(redis_key('terminals')) end - def total_views_count - total_count(VIEWS_COUNT_KEY) + def increment_pipelines_count + increment(redis_key('pipelines')) end def increment_previews_count return unless Gitlab::CurrentSettings.web_ide_clientside_preview_enabled? - increment(PREVIEW_COUNT_KEY) + increment(redis_key('previews')) + end + + def totals + KNOWN_EVENTS.map { |event| [counter_key(event), total_count(redis_key(event))] }.to_h end - def total_previews_count - total_count(PREVIEW_COUNT_KEY) + def fallback_totals + KNOWN_EVENTS.map { |event| [counter_key(event), -1] }.to_h end - def totals - { - web_ide_commits: total_commits_count, - web_ide_views: total_views_count, - web_ide_merge_requests: total_merge_requests_count, - web_ide_previews: total_previews_count - } + private + + def redis_key(event) + "#{PREFIX}_#{event}_count".upcase + end + + def counter_key(event) + "#{PREFIX}_#{event}".to_sym end end end |